I'm using Rails 3.1 and Backbone with the backbone-rails gem. The views are jst.ejs
Is there any way I can use HAML in the views? Are those views precompiled in production environment?
You can use haml_coffee_assets for using haml-coffee templates in the Rails 3.1 asset pipeline. Haml-Coffee is a full HAML implementation in CoffeeScript and with haml_coffee_assets the templates gets compiled in the backend and gets converted in a pure JavaScript template, so no need for CoffeeScript during rendering on the client.
It looks like this is what you're looking for. https://github.com/uglyog/clientside-haml-js
To render Haml on the clientside using backbone (and a jQuery selector):
Put haml.compileHAML(template) in your render() function ala:
render: function(){
var fn = haml.compileHaml(template);
$(this.el).html(fn({});
return this;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With