Permalink
Browse files

Allow connectOutlet(outletName, name, context) syntax

  • Loading branch information...
tchak committed Jul 10, 2012
1 parent 2e1a3fa commit 809746b05cc7fc3c278596a60dfbcb3e8b384348
@@ -61,7 +61,12 @@ Ember.ControllerMixin.reopen({
context: App.Post.find()
});
@param {Class} name a view class to instantiate
You can write this as:
applicationController.connectOutlet('master', 'posts', App.Post.find());
@param {String} outletName a name for the outlet to set
@param {String} name a view/controller pair name
@param {Object} context a context object to assign to the
controller's `content` property, if a controller can be
found (optional)
@@ -71,6 +76,8 @@ Ember.ControllerMixin.reopen({
//
// name
// name, context
// outletName, name
// outletName, name, context
// options
//
// The options hash has the following keys:
@@ -89,6 +96,12 @@ Ember.ControllerMixin.reopen({
var outletName, viewClass, view, controller, options;
if (Ember.typeOf(context) === 'string') {
outletName = name;
name = context;
context = arguments[2];
}
if (arguments.length === 1) {
if (Ember.typeOf(name) === 'object') {
options = name;
@@ -65,6 +65,23 @@ test("connectOutlet takes an optional controller context", function() {
equal(view.getPath('controller.content'), context, "the controller receives the context");
});
test("connectOutlet with outletName, name syntax", function() {
var postController = Ember.Controller.create(),
context = {};
var appController = TestApp.ApplicationController.create({
controllers: { postController: postController },
namespace: { PostView: TestApp.PostView }
});
var view = appController.connectOutlet('main', 'post', context);
ok(view instanceof TestApp.PostView, "the view is an instance of PostView");
equal(view.get('controller'), postController, "the controller is looked up on the parent's controllers hash");
equal(appController.get('main'), view, "the app controller's view is set");
equal(view.getPath('controller.content'), context, "the controller receives the context");
});
test("connectOutlet works if all three parameters are provided", function() {
var postController = Ember.Controller.create(),
context = {};

0 comments on commit 809746b

Please sign in to comment.