From 54838cd90c19bd0b466b1f49fdf5eb16d45c75d3 Mon Sep 17 00:00:00 2001 From: Alan Johnson Date: Wed, 4 Aug 2010 21:54:57 -0400 Subject: [PATCH] Added support for this keyword in paths. --- lib/handlebars.js | 2 ++ test/handlebars.js | 10 ++++++++++ 2 files changed, 12 insertions(+) diff --git a/lib/handlebars.js b/lib/handlebars.js index 73a035d9..a1efa288 100644 --- a/lib/handlebars.js +++ b/lib/handlebars.js @@ -107,6 +107,8 @@ Handlebars.Compiler.prototype = { break; case ".": // 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; default: readDepth = true; diff --git a/test/handlebars.js b/test/handlebars.js index f3620f79..15c231c6 100644 --- a/test/handlebars.js +++ b/test/handlebars.js @@ -47,6 +47,16 @@ test("bad idea nested paths", function() { 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");