由于我遇到的Javascript框架问题,我需要在我的属性上使用双引号,并且我已经尝试设置Haml :: Template.options哈希,因为文档在使用Rails时建议,但是没有影响对于'assets'文件夹,无论我在哪里设置选项。注意,它正在处理由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::Template
,它们都会渲染,但仍然没有采用我在上面设置的选项。
如何在资产管道中设置Haml选项以进行渲染?看来我需要传递Sprocket引擎的选项吗?
答案 0 :(得分: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