开发者

Automatic generation of CSS from SCSS/SASS with HAML and Rails

开发者 https://www.devze.com 2023-01-14 11:35 出处:网络
Is there a way to get your SCSS files to automatically generate new CSS each time a file is changed as part of Rails, 开发者_开发百科without having to use sass --watch? Or is this just meant to happen

Is there a way to get your SCSS files to automatically generate new CSS each time a file is changed as part of Rails, 开发者_开发百科without having to use sass --watch? Or is this just meant to happen anyway?

By this I mean having rails do the watching for you, or maybe if it can recompile all SCSS every page load in development that is fine too.

Also, perhaps HAML is not loading properly, as if I include the line:

Sass::Plugin.options[:always_update] = true

after my initializer block in environment.rb, then I get the following exception on startup:

/persistent/opt/ruby-enterprise-1.8.7-2009.10/lib/ruby/gems/1.8/gems/activesupport-2.3.5/lib/active_support/dependencies.rb:443:in `load_missing_constant': uninitialized constant Sass (NameError)

I am working with Rails v 2.3.5, and HAML v 3.0.18, and have "config.gem 'haml', :version => '3.0.18'" in my initializer block.

Thanks for your help.


The config.gem "haml" line should load both Haml and Sass. Do you have any old versions of Haml hanging around? Does it work if you load it in a brand new application?


Okay, I seem to have found the solution.

Just including the line

config.gem "haml"

Isn't necessarily all you need, as this gem also needs to be loaded as a plugin to get the rails functionality. So, if you are using config.plugins = [] to limit which plugins are loaded, you need to specifically list 'haml' in there. If you aren't using config.plugins then it's all good, the plugin functionality of the gem will be loaded automatically.

0

精彩评论

暂无评论...
验证码 换一张
取 消