Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HAML with Backbone

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?

like image 766
CamelCamelCamel Avatar asked Dec 03 '22 06:12

CamelCamelCamel


2 Answers

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.

like image 117
Netzpirat Avatar answered Dec 14 '22 07:12

Netzpirat


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;
}
like image 21
Chris Biscardi Avatar answered Dec 14 '22 06:12

Chris Biscardi