Skip to content

Commit

Permalink
always force compilation of templates even if cached (fixes mozilla#130)
Browse files Browse the repository at this point in the history
  • Loading branch information
jlongster committed Sep 26, 2013
1 parent 7e7c754 commit 2ce7930
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 6 deletions.
18 changes: 12 additions & 6 deletions src/environment.js
Expand Up @@ -110,6 +110,10 @@ var Environment = Obj.extend({
var tmpl = this.cache[name];

if(tmpl) {
if(eagerCompile) {
tmpl.compile();
}

if(cb) {
cb(null, tmpl);
}
Expand Down Expand Up @@ -327,9 +331,7 @@ var Template = Obj.extend({
}

return lib.withPrettyErrors(this.path, this.env.dev, function() {
if(!this.compiled) {
this._compile();
}
this.compile();

var context = new Context(ctx || {}, this.blocks);
var syncResult = null;
Expand All @@ -348,9 +350,7 @@ var Template = Obj.extend({
},

getExported: function(cb) {
if(!this.compiled) {
this._compile();
}
this.compile();

// Run the rootRenderFunc to populate the context with exported vars
var context = new Context({}, this.blocks);
Expand All @@ -363,6 +363,12 @@ var Template = Obj.extend({
});
},

compile: function() {
if(!this.compiled) {
this._compile();
}
},

_compile: function() {
var props;

Expand Down
26 changes: 26 additions & 0 deletions tests/api.js
@@ -0,0 +1,26 @@
(function() {
var expect, Environment, Loader, templatesPath;

if(typeof require != 'undefined') {
expect = require('expect.js');
Environment = require('../src/environment').Environment;
Loader = require('../src/node-loaders').FileSystemLoader;
templatesPath = 'tests/templates';
}
else {
expect = window.expect;
Environment = nunjucks.Environment;
Loader = nunjucks.WebLoader;
templatesPath = '../templates';
}

describe('api', function() {
it('should always force compilation of parent template', function() {
var env = new Environment(new Loader(templatesPath));

var parent = env.getTemplate('base.html');
var child = env.getTemplate('base-inherit.html');
expect(child.render()).to.be('Foo*Bar*BazFizzle');
});
});
})();

0 comments on commit 2ce7930

Please sign in to comment.