public
Created

MustacheHandler for Rails

  • Download Gist
mustache_hander.rb
Ruby
1 2 3 4 5 6 7 8 9 10 11 12 13 14
class MustacheHandler < ActionView::Template::Handler
include ActionView::Template::Handlers::Compilable
 
# @return [String] its evaled in the context of the action view
# hence the hack below
#
# @param [ActionView::Template]
def compile(template)
mustache_class = ::Mustache
"#{mustache_class}.render('#{template.source}', assigns.merge(local_assigns)).html_safe"
end
end
 
ActionView::Template.register_template_handler(:mustache, MustacheHandler)

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.