Skip to content

Instantly share code, notes, and snippets.

@ippy04
Forked from saaji/hbs_renderer.rb
Created December 28, 2011 05:34
Show Gist options
  • Save ippy04/1526560 to your computer and use it in GitHub Desktop.
Save ippy04/1526560 to your computer and use it in GitHub Desktop.
handlebars renderer for Ruby On Rails 3.1 using hbs gem
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