Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support named endblock tags, fix #521 #641

Merged
merged 1 commit into from
Jan 20, 2016
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
7 changes: 5 additions & 2 deletions src/parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -399,12 +399,15 @@ var Parser = Object.extend({
this.advanceAfterBlockEnd(tag.value);

node.body = this.parseUntilBlocks('endblock');
this.skipSymbol('endblock');
this.skipSymbol(node.name.value);

if(!this.peekToken()) {
var tok = this.peekToken();
if(!tok) {
this.fail('parseBlock: expected endblock, got end of file');
}

this.advanceAfterBlockEnd();
this.advanceAfterBlockEnd(tok.value);

return node;
},
Expand Down
7 changes: 7 additions & 0 deletions tests/parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,9 @@
n = parser.parse('{% block foo %}stuff{% endblock %}');
expect(n.children[0].typename).to.be('Block');

n = parser.parse('{% block foo %}stuff{% endblock foo %}');
expect(n.children[0].typename).to.be('Block');

n = parser.parse('{% extends "test.html" %}stuff');
expect(n.children[0].typename).to.be('Extends');

Expand Down Expand Up @@ -674,6 +677,10 @@
parser.parse('hello {% block sdf %} data');
}).to.throwException(/expected endblock/);

expect(function() {
parser.parse('hello {% block sdf %} data{% endblock foo %}');
}).to.throwException(/expected block end/);

expect(function() {
parser.parse('hello {% bar %} dsfsdf');
}).to.throwException(/unknown block tag/);
Expand Down