Permalink
Browse files

fixing filters to allow chaining multiple filters together

  • Loading branch information...
1 parent 72ab345 commit 0b16f89c970844e93f1fde056258eadfc3eaf661 @paularmstrong paularmstrong committed Aug 6, 2011
Showing with 11 additions and 6 deletions.
  1. +6 −6 lib/filters.js
  2. +5 −0 tests/filters.test.js
View
@@ -4,27 +4,27 @@ var helpers = require('./helpers'),
_filters = {
lower: function () {
- return this + '.toString().toLowerCase()';
+ return '(function () { return ' + this + '.toString().toLowerCase(); })()';
},
upper: function () {
- return this + '.toString().toUpperCase()';
+ return '(function () { return ' + this + '.toString().toUpperCase(); })()';
},
capitalize: function () {
- return this + '.toString().charAt(0).toUpperCase() + ' + this + '.toString().substr(1).toLowerCase()';
+ return '(function () { return ' + this + '.toString().charAt(0).toUpperCase() + ' + this + '.toString().substr(1).toLowerCase(); })()';
},
title: function () {
- return this + '.toString().replace(/\\w\\S*/g, function (str) { return str.charAt(0).toUpperCase() + str.substr(1).toLowerCase(); })';
+ return '(function () { return ' + this + '.toString().replace(/\\w\\S*/g, function (str) { return str.charAt(0).toUpperCase() + str.substr(1).toLowerCase(); }); })()';
},
join: function (separator) {
- return 'if (Array.isArray(' + this + ')) { ' + this + '.join(' + separator + '); } else { ' + this + '}';
+ return '(function () { if (Array.isArray(' + this + ')) { return ' + this + '.join(' + separator + '); } else { return ' + this + ' } })()';
},
length: function () {
- return this + '.length';
+ return '(function () { return ' + this + '.length; })()';
}
};
View
@@ -48,3 +48,8 @@ exports.length = function (test) {
test.done();
};
+exports.multiple = function (test) {
+ var input = ['aWEsoMe', 'sAuCe'];
+ test.strictEqual('Awesome Sauce', eval(filters.wrap('input', ['join(\' \')', 'title'])));
+ test.done();
+};

0 comments on commit 0b16f89

Please sign in to comment.