![](/img/trans.png)
[英]Carry Sass variables through the Assets Pipeline, Rails 3.1 rc1
[英]SASS Global Variables + Rails 3.1
我正在使用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顯然找到了變量文件,因為它不會拋出“找不到文件”錯誤,如果我更改導入文件名就會出錯。 這些變量還沒有結轉。
有任何想法嗎?
謝謝!
最新版本的rails和鏈輪似乎解決了這個問題。 在你的gemfile中:
gem 'rails', :git => "git://github.com/rails/rails.git", :branch => "3-1-stable"
你的問題的第一部分( application.css.scss
代碼片段)似乎沒有任何相關性,因為它只是注釋掉的代碼,所以我將跳過那一部分。
對於第二個代碼片段,我不相信SASS設置為導入“部分”,就像你在這里做的那樣。 你最好做這樣的事情:
_variables.scss (從_variables.css.scss重命名):
$var1: somevalue;
請注意,文件名中的下划線不需要像Ruby部分那樣。 你可以很容易地將其命名為variables.scss
只要你改變import語句@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文件。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.