mirror of
https://github.com/jsbin/jsbin.git
synced 2026-01-18 15:18:04 +00:00
25 lines
544 B
JavaScript
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 = {};
|