Skip to content

Commit

Permalink
Update README.markdown
Browse files Browse the repository at this point in the history
  • Loading branch information
Hoseong Hwang committed Dec 20, 2011
1 parent ecca32a commit 2567171
Showing 1 changed file with 19 additions and 5 deletions.
24 changes: 19 additions & 5 deletions README.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,33 @@ Update your bundle:

## Usage

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

```javascript
// app/assets/javascripts/dusts/demo.js.dust
/* app/assets/javascripts/dusts/demo.js.dust */

Hello {name}! You have {count} new messages.
```

Which will be compiled and rendered as:

```javascript
(function(){dust.register("post",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;})();
```


In your javascript files, require `dust-core` and your own template files.
I recommend you put all the template files under `assets/javascripts/dusts` and require using `require_tree` for easy use.

```javascript
// app/assets/javascripts/application.js
require dust-core
require_tree ./dusts
/* app/assets/javascripts/application.js */

//= require dust-core
//= require_tree ./dusts
...
dust.render("demo", {name: "Fred", count: 10}, function(err, out) {
console.log(out);
});
```

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

0 comments on commit 2567171

Please sign in to comment.