Created
February 21, 2013 19:43
-
-
Save thebyrd/5007531 to your computer and use it in GitHub Desktop.
Allows you to render `.hbs` templates that are in the views directory
This file contains 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' | |
class HandlebarsHandler < ActionView::Template | |
def self.call(template) | |
# return "Hello World!" | |
<<-RUBY_CODE | |
template = Handlebars::Context.new.compile('#{template.source}') | |
vars = {} | |
partial_renderer = @view_renderer.send(:_partial_renderer) | |
vars.merge!(@_assigns) | |
vars.merge!(local_assigns) | |
# vars.merge!(partial_renderer.instance_variable_get('@options')[:context] || {}) | |
template.call(vars.as_json).html_safe | |
RUBY_CODE | |
end | |
end | |
ActionView::Template.register_template_handler(:hbs, HandlebarsHandler) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment