Class: MustacheHandler

Inherits:
ActionView::Template::Handler
  • Object
show all
Includes:
ActionView::Template::Handlers::Compilable
Defined in:
lib/question_chain/mustache_handler.rb

Instance Method Summary collapse

Instance Method Details

#compile(template) ⇒ Object

this string given is evaled in the context of the view_context therefore we can generate from that basis



8
9
10
11
12
13
14
# File 'lib/question_chain/mustache_handler.rb', line 8

def compile(template)
  # virtual path is just a method in the new version of rails so can update from there!
  virtual_path = template.respond_to?(:virtual_path) ? template.virtual_path : template.details[:virtual_path]
  mustache_class_name = "#{virtual_path}_view".classify
  mustache_class = mustache_class_name.constantize
  "#{mustache_class}.new(self, %Q(#{template.source})).render.html_safe"
end