Got empty blocks working.
This commit is contained in:
+23
-19
@@ -172,6 +172,7 @@ var Handlebars = {
|
||||
out = out + lookup.call(context, arg, fn);
|
||||
}
|
||||
else if (typeof lookup != 'undefined') {
|
||||
console.log(fn);
|
||||
out = out + Handlebars.helperMissing.call(arg, lookup, fn);
|
||||
}
|
||||
|
||||
@@ -262,29 +263,32 @@ Handlebars.Compiler.prototype = {
|
||||
},
|
||||
|
||||
compile: function(endCondition) {
|
||||
var chr;
|
||||
while(chr = this.getChar()) {
|
||||
if(chr === "{" && this.peek() === "{" && !this.mustache) {
|
||||
this.getChar();
|
||||
this.parseMustache();
|
||||
// if we're at the end condition already then we don't have to do any work!
|
||||
if (!endCondition || !endCondition(this)) {
|
||||
var chr;
|
||||
while(chr = this.getChar()) {
|
||||
if(chr === "{" && this.peek() === "{" && !this.mustache) {
|
||||
this.getChar();
|
||||
this.parseMustache();
|
||||
|
||||
} else {
|
||||
if(chr === "\n") {
|
||||
this.newlines = this.newlines + "\n";
|
||||
chr = "\\n";
|
||||
} else if (chr === "\r") {
|
||||
this.newlines = this.newlines + "\r";
|
||||
chr = "\\r";
|
||||
} else {
|
||||
if(chr === "\n") {
|
||||
this.newlines = this.newlines + "\n";
|
||||
chr = "\\n";
|
||||
} else if (chr === "\r") {
|
||||
this.newlines = this.newlines + "\r";
|
||||
chr = "\\r";
|
||||
}
|
||||
this.text = this.text + chr;
|
||||
}
|
||||
this.text = this.text + chr;
|
||||
}
|
||||
|
||||
if (endCondition && this.peek(5) == "{{^}}") {
|
||||
this.continueInverted = true;
|
||||
this.getChar(5);
|
||||
break;
|
||||
if (endCondition && this.peek(5) == "{{^}}") {
|
||||
this.continueInverted = true;
|
||||
this.getChar(5);
|
||||
break;
|
||||
}
|
||||
else if(endCondition && endCondition(this)) { break };
|
||||
}
|
||||
else if(endCondition && endCondition(this)) { break };
|
||||
}
|
||||
|
||||
this.addText();
|
||||
|
||||
@@ -138,6 +138,16 @@ test("array", function() {
|
||||
|
||||
});
|
||||
|
||||
test("empty block", function() {
|
||||
var string = "{{#goodbyes}}{{/goodbyes}}cruel {{world}}!"
|
||||
var hash = {goodbyes: [{text: "goodbye"}, {text: "Goodbye"}, {text: "GOODBYE"}], world: "world"};
|
||||
shouldCompileTo(string, hash, "cruel world!",
|
||||
"Arrays iterate over the contents when not empty");
|
||||
|
||||
shouldCompileTo(string, {goodbyes: [], world: "world"}, "cruel world!",
|
||||
"Arrays ignore the contents when empty");
|
||||
});
|
||||
|
||||
test("nested iteration", function() {
|
||||
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user