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
3.3 KiB
88 lines
3.3 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 HandlebarsPlugin;
|
|
return HandlebarsPlugin = (function(_super) {
|
|
|
|
__extends(HandlebarsPlugin, _super);
|
|
|
|
HandlebarsPlugin.prototype.name = 'handlebars';
|
|
|
|
HandlebarsPlugin.prototype.handlebars = null;
|
|
|
|
function HandlebarsPlugin() {
|
|
var config, docpad, handlebars, helper, name, partial, _ref, _ref1;
|
|
HandlebarsPlugin.__super__.constructor.apply(this, arguments);
|
|
docpad = this.docpad;
|
|
config = this.config;
|
|
handlebars = this.handlebars = require('handlebars');
|
|
this.precompileOpts = this.config.precompileOpts || {};
|
|
if (this.config.helpers) {
|
|
_ref = this.config.helpers;
|
|
for (name in _ref) {
|
|
if (!__hasProp.call(_ref, name)) continue;
|
|
helper = _ref[name];
|
|
handlebars.registerHelper(name, helper);
|
|
}
|
|
}
|
|
if (this.config.partials) {
|
|
_ref1 = this.config.partials;
|
|
for (name in _ref1) {
|
|
if (!__hasProp.call(_ref1, name)) continue;
|
|
partial = _ref1[name];
|
|
handlebars.registerPartial(name, partial);
|
|
}
|
|
}
|
|
}
|
|
|
|
HandlebarsPlugin.prototype.render = function(opts) {
|
|
var content, handlebars, inExtension, outExtension, output, templateData;
|
|
inExtension = opts.inExtension, outExtension = opts.outExtension, templateData = opts.templateData, content = opts.content;
|
|
handlebars = this.handlebars;
|
|
if (inExtension === 'hb' || inExtension === 'hbs' || inExtension === 'handlebars') {
|
|
if (outExtension === 'js' || outExtension === 'inlinejs') {
|
|
output = this.handlePrecompileOpts(opts);
|
|
} else {
|
|
output = handlebars.compile(opts.content)(templateData);
|
|
}
|
|
return opts.content = output;
|
|
}
|
|
};
|
|
|
|
HandlebarsPlugin.prototype.handlePrecompileOpts = function(opts) {
|
|
var argv, post, pre, templateName, _ref, _ref1, _ref2;
|
|
argv = this.precompileOpts;
|
|
if ((_ref = argv.wrapper) == null) {
|
|
argv.wrapper = "default";
|
|
}
|
|
if ((_ref1 = argv.amdPath) == null) {
|
|
argv.amdPath = "";
|
|
}
|
|
pre = post = "";
|
|
templateName = opts.file.attributes.slug;
|
|
if (argv.wrapper === "amd") {
|
|
pre += 'define([\'' + argv.amdPath + 'handlebars\'], function(Handlebars) {\n';
|
|
}
|
|
if (argv.wrapper === "default") {
|
|
pre += '(function() {\n';
|
|
}
|
|
if (((_ref2 = argv.wrapper) === "default" || _ref2 === "amd")) {
|
|
pre += ' var template = Handlebars.template, templates = Handlebars.templates = Handlebars.templates || {};\n';
|
|
pre += 'templates[\'' + templateName + '\'] = template(';
|
|
post += ');\n';
|
|
}
|
|
if (argv.wrapper === "amd") {
|
|
post += '});';
|
|
}
|
|
if (argv.wrapper === "default") {
|
|
post += '})();';
|
|
}
|
|
return pre + this.handlebars.precompile(opts.content) + post;
|
|
};
|
|
|
|
return HandlebarsPlugin;
|
|
|
|
})(BasePlugin);
|
|
};
|