Created: 2012-03-26 11:15
Updated: 2015-05-03 05:55
License: mit


Using clientside-haml-js with Sprockets and Rails 3.1/3.2


Inspired by haml-sprockets. Use clientside-haml-js to render your haml templates with javascript/coffeescript and haml.

How to use it?

The gem includes clientside-haml-js, JSON-js for IE, underscore and underscore.string. You would not have to download it separately. To use this gem, you need to do the following:

In the Gemfile, add the following line.

gem "cshaml-sprockets"

In app/assets/javascripts/application.js add the following line before //= require_tree .

//=require json2
//=require underscore
//=require underscore.string
//=require haml

Now, you can create cshamljs files under app/assets/javascripts/templates folder. You can create the templates folder, if it does not already exist.

// code for app/assets/javascripts/templates/hello.jst.cshamljs
%h1 Hello HAML

Or to use CoffeeScript in haml templates name the file

// code for app/assets/javascripts/templates/hello.jst.cshamlcoffee
%h1= @model.title

You can now access the template anywhere in your javascript or coffeescript code.

JST["templates/hello"](model: model)

This should give you back the string "<h1>model title</h1>".

Refer to clientside-haml-js for more details.


This is distributed under the MIT license.


(c) 2012 Boris Nadion, Astrails Ltd

Cookies help us deliver our services. By using our services, you agree to our use of cookies Learn more