Rails 3.1 Template Handlers

I have a ruby ​​stone, poirot , which allows me to use mustache patterns in Rails. The template handler I have extends from ActionView :: Template :: Handler, however this does not seem to be recommended in Rails 3.1.

I reinstalled the handler to execute the deprecation warnings. However, I can’t pass the template to the locals or to the presentation context. I cannot understand how this works with 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

In my code above for the handler, I pass a template that is an instance of ActionView :: Template. But I'm not sure how to get the view context, which should include locals, etc.

Can someone point me in the right direction?

+5
2

, , , , , !

, :

locals = view_context.send(:view_renderer).send(:_partial_renderer).instance_variable_get("@locals") || {}

, view_renderer, _partial_renderer , locals ivar.

, !

0

4 , , :

"local_assigns", .

:

"#{view_class}.new(self, '#{template.source.gsub(/'/, "\\\\'")}', local_assigns).render.html_safe"

- ActionView::CompiledTemplates local_assigns .

0

All Articles