summaryrefslogtreecommitdiffstats
path: root/lib/template.js
diff options
context:
space:
mode:
authorSamy Pessé <samypesse@gmail.com>2015-01-27 15:22:42 +0100
committerSamy Pessé <samypesse@gmail.com>2015-01-27 15:22:42 +0100
commit131c19dee6db956d758ed4a63ee24dbf087a8c7f (patch)
tree9b31f135fb12a105f395f298b7468962559778df /lib/template.js
parent870ca4da0c9fa750acba609aff8d129d5a753466 (diff)
downloadgitbook-131c19dee6db956d758ed4a63ee24dbf087a8c7f.zip
gitbook-131c19dee6db956d758ed4a63ee24dbf087a8c7f.tar.gz
gitbook-131c19dee6db956d758ed4a63ee24dbf087a8c7f.tar.bz2
Move plugin helper methods to a specific class
Diffstat (limited to 'lib/template.js')
-rw-r--r--lib/template.js17
1 files changed, 11 insertions, 6 deletions
diff --git a/lib/template.js b/lib/template.js
index 32c46de..69a1bd5 100644
--- a/lib/template.js
+++ b/lib/template.js
@@ -45,6 +45,7 @@ var BookLoader = nunjucks.Loader.extend({
var TemplateEngine = function(book) {
this.book = book;
+ this.log = this.book.log;
// Nunjucks env
this.env = new nunjucks.Environment(
@@ -66,12 +67,16 @@ var TemplateEngine = function(book) {
);
};
-// Add filters
-TemplateEngine.prototype.addFilters = function(filters) {
- _.each(filters, function(func, key) {
- this.book.log.debug.ln("add filter '"+key+"'");
- this.env.addFilter(key, func);
- }, this);
+
+// Add filter
+TemplateEngine.prototype.addFilter = function(key, filter) {
+ if (this.env.getFilter(filterName)) {
+ this.log.warn.ln("conflict in filters, '"+filterName+"' is already set");
+ return false;
+ }
+ this.log.debug.ln("add filter '"+key+"'");
+ this.env.addFilter(key, func, true);
+ return true;
};
// Render a string from the book