我有一个 ruby gem,poirot,它可以在 Rails 中使用 mustache 模板。我拥有的模板处理程序是从 ActionView::Template::Handler 扩展而来的,但是这似乎在 Rails 3.1 中已被弃用。
我已经重构了处理程序以遵守弃用警告。在这样做时,我现在无法将本地变量或视图上下文传递给模板。我似乎不知道如何让它与 Rails 3.1 一起工作。
module Poirot
class Handler
attr_reader :template
def initialize(template)
@template = template
end
def self.call(template, *args)
self.new(template).call
end
def call
view_path = "#{template.virtual_path}_view"
abs_view_path = Rails.root.join('app/views', view_path)
view_class = begin
view_path.classify.constantize
rescue NameError => e
Poirot::View
end
"#{view_class}.new(self, '#{template.source.gsub(/'/, "\\\\'")}').render.html_safe"
end
end
end
在我上面的处理程序代码中,我传递了模板,它是 ActionView::Template 的一个实例。但我不确定如何获取视图上下文,其中应该包括本地人等
有人可以指出我正确的方向吗?