Revert "ES6: Uses proper normalize method, includes support for namespaced"

This reverts commit b98324a937.
This commit is contained in:
Robin Ward 2014-05-05 13:58:42 -04:00
parent 389c50eb1e
commit 69225a7ea9
3 changed files with 28 additions and 36 deletions

View File

@ -6,7 +6,7 @@
@namespace Discourse
@module Discourse
**/
export default Discourse.ObjectController.extend({
Discourse.BadgesShowController = Discourse.ObjectController.extend({
grantDates: Em.computed.mapBy('userBadges', 'grantedAt'),
minGrantedAt: Em.computed.min('grantDates'),

View File

@ -7,50 +7,31 @@
@namespace Discourse
@module Discourse
**/
var classify = Ember.String.classify;
var get = Ember.get;
function parseName(fullName) {
/*jshint validthis:true */
var nameParts = fullName.split(":"),
type = nameParts[0], fullNameWithoutType = nameParts[1],
name = fullNameWithoutType,
namespace = get(this, 'namespace'),
root = namespace;
return {
fullName: fullName,
type: type,
fullNameWithoutType: fullNameWithoutType,
name: name,
root: root,
resolveMethodName: "resolve" + classify(type)
};
}
Discourse.Resolver = Ember.DefaultResolver.extend({
parseName: parseName,
/**
For our ES6 modules, Discourse standardizes on dashed, lower case names.
This method converts camelCase to that format.
normalize: function(fullName) {
var split = fullName.split(':');
if (split.length > 1) {
var dashed = Ember.String.dasherize(split[1].replace(/\./g, '/')),
moduleName = 'discourse/' + split[0] + 's/' + dashed;
if (requirejs.entries[moduleName]) {
return split[0] + ":" + dashed;
}
}
return this._super(fullName);
@method normalizeName
@param {String} name to convert
@returns {String} the converted name
**/
normalizeName: function(name) {
return name.replace(/([a-z])([A-Z])/g, '$1-$2').replace('_', '-').toLowerCase();
},
resolveController: function(parsedName) {
var moduleName = 'discourse/controllers/' + parsedName.fullNameWithoutType,
var normalized = this.normalizeName(parsedName.fullNameWithoutType),
moduleName = "discourse/controllers/" + normalized,
module = requirejs.entries[moduleName];
if (module) {
if (normalized !== parsedName.fullNameWithoutType) {
Em.Logger.error(parsedName.fullNameWithoutType + " was used to look up an ES6 module. You should use " + normalized+ " instead.");
}
module = require(moduleName, null, null, true /* force sync */);
if (module && module['default']) { module = module['default']; }
}

View File

@ -14,6 +14,11 @@ function setTemplates(lookupStrings) {
});
}
function normalized(input, expected, desc) {
var resolver = Discourse.Resolver.create({namespace: Discourse});
equal(resolver.normalizeName(input), expected, desc);
}
module("Discourse.Resolver", {
setup: function() {
originalTemplates = Ember.TEMPLATES;
@ -29,6 +34,12 @@ module("Discourse.Resolver", {
}
});
test("normalizeName", function() {
normalized('header', 'header', 'a single word stays the same');
normalized('avatarSelector', 'avatar-selector', 'camel case is converted to dashed');
normalized('avatar_selector', 'avatar-selector', 'underscores are converted to dashes');
});
test("finds templates in top level dir", function() {
setTemplates([
"foobar",