jstransformer-twig
Advanced tools
Comparing version 1.1.1 to 1.1.2
# Changelog | ||
## v1.1.2: 2016-11-16 | ||
- Allow for associative arrays of filter modules | ||
## v1.1.1: 2016-11-16 | ||
@@ -4,0 +8,0 @@ |
27
index.js
@@ -26,7 +26,20 @@ 'use strict'; | ||
for (var name in options.filters || {}) { | ||
var filter = null; | ||
switch (typeof options.filters[name]) { | ||
case "string": | ||
case 'string': | ||
try { | ||
filter = require(options.filters[name]); | ||
// Load the filter module. | ||
var out = require(options.filters[name]); | ||
// Check if the module is just a function. | ||
if (typeof out === 'function') { | ||
Twig.extendFilter(name, out) | ||
} | ||
// Perhaps it is an associative array of functions? | ||
else if (out && (typeof out === 'object')) { | ||
for (var outName in out) { | ||
if (typeof out[outName] === 'function') { | ||
Twig.extendFilter(outName, out[outName]) | ||
} | ||
} | ||
} | ||
} | ||
@@ -37,10 +50,6 @@ catch(err) { | ||
break; | ||
case "function": | ||
default: | ||
filter = options.filters[name]; | ||
case 'function': | ||
Twig.extendFilter(name, options.filters[name]); | ||
break; | ||
} | ||
if (filter) { | ||
Twig.extendFilter(name, filter); | ||
} | ||
} | ||
@@ -47,0 +56,0 @@ |
{ | ||
"name": "jstransformer-twig", | ||
"version": "1.1.1", | ||
"version": "1.1.2", | ||
"description": "Twig.js support for JSTransformers.", | ||
@@ -15,2 +15,3 @@ "dependencies": { | ||
"devDependencies": { | ||
"phone-formatter": "0.0.2", | ||
"slugify": "^1.0.2", | ||
@@ -17,0 +18,0 @@ "test-jstransformer": "^1.0.0" |
5067
52
3