Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
MustacheHandler for Rails
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"
ActionView::Template.register_template_handler(:mustache, MustacheHandler)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment