Closed grigio closed 12 years ago
Yes and no. Handlebars is a JavaScript library that is a superset of the mustache syntax. On the master branch I recently made a change to the JavaScript component of poirot to make it possible to use handlebars templates. You can do this on master with the following snippet, presuming that you have included handlebars and poirot earlier.
poirot._viewFactory = function (template, partials) {
var compiledTemplate = Handlebars.compile(template)
return function (data) {
return $(compiledTemplate(data))
}
}
I'm not sure its possible to use handlebars within Rails though, as handlebars is a JavaScript library and I'm not sure a ruby version exists. I have seen it used within Rails via a JavaScript runtime such as The Ruby Racer, I'm not convinced this is a great approach though.
and what about <%= template_include_tag 'post_list' %> ? Will it work too?
Yep that should still work, all it does is pull the contents of a file into a script tag.
Basically everything should work apart from trying to render a handlebars template within ruby. If you do run into any issues please do let me know.
FWIW, there are a few Handlebars gems that run Handlebars.js via the_ruby_racer on the server side. That is one approach.
Yeah I have seen that, however I think its a bit of a weird way to go about it.
Ideally there would be a native ruby implementation of handlebars, if such a gem exists, or gets written, I'd incorporate that into poirot in a similar manner to how you can swap out mustache with handlebars on the client side.
I like this gem but Handlebars seems more flexible, it would be much different to switch or port to a similar template language?