Find file
Fetching contributors…
Cannot retrieve contributors at this time
73 lines (45 sloc) 2.08 KB

Now following LinkedIn managed version as original repository is not being updated anymore.


This gem adds the Dust template and a corresponding assets engine to the asset pipeline in Rails => 3.1 applications.

For detailed information about Dust, visit


Add the following line to your Gemfile:

gem 'dust-rails'

Update your bundle:

bundle install


Place individual Dust template file in their own file with template_name.js.dust extension.

	/* app/assets/javascripts/templates/demo.js.dust */
	Hello {name}! You have {count} new messages.

Which will be compiled and rendered as:

	(function(){dust.register("demo",body_0);function body_0(chk,ctx){return chk.write("Hello ").reference(ctx.get("name"),ctx,"h").write("! You have ").reference(ctx.get("count"),ctx,"h").write(" new messages.");}return body_0;})();

Dust-rails resolves the name of the template out of relative path of each template file. Relative path starts from app/assets/javascripts/templates/ by default.

app/assets/javascripts/templates/demo1.js.dust -> demo1
app/assets/javascripts/templates/demos/demo2.js.dust -> demos/demo2

If you want to change the default root path of template files, add following configuration into application.rb:

    # config/application.rb
    module YourApp
        class Application < Rails::Application
            config.dust.template_root = 'app/assets/your_path_to_templates/'

In your javascript files, require dust-core and your own template files. Using require_tree is recommended if you want to require all the template files at once.

	/* app/assets/javascripts/application.js */
	//= require dust-core
	//= require_tree ./templates
	dust.render("demo", {name: "Fred", count: 10}, function(err, out) {

To include dust-helpers, add require dust-helpers after dust-core in application.js

All done. Your template files will be compiled and registered.