jsbin/lib/hogan.js
2012-07-13 13:38:15 +01:00

25 lines
544 B
JavaScript

var fs = require('fs'),
hogan = require('hogan.js');
// Create a Hogan/Mustache handler for templates.
exports.renderer = function renderer(path, options, fn) {
fs.readFile(path, 'utf8', function (err, template) {
if (err) {
return fn(err);
}
try {
var compiled = exports.templates[path];
if (!compiled) {
compiled = exports.templates[path] = hogan.compile(template);
}
fn(null, compiled.render(options));
} catch (error) {
fn(error);
}
});
};
exports.templates = {};