Permalink
Browse files

Support dot notation in nested routes

When a route is nested, you can override the
default naming conventions by supplying a handler
name with a dot:

```js
App.Router.match('/customers', function(match) {
  match('/customer').to('customers.show');
});
```

This would look for `App.CustomersShowRoute`,
`App.CustomersShowController`, and the
`customers/show` template.

HAT TIP TO @dgeb
  • Loading branch information...
1 parent c66bbed commit 6a165adc15b54ce731e10eb296616efca6a51745 tomhuda committed Jan 10, 2013
Showing with 52 additions and 1 deletion.
  1. +3 −1 packages/ember-routing/lib/system/router.js
  2. +49 −0 packages/ember/tests/routing/basic_test.js
View
4 packages/ember-routing/lib/system/router.js
@@ -194,9 +194,11 @@ function setupRouterDelegate(router, namespace) {
if (context === 'application' || context === undefined) {
return handler;
- } else {
+ } else if (handler.indexOf('.') === -1) {
context = context.split('.').slice(-1)[0];
return context + '.' + handler;
+ } else {
+ return handler;
}
},
View
49 packages/ember/tests/routing/basic_test.js
@@ -839,6 +839,54 @@ test("A redirection hook is provided", function() {
equal(Ember.$("h3:contains(Hours)", "#qunit-fixture").length, 1, "The home template was rendered");
});
+test("Generated names can be customized when providing routes with dot notation", function() {
+ expect(3);
+
+ Ember.TEMPLATES.index = compile("<div>Index</div>");
+ Ember.TEMPLATES.application = compile("<h1>Home</h1><div class='main'>{{outlet}}</div>");
+ Ember.TEMPLATES.top = compile("<div class='middle'>{{outlet}}</div>");
+ Ember.TEMPLATES['foo/bar'] = compile("<div class='bottom'>{{outlet}}</div>");
+ Ember.TEMPLATES['baz/bang'] = compile("<p>{{name}}Bottom!</p>");
+
+ Router.map(function(match) {
+ match("/top").to("top", function(match) {
+ match("/middle").to("foo.bar", function(match) {
+ match("/bottom").to("baz.bang");
+ });
+ });
+ });
+
+ App.FooBarRoute = Ember.Route.extend({
+ renderTemplate: function() {
+ ok(true, "FooBarRoute was called");
+ return this._super.apply(this, arguments);
+ }
+ });
+
+ App.BazBangRoute = Ember.Route.extend({
+ renderTemplate: function() {
+ ok(true, "BazBangRoute was called");
+ return this._super.apply(this, arguments);
+ }
+ });
+
+ App.FooBarController = Ember.Controller.extend({
+ name: "FooBar"
+ });
+
+ App.BazBangController = Ember.Controller.extend({
+ name: "BazBang"
+ });
+
+ bootApplication();
+
+ Ember.run(function() {
+ router.handleURL("/top/middle/bottom");
+ });
+
+ equal(Ember.$('.main .middle .bottom p', '#qunit-fixture').text(), "BazBangBottom!", "The templates were rendered into their appropriate parents");
+});
+
test("Child routes render into their parent route's template by default", function() {
Ember.TEMPLATES.index = compile("<div>Index</div>");
Ember.TEMPLATES.application = compile("<h1>Home</h1><div class='main'>{{outlet}}</div>");
@@ -863,6 +911,7 @@ test("Child routes render into their parent route's template by default", functi
equal(Ember.$('.main .middle .bottom p', '#qunit-fixture').text(), "Bottom!", "The templates were rendered into their appropriate parents");
});
+
test("Parent route context change", function() {
var editCount = 0;

0 comments on commit 6a165ad

Please sign in to comment.