handlebar_wax
What is it?
HandlebarWax is a gem to let you easily share mustache templates between your server-side and client-side code.
On the server, HandlebarWax uses code borrowed from handlebars-rails to support *.*.hbs as a template type (think foo.html.erb, foo.html.haml, foo.html.hbs). These work pretty much exactly like you would expect they should.
For the client side, HandlebarWax writes all your templates into public/javascripts/handlebars_templates.js, for you to use in your JavaScript code.
How do I use it?
-
Add it to your gemfile.
gem "handlebar_wax"
-
Add it to your layout (it's important that
:handlebar_waxbe a symbol, not a string)javascript_include_tag :handlebar_wax
-
Create view files.
(app/views/users/_user.html.hbs)
{greeting}, {user/name}!
-
Render views from rails. Note that in MustacheWax, hbs templates understand both assigns and locals.
- @user = User.first
render :partial => 'users/user', :locals => => "Hello"
-
Render views from JavaScript
HandlebarWax('users/_user', {name: "Why", greeting: "Frabjous Day"})
Who made this possible?
- Steven Soroka (ssoroka) for pub-based discussion about this, and initial mustache_wax code
- Yehuda Katz and Jamesarosen for handlebars-rails, which this project includes in its entirety, with very few modifications as of yet.
- Yehuda Katz (yes, twice) for the wonderful Handlebars.js.
I want to help / I have an idea.
- I'm all ears. Shoot me an email or a PM.
Copyright
Copyright (c) 2011 Burke Libbey. See LICENSE.txt for further details.