2

由于我遇到的 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::Engineand Haml::Template,它们都可以渲染,但仍然没有采用我在上面设置的选项。

如何设置 Haml 选项以在资产管道中进行渲染?似乎我需要传递 Sprocket 引擎的选项?

4

1 回答 1

0

我在这里找到了解决方案。这都是关于猴子补丁的。

我更喜欢这种变体,因为它保留了已经为 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
于 2013-01-15T10:36:17.197 回答