summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lib/handlebars/runtime.js6
-rw-r--r--spec/track-ids.js44
2 files changed, 50 insertions, 0 deletions
diff --git a/lib/handlebars/runtime.js b/lib/handlebars/runtime.js
index 5f73897..d41b42a 100644
--- a/lib/handlebars/runtime.js
+++ b/lib/handlebars/runtime.js
@@ -36,6 +36,9 @@ export function template(templateSpec, env) {
function invokePartialWrapper(partial, context, options) {
if (options.hash) {
context = Utils.extend({}, context, options.hash);
+ if (options.ids) {
+ options.ids[0] = true;
+ }
}
partial = env.VM.resolvePartial.call(this, partial, context, options);
@@ -193,6 +196,9 @@ export function resolvePartial(partial, context, options) {
export function invokePartial(partial, context, options) {
options.partial = true;
+ if (options.ids) {
+ options.data.contextPath = options.ids[0] || options.data.contextPath;
+ }
if (partial === undefined) {
throw new Exception('The partial ' + options.name + ' could not be found');
diff --git a/spec/track-ids.js b/spec/track-ids.js
index 88db789..30a4661 100644
--- a/spec/track-ids.js
+++ b/spec/track-ids.js
@@ -190,4 +190,48 @@ describe('track ids', function() {
});
});
});
+
+ describe('partials', function() {
+ var helpers = {
+ blockParams: function(name, options) {
+ return name + ':' + options.ids[0] + '\n';
+ },
+ wycats: function(name, options) {
+ return name + ':' + options.data.contextPath + '\n';
+ }
+ };
+
+ it('should pass track id for basic partial', function() {
+ var template = CompilerContext.compile('Dudes: {{#dudes}}{{> dude}}{{/dudes}}', {trackIds: true}),
+ hash = {dudes: [{name: 'Yehuda', url: 'http://yehuda'}, {name: 'Alan', url: 'http://alan'}]};
+
+ var partials = {
+ dude: CompilerContext.compile('{{wycats name}}', {trackIds: true})
+ };
+
+ equals(template(hash, {helpers: helpers, partials: partials}), 'Dudes: Yehuda:dudes.0\nAlan:dudes.1\n');
+ });
+
+ it('should pass track id for context partial', function() {
+ var template = CompilerContext.compile('Dudes: {{> dude dudes}}', {trackIds: true}),
+ hash = {dudes: [{name: 'Yehuda', url: 'http://yehuda'}, {name: 'Alan', url: 'http://alan'}]};
+
+ var partials = {
+ dude: CompilerContext.compile('{{#each this}}{{wycats name}}{{/each}}', {trackIds: true})
+ };
+
+ equals(template(hash, {helpers: helpers, partials: partials}), 'Dudes: Yehuda:dudes..0\nAlan:dudes..1\n');
+ });
+
+ it('should invalidate context for partials with parameters', function() {
+ var template = CompilerContext.compile('Dudes: {{#dudes}}{{> dude . bar="foo"}}{{/dudes}}', {trackIds: true}),
+ hash = {dudes: [{name: 'Yehuda', url: 'http://yehuda'}, {name: 'Alan', url: 'http://alan'}]};
+
+ var partials = {
+ dude: CompilerContext.compile('{{wycats name}}', {trackIds: true})
+ };
+
+ equals(template(hash, {helpers: helpers, partials: partials}), 'Dudes: Yehuda:true\nAlan:true\n');
+ });
+ });
});