wintersmith
Version:
A flexible static site generator.
61 lines (50 loc) • 1.78 kB
JavaScript
(function() {
var async, fs, path, pug,
extend = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; },
hasProp = {}.hasOwnProperty;
async = require('async');
fs = require('fs');
pug = require('pug');
path = require('path');
module.exports = function(env, callback) {
var PugTemplate;
PugTemplate = (function(superClass) {
extend(PugTemplate, superClass);
function PugTemplate(fn) {
this.fn = fn;
}
PugTemplate.prototype.render = function(locals, callback) {
var error;
try {
return callback(null, Buffer.from(this.fn(locals)));
} catch (error1) {
error = error1;
return callback(error);
}
};
return PugTemplate;
})(env.TemplatePlugin);
PugTemplate.fromFile = function(filepath, callback) {
return async.waterfall([
function(callback) {
return fs.readFile(filepath.full, callback);
}, (function(_this) {
return function(buffer, callback) {
var conf, error, rv;
conf = env.config.pug || {};
conf.filename = filepath.full;
try {
rv = pug.compile(buffer.toString(), conf);
return callback(null, new _this(rv));
} catch (error1) {
error = error1;
return callback(error);
}
};
})(this)
], callback);
};
env.registerTemplatePlugin('**/*.*(pug|jade)', PugTemplate);
return callback();
};
}).call(this);