Added support for this keyword in paths.
This commit is contained in:
@@ -107,6 +107,8 @@ Handlebars.Compiler.prototype = {
|
|||||||
break;
|
break;
|
||||||
case ".":
|
case ".":
|
||||||
// do nothing - using .'s is pretty dumb, but it's also basically free for us to support
|
// do nothing - using .'s is pretty dumb, but it's also basically free for us to support
|
||||||
|
case "this":
|
||||||
|
// if we do nothing you'll end up sticking in the same context
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
readDepth = true;
|
readDepth = true;
|
||||||
|
|||||||
@@ -47,6 +47,16 @@ test("bad idea nested paths", function() {
|
|||||||
shouldCompileTo(string, hash, "world world world ", "Same context (.) is ignored in paths");
|
shouldCompileTo(string, hash, "world world world ", "Same context (.) is ignored in paths");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test("this keyword in paths", function() {
|
||||||
|
var string = "{{#goodbyes}}{{this}}{{/goodbyes}}";
|
||||||
|
var hash = {goodbyes: ["goodbye", "Goodbye", "GOODBYE"]};
|
||||||
|
shouldCompileTo(string, hash, "goodbyeGoodbyeGOODBYE",
|
||||||
|
"This keyword in paths evaluates to current context");
|
||||||
|
|
||||||
|
string = "{{#hellos}}{{this/text}}{{/hellos}}"
|
||||||
|
hash = {hellos: [{text: "hello"}, {text: "Hello"}, {text: "HELLO"}]};
|
||||||
|
shouldCompileTo(string, hash, "helloHelloHELLO", "This keyword evaluates in more complex paths");
|
||||||
|
});
|
||||||
|
|
||||||
module("blocks");
|
module("blocks");
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user