You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

88 lines
2.6 KiB

// Generated by CoffeeScript 1.4.0
var __hasProp = {}.hasOwnProperty,
__extends = 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; };
module.exports = function(BasePlugin) {
var JadePlugin;
return JadePlugin = (function(_super) {
__extends(JadePlugin, _super);
JadePlugin.prototype.name = 'jade';
JadePlugin.prototype.config = {
jadeOptions: {
pretty: false
},
environments: {
development: {
jadeOptions: {
pretty: true
}
}
}
};
function JadePlugin() {
JadePlugin.__super__.constructor.apply(this, arguments);
this.jade = require('jade');
this;
}
JadePlugin.prototype.generateBefore = function() {
var addTemplateDataAsFilter, filters, key, templateData, value;
templateData = this.docpad.getTemplateData();
filters = this.jade.filters;
addTemplateDataAsFilter = function(key, value) {
var _ref;
return (_ref = filters[key]) != null ? _ref : filters[key] = function(str, opts) {
var args;
if (opts.args) {
args = str.split(/\s*\n\s*/);
return value.apply(templateData, args);
} else {
args = [str, opts];
return value.apply(templateData, args);
}
};
};
for (key in templateData) {
if (!__hasProp.call(templateData, key)) continue;
value = templateData[key];
if (Object.prototype.toString.call(value) === '[object Function]') {
addTemplateDataAsFilter(key, value);
}
}
return this;
};
JadePlugin.prototype.render = function(opts, next) {
var config, file, inExtension, jadeOptions, key, templateData, value, _ref;
inExtension = opts.inExtension, templateData = opts.templateData, file = opts.file;
config = this.config;
if (inExtension === 'jade') {
jadeOptions = {
filename: file.get('fullPath')
};
if (config.jadeOptions) {
_ref = config.jadeOptions;
for (key in _ref) {
if (!__hasProp.call(_ref, key)) continue;
value = _ref[key];
jadeOptions[key] = value;
}
}
try {
opts.content = this.jade.compile(opts.content, jadeOptions)(templateData);
} catch (err) {
return next(err);
}
}
return next();
};
return JadePlugin;
})(BasePlugin);
};