Skip to content

Commit 1c08771

Browse files
committed
Fix track id handling in partials
Fixes #914
1 parent 9f265b9 commit 1c08771

File tree

2 files changed

+50
-0
lines changed

2 files changed

+50
-0
lines changed

lib/handlebars/runtime.js

+6
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@ export function template(templateSpec, env) {
3636
function invokePartialWrapper(partial, context, options) {
3737
if (options.hash) {
3838
context = Utils.extend({}, context, options.hash);
39+
if (options.ids) {
40+
options.ids[0] = true;
41+
}
3942
}
4043

4144
partial = env.VM.resolvePartial.call(this, partial, context, options);
@@ -193,6 +196,9 @@ export function resolvePartial(partial, context, options) {
193196

194197
export function invokePartial(partial, context, options) {
195198
options.partial = true;
199+
if (options.ids) {
200+
options.data.contextPath = options.ids[0] || options.data.contextPath;
201+
}
196202

197203
if (partial === undefined) {
198204
throw new Exception('The partial ' + options.name + ' could not be found');

spec/track-ids.js

+44
Original file line numberDiff line numberDiff line change
@@ -190,4 +190,48 @@ describe('track ids', function() {
190190
});
191191
});
192192
});
193+
194+
describe('partials', function() {
195+
var helpers = {
196+
blockParams: function(name, options) {
197+
return name + ':' + options.ids[0] + '\n';
198+
},
199+
wycats: function(name, options) {
200+
return name + ':' + options.data.contextPath + '\n';
201+
}
202+
};
203+
204+
it('should pass track id for basic partial', function() {
205+
var template = CompilerContext.compile('Dudes: {{#dudes}}{{> dude}}{{/dudes}}', {trackIds: true}),
206+
hash = {dudes: [{name: 'Yehuda', url: 'http://yehuda'}, {name: 'Alan', url: 'http://alan'}]};
207+
208+
var partials = {
209+
dude: CompilerContext.compile('{{wycats name}}', {trackIds: true})
210+
};
211+
212+
equals(template(hash, {helpers: helpers, partials: partials}), 'Dudes: Yehuda:dudes.0\nAlan:dudes.1\n');
213+
});
214+
215+
it('should pass track id for context partial', function() {
216+
var template = CompilerContext.compile('Dudes: {{> dude dudes}}', {trackIds: true}),
217+
hash = {dudes: [{name: 'Yehuda', url: 'http://yehuda'}, {name: 'Alan', url: 'http://alan'}]};
218+
219+
var partials = {
220+
dude: CompilerContext.compile('{{#each this}}{{wycats name}}{{/each}}', {trackIds: true})
221+
};
222+
223+
equals(template(hash, {helpers: helpers, partials: partials}), 'Dudes: Yehuda:dudes..0\nAlan:dudes..1\n');
224+
});
225+
226+
it('should invalidate context for partials with parameters', function() {
227+
var template = CompilerContext.compile('Dudes: {{#dudes}}{{> dude . bar="foo"}}{{/dudes}}', {trackIds: true}),
228+
hash = {dudes: [{name: 'Yehuda', url: 'http://yehuda'}, {name: 'Alan', url: 'http://alan'}]};
229+
230+
var partials = {
231+
dude: CompilerContext.compile('{{wycats name}}', {trackIds: true})
232+
};
233+
234+
equals(template(hash, {helpers: helpers, partials: partials}), 'Dudes: Yehuda:true\nAlan:true\n');
235+
});
236+
});
193237
});

0 commit comments

Comments
 (0)