Created
December 28, 2013 17:15
-
-
Save alyssais/8161687 to your computer and use it in GitHub Desktop.
A Handlebars template handler for Rails.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$handlebars = Handlebars::Context.new | |
module HandlebarsTemplateHandler | |
def self.call(template) | |
if template.locals.include? "raw" | |
"#{template.source.inspect}.html_safe" | |
else | |
%{ | |
locals = #{template.locals.inspect} | |
vars = Hash[locals.zip(locals.map(&method(:eval)))] | |
$handlebars.compile(#{template.source.inspect}).call(vars).html_safe | |
} | |
end | |
end | |
end | |
ActionView::Template.register_template_handler :handlebars, HandlebarsTemplateHandler | |
ActionView::Template.register_template_handler :hbs, HandlebarsTemplateHandler |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment