2013-01-05 24 views
2

我需要使用我的屬性,由於我有一個javascript框架問題雙引號,我已經嘗試設置Haml的:: Template.options哈希作爲文檔使用Rails時建議,但是不會影響「資產」文件夾,無論我在哪裏設置選項。請注意,它正在由Rails的控制器所呈現正常模板的ActionView,但不是在模板中我有{Rails.root}/app/assets/javascripts/templates/*.html.haml選項傳遞到鏈輪發動機

下,這是我在{Rails.root}/config/initializers/haml.rb

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

# Adds the ability to use HAML templates in the asset pipeline for use with 
# Batman.js partials 
Rails.application.assets.register_mime_type 'text/html', '.html' 
Rails.application.assets.register_engine '.haml', Tilt::HamlTemplate 

我也試圖改變register_engine使用Haml::Engine和​​,這兩個都呈現,但仍然沒有采取我上面設置的選項。

如何在資產管道中設置用於渲染的Haml選項?似乎我需要傳遞Sprocket引擎的選項?

回答

0

我找到了解決方案here。 這是關於猴子補丁。

我更喜歡這個變體,因爲它保留了已經爲Haml :: Template設置的選項。 把這個放在你的haml初始化器的末尾。

class Tilt::HamlTemplate 
    def prepare 
    options = @options.merge(:filename => eval_file, :line => line) 
    # Use same options as Haml::Template 
    options = options.merge Haml::Template.options 
    @engine = ::Haml::Engine.new(data, options) 
    end 
end