Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUGFIX release] Fix nested render helpers #10843

Merged
merged 2 commits into from
Apr 8, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 7 additions & 0 deletions packages/ember-routing-htmlbars/lib/helpers/render.js
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,13 @@ function impersonateAnOutlet(currentView, view, name) {
view._isOutlet = true;
view._outletName = '__ember_orphans__';
view._matchOutletName = name;
view._parentOutlet = function() {
var parent = this._parentView;
while (parent && !parent._isOutlet) {
parent = parent._parentView;
}
return parent;
};
view.setOutletState = function(state) {
var ownState;
if (state && (ownState = state.outlets[this._matchOutletName])) {
Expand Down
17 changes: 17 additions & 0 deletions packages/ember-routing-htmlbars/tests/helpers/render_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,23 @@ QUnit.test("{{render}} helper should render given template", function() {
ok(container.lookup('router:main')._lookupActiveView('home'), 'should register home as active view');
});

QUnit.test("{{render}} helper should render nested helpers", function() {
var template = "<h1>HI</h1>{{render 'foo'}}";
var controller = EmberController.extend({ container: container });
view = EmberView.create({
controller: controller.create(),
template: compile(template)
});

Ember.TEMPLATES['foo'] = compile("<p>FOO</p>{{render 'bar'}}");
Ember.TEMPLATES['bar'] = compile("<p>BAR</p>{{render 'baz'}}");
Ember.TEMPLATES['baz'] = compile("<p>BAZ</p>");

runAppend(view);

equal(view.$().text(), 'HIFOOBARBAZ');
});

QUnit.test("{{render}} helper should have assertion if neither template nor view exists", function() {
var template = "<h1>HI</h1>{{render 'oops'}}";
var controller = EmberController.extend({ container: container });
Expand Down
54 changes: 54 additions & 0 deletions packages/ember/tests/routing/basic_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3850,3 +3850,57 @@ QUnit.test("Can disconnect from the render helper's children", function() {
Ember.run(router, 'send', 'disconnect');
equal(Ember.$('#qunit-fixture .foo .index').text(), '');
});

QUnit.test("Can render({into:...}) nested render helpers", function() {
Ember.TEMPLATES.application = compile('{{render "foo"}}');
Ember.TEMPLATES.foo = compile('<div class="foo">{{render "bar"}}</div>');
Ember.TEMPLATES.bar = compile('<div class="bar">{{outlet}}</div>');
Ember.TEMPLATES.index = compile('other');
Ember.TEMPLATES.baz = compile('baz');

App.IndexRoute = Ember.Route.extend({
renderTemplate: function() {
this.render({ into: 'bar' });
},
actions: {
changeToBaz: function() {
this.disconnectOutlet({
parentView: 'bar',
outlet: 'main'
});
this.render('baz', { into: 'bar' });
}
}
});

bootApplication();
equal(Ember.$('#qunit-fixture .bar').text(), 'other');
Ember.run(router, 'send', 'changeToBaz');
equal(Ember.$('#qunit-fixture .bar').text(), 'baz');
});

QUnit.test("Can disconnect from nested render helpers", function() {
Ember.TEMPLATES.application = compile('{{render "foo"}}');
Ember.TEMPLATES.foo = compile('<div class="foo">{{render "bar"}}</div>');
Ember.TEMPLATES.bar = compile('<div class="bar">{{outlet}}</div>');
Ember.TEMPLATES.index = compile('other');

App.IndexRoute = Ember.Route.extend({
renderTemplate: function() {
this.render({ into: 'bar' });
},
actions: {
disconnect: function() {
this.disconnectOutlet({
parentView: 'bar',
outlet: 'main'
});
}
}
});

bootApplication();
equal(Ember.$('#qunit-fixture .bar').text(), 'other');
Ember.run(router, 'send', 'disconnect');
equal(Ember.$('#qunit-fixture .bar').text(), '');
});