Skip to content

Commit

Permalink
Merge branch 'master' of github.com:paularmstrong/swig
Browse files Browse the repository at this point in the history
  • Loading branch information
paularmstrong committed Feb 28, 2012
2 parents b97809c + 7781239 commit 5c5495b
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 8 deletions.
11 changes: 7 additions & 4 deletions lib/parser.js
Expand Up @@ -301,7 +301,8 @@ exports.compile = function compile(indent, parentBlock) {
parent,
filepath,
blockname,
varOutput;
varOutput,
wrappedInMethod;

indent = indent || '';

Expand Down Expand Up @@ -377,14 +378,16 @@ exports.compile = function compile(indent, parentBlock) {
args = (token.args && token.args.length) ? token.args : '';

code += 'if (typeof _context !== "undefined" && typeof _context' + key + ' === "function") {\n';
code += ' _output += ' + helpers.wrapMethod('', { name: name, args: args }, '_context') + ';\n';
wrappedInMethod = helpers.wrapMethod('', { name: name, args: args }, '_context');
code += ' _output = (typeof _output === "undefined") ? ' + wrappedInMethod + ': _output + ' + wrappedInMethod + ';\n';
if (helpers.isValidName(name)) {
code += '} else if (typeof ' + name + ' === "function") {\n';
code += ' _output += ' + helpers.wrapMethod('', { name: name, args: args }) + ';\n';
wrappedInMethod = helpers.wrapMethod('', { name: name, args: args });
code += ' _output = (typeof _output === "undefined") ? ' + wrappedInMethod + ': _output + ' + wrappedInMethod + ';\n';
}
code += '} else {\n';
code += helpers.setVar('__' + name, token);
code += ' _output += __' + name + ';\n';
code += ' _output = (typeof _output === "undefined") ? __' + name + ': _output + __' + name + ';\n';
code += '}\n';
}

Expand Down
2 changes: 1 addition & 1 deletion lib/tags/set.js
Expand Up @@ -22,7 +22,7 @@ module.exports = function (indent, parentBlock, parser) {
value = parser.parseVariable(value);
return ' ' + varname + ' = ' +
'(function () {\n' +
' var _output = "";\n' +
' var _output;\n' +
parser.compile.apply({ tokens: [value] }, [indent, parentBlock]) + '\n' +
' return _output;\n' +
'})();\n';
Expand Down
2 changes: 2 additions & 0 deletions lib/tags/set.test.js
Expand Up @@ -39,6 +39,8 @@ exports.set = testCase({
'set number is really a number [gh-53]': function (test) {
test.strictEqual(swig.compile('{% set foo = 1 %}{{ foo|add(1) }}')(), '2', 'literal number is a number');
test.strictEqual(swig.compile('{% set foo = "1" %}{{ foo|add(1) }}')(), '11', 'string number is not a number');
test.strictEqual(swig.compile('{% set bar = 1 %} {% set foo = bar %}{{ foo|add(1) }}')(), ' 2', 'number remains a number after set from variable');
test.strictEqual(swig.compile('{% set foo = 1 %} {% set foo = foo|add(1) %}{% set foo = foo|add(1) %}{{ foo|add(1) }}')(), ' 4', 'number remains a number after set from filter');
test.done();
}
});
4 changes: 2 additions & 2 deletions package.json
Expand Up @@ -16,8 +16,8 @@
},
"devDependencies": {
"express": ">=2.5.0",
"nodelint": ">=0.5.2",
"nodeunit": ">=0.6.4",
"nodelint": "~0.6",
"nodeunit": "~0.7",
"uglify-js": ">=1.1.0"
},
"main": "index",
Expand Down
2 changes: 1 addition & 1 deletion scripts/runlint.js
Expand Up @@ -22,7 +22,7 @@ function runLint(error, stdout, stderr) {
var files = stdout.trim().replace(/\n/g, ' ');

child_process.exec('node ' + __dirname + '/../node_modules/nodelint/nodelint ' + files + ' --config ' + configFile + '.js', { cwd: config.root }, function (error, stdout, stderr) {
util.puts(stderr);
util.puts(stdout);
});
}

Expand Down

0 comments on commit 5c5495b

Please sign in to comment.