Skip to content

Commit

Permalink
fix multiple levels of super (fixes mozilla#61)
Browse files Browse the repository at this point in the history
  • Loading branch information
jlongster committed Feb 28, 2013
1 parent b64cdd7 commit 10ac70f
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/compiler.js
Original file line number Diff line number Diff line change
Expand Up @@ -633,8 +633,10 @@ var Compiler = Object.extend({
},

compileBlock: function(node, frame) {
this.emitLine(this.buffer + ' += context.getBlock("' +
node.name.value + '")(env, context, frame, runtime);');
if(!this.isChild) {
this.emitLine(this.buffer + ' += context.getBlock("' +
node.name.value + '")(env, context, frame, runtime);');
}
},

compileExtends: function(node, frame) {
Expand Down Expand Up @@ -749,9 +751,9 @@ var Compiler = Object.extend({

// var fs = require("fs");
// var c = new Compiler();
// //var src = '{{ foo({a:1}) }}';
// //var src = '{{ foo({a:1}) }} {% block content %}foo{% endblock %}';
// var src = '{% extends "base.html" %}' +
// '{% block block1 %}{{ super() }}BAR{% endblock %}';
// '{% block block1 %}{{ super() }}{% endblock %}';

// var ns = parser.parse(src);
// nodes.printNodes(ns);
Expand Down
5 changes: 5 additions & 0 deletions tests/compiler.js
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,11 @@ describe('compiler', function() {
var s = render('{% extends "base.html" %}' +
'{% block block1 %}{{ super() }}BAR{% endblock %}');
s.should.equal('FooBarBARBazFizzle');

// two levels of `super` should work
s = render('{% extends "base-inherit.html" %}' +
'{% block block1 %}*{{ super() }}*{% endblock %}');
s.should.equal('Foo**Bar**BazFizzle');
});

it('should include templates', function() {
Expand Down

0 comments on commit 10ac70f

Please sign in to comment.