summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lib/template.js16
-rw-r--r--test/plugins.js4
2 files changed, 14 insertions, 6 deletions
diff --git a/lib/template.js b/lib/template.js
index 070173c..a34f79b 100644
--- a/lib/template.js
+++ b/lib/template.js
@@ -203,8 +203,9 @@ TemplateEngine.prototype.addBlock = function(name, block) {
// Add shortcuts
if (!_.isArray(block.shortcuts)) block.shortcuts = [block.shortcuts];
_.each(block.shortcuts, function(shortcut) {
- this.log.debug.ln("add template shortcut from '"+shortcut.start+"' to block '"+name+"'");
+ this.log.debug.ln("add template shortcut from '"+shortcut.start+"' to block '"+name+"' for parsers ", shortcut.parsers);
this.shortcuts.push({
+ parsers: shortcut.parsers,
start: shortcut.start,
end: shortcut.end,
tag: {
@@ -216,7 +217,8 @@ TemplateEngine.prototype.addBlock = function(name, block) {
};
// Apply a shortcut to a string
-TemplateEngine.prototype._applyShortcut = function(content, shortcut) {
+TemplateEngine.prototype._applyShortcut = function(parser, content, shortcut) {
+ if (!_.contains(shortcut.parsers, parser)) return content;
var regex = new RegExp(
stringUtils.escapeRegex(shortcut.start) + "\\s*([\\s\\S]*?[^\\$])\\s*" + stringUtils.escapeRegex(shortcut.end),
'g'
@@ -237,11 +239,14 @@ TemplateEngine.prototype.renderString = function(content, context, options) {
version: pkg.version
}
});
- options = _.defaults(options || {}, { path: null});
+ options = _.defaults(options || {}, {
+ path: null,
+ type: null
+ });
if (options.path) options.path = this.book.resolve(options.path);
// Replace shortcuts
- content = _.reduce(this.shortcuts, this._applyShortcut.bind(this), content);
+ content = _.reduce(this.shortcuts, _.partial(this._applyShortcut.bind(this), options.type), content);
return Q.nfcall(this.env.renderString.bind(this.env), content, context, options);
};
@@ -273,7 +278,8 @@ TemplateEngine.prototype.renderPage = function(page) {
};
return that.renderString(page.content, context, {
- path: page.path
+ path: page.path,
+ type: page.type
});
});
};
diff --git a/test/plugins.js b/test/plugins.js
index 43ce497..78f5b44 100644
--- a/test/plugins.js
+++ b/test/plugins.js
@@ -100,7 +100,9 @@ describe('Plugins', function () {
it('should correctly accept shortcuts', function(done) {
qdone(
- books[0].template.renderString('$$hello$$')
+ books[0].template.renderString('$$hello$$', {}, {
+ type: "markdown"
+ })
.then(function(content) {
assert.equal(content, "testhellotest");
}),