summaryrefslogtreecommitdiffstats
path: root/lib/template.js
diff options
context:
space:
mode:
authorSamy Pessé <samypesse@gmail.com>2015-01-27 15:58:28 +0100
committerSamy Pessé <samypesse@gmail.com>2015-01-27 15:58:28 +0100
commit750fb862d4e2d68cb65122c85743c0957ca3a3f1 (patch)
tree9f671b1f01c658c87483ba71b99451e208d6b6b3 /lib/template.js
parent131c19dee6db956d758ed4a63ee24dbf087a8c7f (diff)
downloadgitbook-750fb862d4e2d68cb65122c85743c0957ca3a3f1.zip
gitbook-750fb862d4e2d68cb65122c85743c0957ca3a3f1.tar.gz
gitbook-750fb862d4e2d68cb65122c85743c0957ca3a3f1.tar.bz2
Improve tests for plugins with filters
Diffstat (limited to 'lib/template.js')
-rw-r--r--lib/template.js12
1 files changed, 7 insertions, 5 deletions
diff --git a/lib/template.js b/lib/template.js
index 69a1bd5..4b3fdbe 100644
--- a/lib/template.js
+++ b/lib/template.js
@@ -69,14 +69,16 @@ var TemplateEngine = function(book) {
// Add filter
-TemplateEngine.prototype.addFilter = function(key, filter) {
- if (this.env.getFilter(filterName)) {
+TemplateEngine.prototype.addFilter = function(filterName, func) {
+ try {
+ this.env.getFilter(filterName);
this.log.warn.ln("conflict in filters, '"+filterName+"' is already set");
return false;
+ } catch(e) {
+ this.log.debug.ln("add filter '"+filterName+"'");
+ this.env.addFilter(filterName, func, true);
+ return true;
}
- this.log.debug.ln("add filter '"+key+"'");
- this.env.addFilter(key, func, true);
- return true;
};
// Render a string from the book