Skip to content
This repository has been archived by the owner on Apr 11, 2018. It is now read-only.

Fixing issue #499 #502

Merged
merged 2 commits into from
Jul 29, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions lib/tags/macro.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,11 @@ exports.compile = function (compiler, args, content, parents, options, blockName
return '_ctx.' + fnName + ' = function (' + args.join('') + ') {\n' +
' var _output = "";\n' +
' __ctx = _utils.extend({}, _ctx),\n' +
' _ctx = _utils.extend({}, __ctx);\n' +
' _utils.each(_ctx, function (v, k) {\n' +
' if (["' + args.join('","') + '"].indexOf(k) !== -1) { delete _ctx[k]; }\n' +
' });\n' +
compiler(content, parents, options, blockName) + '\n' +
' _ctx = __ctx;\n' +
' _ctx = _utils.extend(_ctx, __ctx);\n' +
' return _output;\n' +
'};\n' +
'_ctx.' + fnName + '.safe = true;\n';
Expand Down
4 changes: 4 additions & 0 deletions tests/tags/macro.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,8 @@ describe('Tag: macro', function () {
it('gh-457: local context is copied and overwritten within macro context', function () {
expect(swig.render('{% set foo = 1 %}{% set baz = 3 %}{% macro bar(foo) %}{{ foo }}{{ baz }}{% endmacro %}{{ bar(2) }}{{ foo }}')).to.equal('231');
});

it('gh-499: a macro can be set to a variable', function () {
expect(swig.render('{% macro burrito() %}burrito{% endmacro %}{% set foo = burrito() %}{{foo}}')).to.equal('burrito');
});
});