From ac51f74224ff488605c193e3b77515940c589ffa Mon Sep 17 00:00:00 2001 From: Stefan Penner Date: Sun, 6 Oct 2013 11:16:53 -0400 Subject: [PATCH] opt-out flag for slash being the namespace separator. [fixes #2723 #2813] --- .../ember-application/lib/system/resolver.js | 16 +++++++------ packages/ember-routing/lib/helpers/render.js | 5 +++- .../tests/helpers/render_test.js | 23 +++++++++++++++++++ 3 files changed, 36 insertions(+), 8 deletions(-) diff --git a/packages/ember-application/lib/system/resolver.js b/packages/ember-application/lib/system/resolver.js index 5b154257198..892eaf4a899 100644 --- a/packages/ember-application/lib/system/resolver.js +++ b/packages/ember-application/lib/system/resolver.js @@ -151,13 +151,15 @@ Ember.DefaultResolver = Ember.Object.extend({ namespace = get(this, 'namespace'), root = namespace; - if (type !== 'template' && name.indexOf('/') !== -1) { - var parts = name.split('/'); - name = parts[parts.length - 1]; - var namespaceName = capitalize(parts.slice(0, -1).join('.')); - root = Ember.Namespace.byName(namespaceName); - - Ember.assert('You are looking for a ' + name + ' ' + type + ' in the ' + namespaceName + ' namespace, but the namespace could not be found', root); + if (Ember.ENV['EMBER_SLASH_AS_NAMESPACE_SEPARATOR'] !== false) { + if (type !== 'template' && name.indexOf('/') !== -1) { + var parts = name.split('/'); + name = parts[parts.length - 1]; + var namespaceName = capitalize(parts.slice(0, -1).join('.')); + root = Ember.Namespace.byName(namespaceName); + + Ember.assert('You are looking for a ' + name + ' ' + type + ' in the ' + namespaceName + ' namespace, but the namespace could not be found', root); + } } return { diff --git a/packages/ember-routing/lib/helpers/render.js b/packages/ember-routing/lib/helpers/render.js index 80e1f940ce1..25af0941b94 100644 --- a/packages/ember-routing/lib/helpers/render.js +++ b/packages/ember-routing/lib/helpers/render.js @@ -94,7 +94,10 @@ Ember.onLoad('Ember.Handlebars', function(Handlebars) { lookupOptions = { singleton: false }; } - name = name.replace(/\//g, '.'); + if (Ember.ENV['EMBER_SLASH_AS_NAMESPACE_SEPARATOR'] !== false) { + name = name.replace(/\//g, '.'); + } + container = options.data.keywords.controller.container; router = container.lookup('router:main'); diff --git a/packages/ember-routing/tests/helpers/render_test.js b/packages/ember-routing/tests/helpers/render_test.js index d67eefa3f19..2ee255a4253 100644 --- a/packages/ember-routing/tests/helpers/render_test.js +++ b/packages/ember-routing/tests/helpers/render_test.js @@ -58,6 +58,7 @@ module("Handlebars {{render}} helper", { container.register('router:main', Ember.Router.extend()); }, teardown: function() { + delete Ember.ENV['EMBER_SLASH_AS_NAMESPACE_SEPARATOR'] ; Ember.run(function () { if (container) { container.destroy(); @@ -391,3 +392,25 @@ test("{{render}} works with slash notation", function() { equal(renderedView.get('viewName'), 'blogPost', 'camelizes the view name'); equal(container.lookup('controller:blog.post'), renderedView.get('controller'), 'rendered with correct controller'); }); + +test("{{render}} works with slash notation, with EMBER_SLASH_AS_NAMESPACE_SEPARATOR = false", function() { + Ember.ENV['EMBER_SLASH_AS_NAMESPACE_SEPARATOR'] = false; + + var template = '

BLOG

{{render "blog/post"}}'; + + var controller = Ember.Controller.extend({container: container}); + container.register('controller:blog.post', Ember.ObjectController.extend()); + + view = Ember.View.create({ + controller: controller.create(), + template: Ember.Handlebars.compile(template) + }); + + Ember.TEMPLATES['blog/post'] = compile("

POST

"); + + appendView(view); + + var renderedView = container.lookup('router:main')._lookupActiveView('blog/post'); + equal(renderedView.get('viewName'), 'blog/post', 'camelizes the view name'); + equal(container.lookup('controller:blog/post'), renderedView.get('controller'), 'rendered with correct controller'); +});