Skip to content

Commit

Permalink
Simplify filter
Browse files Browse the repository at this point in the history
  • Loading branch information
tj committed Aug 20, 2010
1 parent 558b773 commit 3952c81
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/ejs/index.js
Expand Up @@ -53,7 +53,7 @@ exports.clearCache = function(){
*/

function filtered(js) {
return js.substr(1).split(/ *\| */).reduce(function(js, filter){
return js.substr(1).split('|').reduce(function(js, filter){
var parts = filter.split(':'),
name = parts.shift(),
args = parts.shift() || '';
Expand Down
13 changes: 13 additions & 0 deletions test/ejs.test.js
Expand Up @@ -198,6 +198,19 @@ module.exports = {
}));
},

'test filter js': function(assert){
var html = 'tj',
str = '<%=: [users[0]] | map:\'name\' | first %>';
assert.equal(html, ejs.render(str, {
locals: {
users: [
{ name: 'tj' },
{ name: 'guillermo' }
]
}
}));
},

'test custom filters': function(assert){
var html = 'Welcome Tj Holowaychuk',
str = '<%=: users | first | greeting %>';
Expand Down

0 comments on commit 3952c81

Please sign in to comment.