Using Rails 3 and Haml 3, how do I configure Haml?

ⅰ亾dé卋堺 提交于 2019-12-03 12:36:50

问题


I'm using Rails 3.0.0.beta3 and Haml 3.0.0.rc.2, and I can't find where I need to place the configuration lines for Haml (nor what they are in the new version, for that matter). Using Rails 2.3.5 and Haml 2, I would do

Haml::Template.options[:format] = :html5

in environment.rb. Or, in Sinatra,

set :haml, {:format => :html5}

in my main file. But in Rails 3 everything's been changed around, and no matter where I put that configuration line, I get an undefined method or undefined object error.


回答1:


Create the file:

#{Rails.root}/config/initializers/haml.rb

With haml option:

Haml::Template.options[:attr_wrapper] = '"'



回答2:


In accordance with Rails 3's lazy-loading philosophy, Haml only initializes itself once ActionView::Base is loaded, which may not have happened when the configuration file is being parsed. In order to run code once Haml's been loaded, you need to run it in a ActiveSupport#on_load block. For example:

ActiveSupport.on_load(:action_vew) do
  Haml::Template.options[:format] = :html5
end

I'm considering ways of making the configuration accessible before the full Haml system has been loaded, either by defining Haml::Template.options earlier or adding a special config.haml hash.



来源:https://stackoverflow.com/questions/2726673/using-rails-3-and-haml-3-how-do-i-configure-haml

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