Last active
December 20, 2015 11:29
-
-
Save teddyzeenny/6124232 to your computer and use it in GitHub Desktop.
Override resolver to account for other namespaces
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
News = Em.Namespace.create(); | |
News.ArticleController = Ember.Controller.extend(); | |
var get = Ember.get; | |
var Resolver = Ember.DefaultResolver.extend({ | |
parseName:function (fullName) { | |
var nameParts = fullName.split(":"), | |
type = nameParts[0], fullNameWithoutType = nameParts[1], | |
name = fullNameWithoutType, | |
namespace = 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); | |
} else if (type !== 'template' && name.underscore().replace('_','.').indexOf('.') !== -1) { | |
var parts = name.underscore().split('_'); | |
var possibleNamespace = parts[0].capitalize(); | |
if (Ember.Namespace.byName(possibleNamespace)) { | |
name = parts.splice(-1).join('_').camelize(); | |
root = Ember.Namespace.byName(possibleNamespace); | |
} | |
} | |
return { | |
fullName: fullName, | |
type: type, | |
fullNameWithoutType: fullNameWithoutType, | |
name: name, | |
root: root, | |
resolveMethodName: "resolve" + Ember.String.classify(type) | |
}; | |
} | |
}); | |
App = Em.Application.create({ | |
resolver: Resolver | |
}); | |
App.deferReadiness(); | |
$(function() { | |
Em.run(App, 'advanceReadiness'); | |
var controller = App.__container__.lookup('controller:news.article'); | |
console.log(controller); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment