由于我有一个Javascript框架问题,我需要在属性上使用双引号,并且我已经尝试在使用Rails时按照文档建议的方式设置Haml::Template.options散列,但是无论我在哪里设置选项,对'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选项?似乎我需要传递链轮引擎的选项?
发布于 2013-01-15 10:36:17
我找到了解决方案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
https://stackoverflow.com/questions/14169801
复制