forked from geddy/geddy
/
handlebars.js
38 lines (29 loc) · 996 Bytes
/
handlebars.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
var path = require('path')
, TemplatoHandlebars;
TemplatoHandlebars = (function() {
function TemplatoHandlebars() {
try {
this.engine = this.engine || require(path.join(process.cwd(), 'node_modules', 'handlebars'));
} catch(err) {
throw "To use Handlebars you will need to install it: [sudo] npm install [-g] handlebars";
}
};
TemplatoHandlebars.prototype.compile = function(template, options) {
return this.engine.compile(template, options);
};
TemplatoHandlebars.prototype.render = function(data, fn) {
return fn(data);
};
// Iterate over a object of helpers and assign them by name
TemplatoHandlebars.prototype.registerHelper = function(data) {
var helper;
for(helper in data) {
// Only functions are allowed to be assigned
if(typeof data[helper] === 'function') {
this.engine.registerHelper(helper, data[helper]);
}
}
};
return TemplatoHandlebars;
})();
module.exports = TemplatoHandlebars;