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

Fixed limitation where macros (and other similar tokens) would not get preserved #132

Merged
merged 4 commits into from
Oct 28, 2012
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
6 changes: 5 additions & 1 deletion lib/parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -394,9 +394,13 @@ function precompile(indent, context) {
}

}
} else if (token.name === 'set') {
} else if (token.type === LOGIC_TOKEN) {
// Preserve any template logic from the extended template.
preservedTokens.push(token);
}
// else, discard any tokens that are not under a LOGIC_TOKEN
// or VAR_TOKEN (for example, static strings).

}
}, this);

Expand Down
50 changes: 50 additions & 0 deletions tests/tags/block.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,56 @@ describe('Tag: block', function () {
tpl = swig.compile(extends1, { filename: 'extends1.html' });
expect(tpl({})).to.equal('Base Content 1\n\n\nOneContent 1\n\nbar\nOneTwoContent\n\nOneContent 2\n\n\nBase Content 2\n');
});

it('block macro inheritance', function () {
var tpl,
extends_base = [
'Base Content 1',
'',
'{% block one %}',
'OneContent 1',
'{% endblock %}',
].join('\n'),
extends1 = [
'{% extends "extends_base.html" %}',
'',
'{% macro custommacro %}',
'hello',
'{% endmacro %}',
'{% block one %}',
'{{ custommacro }}',
'{% endblock %}',
].join('\n');

swig.compile(extends_base, { filename: 'extends_base.html' });
tpl = swig.compile(extends1, { filename: 'extends1.html' });
expect(tpl({})).to.equal('Base Content 1\n\n\n\nhello\n\n');
});

it('block macro inheritance from parent', function () {
var tpl,
extends_base = [
'Base Content 1',
'',
'{% macro custommacro %}',
'hello',
'{% endmacro %}',
'{% block one %}',
'OneContent 1',
'{% endblock %}',
].join('\n'),
extends1 = [
'{% extends "extends_base.html" %}',
'',
'{% block one %}',
'{{ custommacro }}',
'{% endblock %}',
].join('\n');

swig.compile(extends_base, { filename: 'extends_base.html' });
tpl = swig.compile(extends1, { filename: 'extends1.html' });
expect(tpl({})).to.equal('Base Content 1\n\n\n\n\nhello\n\n');
});
});
});