Permalink
Browse files

yeah i'm not so certain about macros at all

  • Loading branch information...
1 parent 0a99958 commit 2108f176abfc6f837d4a417239cce8e8c45a3fc0 @paularmstrong committed Sep 23, 2011
Showing with 17 additions and 12 deletions.
  1. +1 −1 lib/parser.js
  2. +14 −9 lib/tags.js
  3. +2 −2 tests/tags.test.js
View
@@ -42,8 +42,8 @@ function parseVariable(token, escape) {
args = null, filter_name, part;
if ((/\(/).test(varname)) {
- varname = getMethod(varname);
args = getArgs(varname);
+ varname = getMethod(varname);
}
for (part in parts) {
View
@@ -272,14 +272,19 @@ exports.set = function (indent) {
};
exports.macro = function (indent) {
- var macro = this.args.shift();
- console.log(this.args)
-
- return ['var ' + macro + ' = (function () {'
- , ' var __output = [];'
- , parser.compile.call(this, indent + ' ')
- , ' return __output.join("");'
- , '})();'
- ].join('\n' + indent);
+ var macro = this.args.shift(),
+ out = [
+ '__tags[' + macro + '] = function (indent) {',
+ ' var args = ' + this.args + ';'
+ ];
+
+ out.push(parser.compile.call(this, indent + ' '));
+ out.push(' return __output.join("");');
+ out.push('};');
+ out.push('__tags[' + macro + '].ends = false;')
+
+ console.log(out)
+
+ return out.join('\n' + indent);
};
exports.macro.ends = true;
View
@@ -175,13 +175,13 @@ exports.macro = testCase({
},
basic: function (test) {
- var tmpl8 = swig.fromString('{% macro foo %}hi!{% endmacro %}oh, {{ foo }}');
+ var tmpl8 = swig.fromString('{% macro foo %}hi!{% endmacro %}oh, {% foo %}');
test.strictEqual(tmpl8.render({}), 'oh, hi!');
test.done();
},
args: function (test) {
- var tmpl8 = swig.fromString('{% macro foo(input) %}{{ input }}{% endmacro %}oh, {{ foo("yep") }}');
+ var tmpl8 = swig.fromString('{% macro foo input %}{{ input }}{% endmacro %}oh, {% foo "yep" %}');
test.strictEqual(tmpl8.render({}), 'oh, yep');
test.done();
}

0 comments on commit 2108f17

Please sign in to comment.