wintersmith
Version:
A flexible static site generator.
61 lines (50 loc) • 1.79 kB
JavaScript
(function() {
var async, fs, jade, path,
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');
jade = require('jade-legacy');
path = require('path');
module.exports = function(env, callback) {
var JadeTemplate;
JadeTemplate = (function(superClass) {
extend(JadeTemplate, superClass);
function JadeTemplate(fn) {
this.fn = fn;
}
JadeTemplate.prototype.render = function(locals, callback) {
var error;
try {
return callback(null, Buffer.from(this.fn(locals)));
} catch (error1) {
error = error1;
return callback(error);
}
};
return JadeTemplate;
})(env.TemplatePlugin);
JadeTemplate.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.jade || {};
conf.filename = filepath.full;
try {
rv = jade.compile(buffer.toString(), conf);
return callback(null, new _this(rv));
} catch (error1) {
error = error1;
return callback(error);
}
};
})(this)
], callback);
};
env.registerTemplatePlugin('**/*.jade', JadeTemplate);
return callback();
};
}).call(this);