ref. http://net.tutsplus.com/tutorials/javascript-ajax/introduction-to-handlebars/
http://berzniz.com/post/24743062344/handling-handlebars-js-like-a-pro
== Handlebars precompiling templates
1. download the Node.js package through npm :
sudo npm install handlebars -g
2. create a file for your template and compile it like so: -m: minimize output
app/assets/javascripts> mkdir templates
vim hello.handlebars
<p>Hello {{name}}</p>
handlebars ./templates/ -f ./templates/templates.js -m
3. simply include the output file along with the run-time version(handlebars.runtime.js) of Handlebars (you can use the regular version, but it’s larger) and type the following:
vim application.js
//= require handlebars-1.0.rc.1.min
//= require ./templates/templates
or
//= require andlebars.runtime
//= require ./templates/templates
Source Code:
var template = Handlebars.templates['hello'];
var html = template({ name: ‘World’ });
Mixing precompiling and runtime compiling templates
Handlebars.getTemplate = function(name) {
if (Handlebars.templates === undefined || Handlebars.templates[name] === undefined) {
$.ajax({
url : 'templates/' + name + '.handlebars',
success : function(data) {
if (Handlebars.templates === undefined) {
Handlebars.templates = {};
}
Handlebars.templates[name] = Handlebars.compile(data);
},
async : false
});
}
return Handlebars.templates[name];
};