Git Product home page Git Product logo

dust-rails's Introduction

Dust-Rails

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 http://akdubya.github.com/dustjs/

Installing

Add the following line to your Gemfile:

gem 'dust-rails'

Update your bundle:

bundle install

Usage

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/'
        end
    end

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) {
 		console.log(out);
	});

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

dust-rails's People

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.