Permalink
Browse files

fixing filter argument parsing from macros breaking them

  • Loading branch information...
1 parent 58db4c9 commit 1d53aaf9fbe86b83b28ea0ac8dde6d30b999c8d4 @paularmstrong committed Sep 24, 2011
Showing with 9 additions and 6 deletions.
  1. +1 −1 lib/helpers.js
  2. +5 −5 lib/parser.js
  3. +3 −0 tests/templates.test.js
View
@@ -152,7 +152,7 @@ exports.wrapFilter = function (variable, filter) {
if (filters.hasOwnProperty(filter.name)) {
args = [variable];
filter.args.forEach(function (f) {
- args.push('\'' + f.replace(/\\/g, '\\\\') + '\'');
+ args.push('\'' + f.replace(/\\/g, '\\\\').replace(/^\"|\"$/g, '') + '\'');
});
output = '__filters.' + filter.name + '.apply(this, [' + args.toString() + '])';
}
View
@@ -24,29 +24,29 @@ function getMethod(input) {
function getArgs(input) {
var parts = input.replace(/^\w+\(|\)$/g, '').split(', '),
- i = parts.length,
+ l = parts.length,
+ i = 0,
part = '',
partial = '',
out = [];
- while (i) {
- i -= 1;
+ for (; i < l; i += 1) {
part = parts[i];
if ((/^\'|^\"/).test(part) && !(/\"$|\'$/).test(part)) {
partial = part;
continue;
}
if (partial !== '') {
- partial += part;
+ partial += ', ' + part;
if (!(/\"$|\'$/).test(partial)) {
continue;
}
part = partial;
}
out.push(part);
}
- return parts;
+ return out;
}
function parseVariable(token, escape) {
View
@@ -60,6 +60,9 @@ exports.Variables = testCase({
var tmpl8 = swig.fromString('{{ asdf|lower }}');
test.strictEqual(tmpl8.render({ asdf: 'BLAH' }), 'blah');
+
+ tmpl8 = swig.fromString('{{ date|date("F jS, Y") }}');
+ test.strictEqual(tmpl8.render({ date: new Date(2011, 8, 24) }), 'September 24th, 2011');
test.done();
},

0 comments on commit 1d53aaf

Please sign in to comment.