Allow passing depths to _child
This commit is contained in:
@@ -426,11 +426,11 @@ export function compile(input, options, env) {
|
||||
}
|
||||
return compiled._setup(options);
|
||||
};
|
||||
ret._child = function(i) {
|
||||
ret._child = function(i, data, depths) {
|
||||
if (!compiled) {
|
||||
compiled = compileInput();
|
||||
}
|
||||
return compiled._child(i);
|
||||
return compiled._child(i, data, depths);
|
||||
};
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -149,12 +149,12 @@ export function template(templateSpec, env) {
|
||||
}
|
||||
};
|
||||
|
||||
ret._child = function(i) {
|
||||
if (templateSpec.useDepths) {
|
||||
throw new Exception('_child can not be used with depthed templates');
|
||||
ret._child = function(i, data, depths) {
|
||||
if (templateSpec.useDepths && !depths) {
|
||||
throw new Exception('must pass parent depths');
|
||||
}
|
||||
|
||||
return program(container, i, templateSpec[i]);
|
||||
return program(container, i, templateSpec[i], data, depths);
|
||||
};
|
||||
return ret;
|
||||
}
|
||||
|
||||
+9
-2
@@ -39,18 +39,25 @@ describe('runtime', function() {
|
||||
return;
|
||||
}
|
||||
|
||||
it('should throw for depthed methods', function() {
|
||||
it('should throw for depthed methods without depths', function() {
|
||||
shouldThrow(function() {
|
||||
var template = Handlebars.compile('{{#foo}}{{../bar}}{{/foo}}');
|
||||
// Calling twice to hit the non-compiled case.
|
||||
template._setup({});
|
||||
template._setup({});
|
||||
template._child(1);
|
||||
}, Error, '_child can not be used with depthed templates');
|
||||
}, Error, 'must pass parent depths');
|
||||
});
|
||||
it('should expose child template', function() {
|
||||
var template = Handlebars.compile('{{#foo}}bar{{/foo}}');
|
||||
// Calling twice to hit the non-compiled case.
|
||||
equal(template._child(1)(), 'bar');
|
||||
equal(template._child(1)(), 'bar');
|
||||
});
|
||||
it('should render depthed content', function() {
|
||||
var template = Handlebars.compile('{{#foo}}{{../bar}}{{/foo}}');
|
||||
// Calling twice to hit the non-compiled case.
|
||||
equal(template._child(1, undefined, [{bar: 'baz'}])(), 'baz');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user