Skip to content

innovatis/mustache_wax

Repository files navigation

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?

  1. Add it to your gemfile.

    gem "handlebar_wax"
    
  2. Add it to your layout (it’s important that :handlebar_wax be a symbol, not a string)

    = javascript_include_tag :handlebar_wax
  3. Create view files.

    (app/views/users/_user.html.hbs)
    
    <h1>{{greeting}},  {{user/name}}!</h1>
  4. Render views from rails. Note that in MustacheWax, hbs templates understand both assigns and locals.

    - @user = User.first
    = render :partial => 'users/user', :locals => {:greeting => "Hello"}
  5. Render views from JavaScript

    HandlebarWax('users/_user', {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 © 2011 Burke Libbey. See LICENSE.txt for further details.

About

Unified Client + Server side handlebars templating.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages