SASS Global Variables + Rails 3.1

时间:2011-06-18 00:59:58

标签: ruby-on-rails haml sass

我正在使用Rails 3.1RC4和默认的SASS设置。我有以下文件

application.css.scss

/*
 * This is a manifest file that'll automatically include all the stylesheets available in this directory
 * and any sub-directories. You're free to add application-wide styles to this file and they'll appear at
 * the top of the compiled file, but it's generally better to create a new file per style scope.
 *= require_self
 *= require_tree . 
*/

_variables.css.scss

$var1 : somevalue;
...

site_layout.css.scss

@import "variables";
... Some Sass Code

但我无法访问site_layout中_variables.css.scss中定义的变量。我究竟做错了什么? Rails显然找到了变量文件,因为它不会抛出“找不到文件”错误,如果我更改导入文件名就会出错。 vars还没有结转。

有什么想法吗?

谢谢!

2 个答案:

答案 0 :(得分:3)

这个问题似乎与最新版本的rails& amp;链轮。在你的gemfile中:

gem 'rails', :git => "git://github.com/rails/rails.git", :branch => "3-1-stable"

答案 1 :(得分:-3)

您问题的第一部分(application.css.scss代码段)似乎没有任何相关性,因为它只是注释掉了代码,因此我将跳过该部分。

对于第二个代码段,我不相信SASS设置为导入“部分”,就像你在这里做的那样。你最好做这样的事情:

_variables.scss (从 _variables.css.scss 重命名):

$var1: somevalue;

请注意,文件名中的下划线不需要像Ruby部分那样。只要您将导入语句更改为variables.scss

,就可以轻松地将其命名为@import "variables";

site_layout.scss (从 site_layout.css.scss 重命名)

@import "_variables";

.test_thingy {
  color: $var1;
  }

这将生成一个site_layout.css文件,其中包含以下代码替换:

.test_thingy {
  color: somevalue; }

请注意,不需要像使用HAML / ERB文件那样使用名为filename.css.scss的文件。只需将文件命名为您想要的名称即可。例如,filename.scss将导致SASS自动生成名为filename.css的CSS文件。