Created
November 13, 2011 00:37
-
-
Save saaji/1361367 to your computer and use it in GitHub Desktop.
handlebars renderer for Ruby On Rails 3.1 using hbs gem
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
require 'handlebars' | |
module HBSTemplateHandler | |
def self.call(template) | |
if template.locals.include? :hbs | |
<<-TEMPLATE | |
template = Handlebars.compile #{template.source.inspect} | |
template.call(hbs || {}).html_safe | |
TEMPLATE | |
else | |
<<-SOURCE | |
#{template.source.inspect}.html_safe | |
SOURCE | |
end | |
end | |
end | |
# Register HBS template handler to render Handlebars templates | |
ActionView::Template.register_template_handler(:hbs, HBSTemplateHandler) | |
# Make HBS'es of handlebars_assets usable from ruby | |
ActionController::Base.append_view_path "app/assets/templates" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment