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

[fixes #2723 #2813] opt-out flag for slash being the namespace separator. #3537

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 9 additions & 7 deletions packages/ember-application/lib/system/resolver.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
5 changes: 4 additions & 1 deletion packages/ember-routing/lib/helpers/render.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');

Expand Down
23 changes: 23 additions & 0 deletions packages/ember-routing/tests/helpers/render_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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 = '<h1>BLOG</h1>{{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("<p>POST</p>");

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');
});