summaryrefslogtreecommitdiffstats
path: root/spec/data.js
diff options
context:
space:
mode:
authorkpdecker <kpdecker@gmail.com>2014-02-09 18:35:22 -0600
committerkpdecker <kpdecker@gmail.com>2014-02-09 18:35:22 -0600
commit16f135835eb55dcbb7fa26dab63a9c20fd3981ac (patch)
tree0cffa9a14a7f33b04f2f3431aa829722a3b1a99d /spec/data.js
parentfcec69ae2c838a9df7a456557b57671a80d1732b (diff)
downloadhandlebars.js-16f135835eb55dcbb7fa26dab63a9c20fd3981ac.zip
handlebars.js-16f135835eb55dcbb7fa26dab63a9c20fd3981ac.tar.gz
handlebars.js-16f135835eb55dcbb7fa26dab63a9c20fd3981ac.tar.bz2
Add support for depthed resolution of data fields
Diffstat (limited to 'spec/data.js')
-rw-r--r--spec/data.js35
1 files changed, 19 insertions, 16 deletions
diff --git a/spec/data.js b/spec/data.js
index eab80ef..bb90df5 100644
--- a/spec/data.js
+++ b/spec/data.js
@@ -85,22 +85,6 @@ describe('data', function() {
equals("Hello undefined", result, "@foo as a parameter retrieves template data");
});
- it("parameter data throws when using this scope references", function() {
- var string = "{{#goodbyes}}{{text}} cruel {{@./name}}! {{/goodbyes}}";
-
- shouldThrow(function() {
- CompilerContext.compile(string);
- }, Error);
- });
-
- it("parameter data throws when using parent scope references", function() {
- var string = "{{#goodbyes}}{{text}} cruel {{@../name}}! {{/goodbyes}}";
-
- shouldThrow(function() {
- CompilerContext.compile(string);
- }, Error);
- });
-
it("parameter data throws when using complex scope references", function() {
var string = "{{#goodbyes}}{{text}} cruel {{@foo/../name}}! {{/goodbyes}}";
@@ -251,4 +235,23 @@ describe('data', function() {
equals('hello', result);
});
});
+
+ describe('nesting', function() {
+ it('the root context can be looked up via @root', function() {
+ var template = CompilerContext.compile('{{#helper}}{{#helper}}{{@./depth}} {{@../depth}} {{@../../depth}}{{/helper}}{{/helper}}');
+ var result = template({foo: 'hello'}, {
+ helpers: {
+ helper: function(options) {
+ var frame = Handlebars.createFrame(options.data);
+ frame.depth = options.data.depth + 1;
+ return options.fn(this, {data: frame});
+ }
+ },
+ data: {
+ depth: 0
+ }
+ });
+ equals('2 1 0', result);
+ });
+ });
});