Carry Sass variables through the Assets Pipeline, Rails 3.1 rc1

安稳与你 提交于 2019-12-03 06:59:32

问题


I recently branched one of my Rails 3.0 projects with the 3.1 rc1 to try the new assets pipeline. I've been using Sass in the project before going 3.1 so I've been setting up some variables and functions in a separate configure file and let all my other sass files import that one file at the first line.

This has been working out great to not repeat some color codes and general geometry through in the stylesheets. Problem is now with the new Assets Pipeline is that as I've understood it converts the ".css.sass" files to raw css before appending it to the rest of the code.

So if i specify, in my "application.css":

/*
 *= require ./configure
 *= require ./what_ever_other_files_i_want_to_import
*/

I get errors like:

Sass::SyntaxError
    Undefined variable: "$interactive".

When i try to access the file from: http://localhost:3000/assets/application.css

Any ideas?


回答1:


Sass supports Partials. That way you can include your separate configuration in __configuration.sass_ and reference it with

@import "configuration";

from your main sass-file.




回答2:


Unfortunately I found out that SASS variables are be page specific.

If you want to carry your variables across all files, remove the *= require_tree . line from your application.css.scss file and replace it with the @import "layout.css.scss"; directive to manually import each sass file.

Yes you have to @import each file



来源:https://stackoverflow.com/questions/6162468/carry-sass-variables-through-the-assets-pipeline-rails-3-1-rc1

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!