-
Notifications
You must be signed in to change notification settings - Fork 67
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add Rails template handler #2
Comments
On RoR 3.1: initializerz/template_handlers.rbrequire 'action_view/template/handlers/handlebars'
ActionView::Template.register_template_handler(:hbs, ActionView::Template::Handlers::Handlebars.new) # lib/action_view/template/handlers/handlebars.rb require 'handlebars'
class ActionView::Template::Handlers::Handlebars
def call(template)
<<-RUBY_CODE
template = Handlebars.compile('#{template.source}');
vars = {}
partial_renderer = @view_renderer.send(:_partial_renderer)
vars.merge!(@_assigns)
vars.merge!(partial_renderer.instance_variable_get('@locals'))
vars.merge!(partial_renderer.instance_variable_get('@options')[:context] || {})
template.call(vars.as_json).html_safe
RUBY_CODE
end
end
Just place your |
I had some errors with the above and made a couple of modifications: require 'handlebars'
class ActionView::Template::Handlers::Handlebars
def call(template)
<<-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 This is using a HandleBars::Context instance rather than Handlebars global; and local_assigns rather than @Locals. I'm not sure how to fix the @options. |
I have a handlebars-rails template handler that supports partials and more. https://github.com/cowboyd/handlebars-rails @jamesarosen any chance you can give me the keys to the rubygem? |
@wycats is the only owner on Rubygems; he'll have to do it. |
@cowboyd you are now an owner! |
See the following for a good example:
I just forked the project to give this a go. I'll update with findings as I go.
The text was updated successfully, but these errors were encountered: