From 4989f38ba205dc97215a9aa0a4e7ffbb07e8ccdc Mon Sep 17 00:00:00 2001 From: Alan Johnson Date: Sun, 26 Sep 2010 17:18:57 -0400 Subject: [PATCH] Fixed bug where compiler was continuing to think it was looking at partials after the partial tag was done. Closes GH-14. --- lib/handlebars.js | 2 ++ test/handlebars.js | 11 +++++++++-- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/lib/handlebars.js b/lib/handlebars.js index 26dd7b79..bfddd092 100644 --- a/lib/handlebars.js +++ b/lib/handlebars.js @@ -462,9 +462,11 @@ Handlebars.Compiler.prototype = { return; } else if (this.partial) { this.addPartial(mustache, param) + this.partial = false; return; } else if (this.inverted) { this.addInvertedSection(mustache); + this.inverted = false; return; } else if(this.openBlock) { this.addBlock(mustache, param, parts) diff --git a/test/handlebars.js b/test/handlebars.js index f7c870b4..db9b778c 100644 --- a/test/handlebars.js +++ b/test/handlebars.js @@ -325,7 +325,7 @@ test("basic partials", function() { }); test("partials with context", function() { - var string = "Dudes: {{> dude dudes}}"; + var string = "Dudes: {{>dude dudes}}"; var partial = "{{#this}}{{name}} ({{url}}) {{/this}}"; var hash = {dudes: [{name: "Yehuda", url: "http://yehuda"}, {name: "Alan", url: "http://alan"}]}; shouldCompileTo(string, [hash, {partials: {dude: partial}}], "Dudes: Yehuda (http://yehuda) Alan (http://alan) ", @@ -333,7 +333,7 @@ test("partials with context", function() { }); test("partial in a partial", function() { - var string = "Dudes: {{#dudes}}{{> dude}}{{/dudes}}"; + var string = "Dudes: {{#dudes}}{{>dude}}{{/dudes}}"; var dude = "{{name}} {{> url}} "; var url = "{{url}}"; var hash = {dudes: [{name: "Yehuda", url: "http://yehuda"}, {name: "Alan", url: "http://alan"}]}; @@ -347,6 +347,13 @@ test("rendering undefined partial throws an exception", function() { }, Handlebars.Exception, "Should throw exception"); }); +test("GH-14: a partial preceding a selector", function() { + var string = "Dudes: {{>dude}} {{another_dude}}"; + var dude = "{{name}}"; + var hash = {name:"Jeepers", another_dude:"Creepers"}; + shouldCompileTo(string, [hash, {partials: {dude:dude}}], "Dudes: Jeepers Creepers", "Regular selectors can follow a partial"); +}); + module("safestring"); test("constructing a safestring from a string and checking its type", function() {