Permalink
Browse files

removing duplication in favor of helpers.setVar

  • Loading branch information...
1 parent 32d219e commit fcc569ce6b5b298205f5e4f5e2544dc8a04cadfc @paularmstrong committed Sep 16, 2011
Showing with 5 additions and 10 deletions.
  1. +2 −2 lib/helpers.js
  2. +3 −8 lib/parser.js
View
@@ -178,9 +178,9 @@ exports.wrapFilters = function (variable, filters, context, escape) {
exports.setVar = function (varName, argument) {
var out = 'var ' + varName + ';' +
'if (' + check(argument.name) + ') {' +
- ' ' + varName + ' = ' + exports.wrapFilters(exports.escape(argument.name), argument.filters, null, false) + ';' +
+ ' ' + varName + ' = ' + exports.wrapFilters(exports.escape(argument.name), argument.filters, null, argument.escape) + ';' +
'} else if (' + check(argument.name, '__context') + ') {' +
- ' ' + varName + ' = ' + exports.wrapFilters(exports.escape(argument.name), argument.filters, '__context', false) + ';' +
+ ' ' + varName + ' = ' + exports.wrapFilters(exports.escape(argument.name), argument.filters, '__context', argument.escape) + ';' +
'}';
return out;
View
@@ -189,14 +189,9 @@ exports.compile = function compile(indent, parentBlock) {
}
if (token.type === VAR_TOKEN) {
- varOutput = token.name;
- return code.push(
- 'if (' + check(varOutput) + ') {'
- , ' __output.push(' + helpers.wrapFilters(varOutput, token.filters, null, token.escape) + ');'
- , '} else if (' + check(varOutput, '__context') + ') {'
- , ' __output.push(' + helpers.wrapFilters(varOutput, token.filters, '__context', token.escape) + ');'
- , '}'
- );
+ var name = token.name.replace(/\W/g, '_');
+ code.push(helpers.setVar('__' + name, token));
+ code.push('__output.push(__' + name + ');');
}
if (token.type !== LOGIC_TOKEN) {

0 comments on commit fcc569c

Please sign in to comment.