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

Allow pluralization to be configurable. #68

Merged
merged 2 commits into from
Oct 9, 2014
Merged
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
2 changes: 1 addition & 1 deletion dist/ember-resolver-spade.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/ember-resolver-tests.js

Large diffs are not rendered by default.

13 changes: 12 additions & 1 deletion dist/ember-resolver.js
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ define("ember/resolver",
var Resolver = Ember.DefaultResolver.extend({
resolveOther: resolveOther,
resolveTemplate: resolveOther,
pluralizedTypes: null,

makeToString: function(factory, fullName) {
return '' + this.namespace.modulePrefix + '@' + fullName + ':';
Expand All @@ -151,6 +152,12 @@ define("ember/resolver",
init: function() {
this._super();
this._normalizeCache = makeDictionary();

this.pluralizedTypes = this.pluralizedTypes || makeDictionary();

if (!this.pluralizedTypes.config) {
this.pluralizedTypes.config = 'config';
}
},
normalize: function(fullName) {
return this._normalizeCache[fullName] || (this._normalizeCache[fullName] = this._normalize(fullName));
Expand All @@ -168,6 +175,10 @@ define("ember/resolver",
}
},

pluralize: function(type) {
return this.pluralizedTypes[type] || (this.pluralizedTypes[type] = type + 's');
},

podBasedLookupWithPrefix: function(podPrefix, parsedName) {
var fullNameWithoutType = parsedName.fullNameWithoutType;

Expand Down Expand Up @@ -203,7 +214,7 @@ define("ember/resolver",
},

defaultModuleName: function(parsedName) {
return this.prefix(parsedName) + '/' + parsedName.type + 's/' + parsedName.fullNameWithoutType;
return this.prefix(parsedName) + '/' + this.pluralize(parsedName.type) + '/' + parsedName.fullNameWithoutType;
},

prefix: function(parsedName) {
Expand Down
2 changes: 1 addition & 1 deletion dist/ember-resolver.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 12 additions & 1 deletion dist/ember-resolver.prod.js
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ define("ember/resolver",
var Resolver = Ember.DefaultResolver.extend({
resolveOther: resolveOther,
resolveTemplate: resolveOther,
pluralizedTypes: null,

makeToString: function(factory, fullName) {
return '' + this.namespace.modulePrefix + '@' + fullName + ':';
Expand All @@ -151,6 +152,12 @@ define("ember/resolver",
init: function() {
this._super();
this._normalizeCache = makeDictionary();

this.pluralizedTypes = this.pluralizedTypes || makeDictionary();

if (!this.pluralizedTypes.config) {
this.pluralizedTypes.config = 'config';
}
},
normalize: function(fullName) {
return this._normalizeCache[fullName] || (this._normalizeCache[fullName] = this._normalize(fullName));
Expand All @@ -168,6 +175,10 @@ define("ember/resolver",
}
},

pluralize: function(type) {
return this.pluralizedTypes[type] || (this.pluralizedTypes[type] = type + 's');
},

podBasedLookupWithPrefix: function(podPrefix, parsedName) {
var fullNameWithoutType = parsedName.fullNameWithoutType;

Expand Down Expand Up @@ -203,7 +214,7 @@ define("ember/resolver",
},

defaultModuleName: function(parsedName) {
return this.prefix(parsedName) + '/' + parsedName.type + 's/' + parsedName.fullNameWithoutType;
return this.prefix(parsedName) + '/' + this.pluralize(parsedName.type) + '/' + parsedName.fullNameWithoutType;
},

prefix: function(parsedName) {
Expand Down
60 changes: 60 additions & 0 deletions dist/modules/ember-resolver-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -425,5 +425,65 @@ test("will not lookup non component templates in components/", function() {
resolver.resolve('template:foo-bar');
});

module("custom pluralization", {
teardown: resetRegistry
});

test("will use the pluralization specified for a given type", function() {
expect(1);

setupResolver({
namespace: {
modulePrefix: 'appkit'
},

pluralizedTypes: {
'sheep': 'sheep',
'octipus': 'octipii'
}
});

define('appkit/sheep/baaaaaa', [], function(){
ok(true, 'custom pluralization used');
return 'whatever';
});

resolver.resolve('sheep:baaaaaa');
});

test("will pluralize 'config' as 'config' by default", function() {
expect(1);

setupResolver();

define('appkit/config/environment', [], function(){
ok(true, 'config/environment is found');
return 'whatever';
});

resolver.resolve('config:environment');
});

test("'config' can be overridden", function() {
expect(1);

setupResolver({
namespace: {
modulePrefix: 'appkit'
},

pluralizedTypes: {
'config': 'super-duper-config'
}
});

define('appkit/super-duper-config/environment', [], function(){
ok(true, 'super-duper-config/environment is found');
return 'whatever';
});

resolver.resolve('config:environment');
});

})();

13 changes: 12 additions & 1 deletion dist/modules/ember-resolver.js
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ define("ember/resolver",
var Resolver = Ember.DefaultResolver.extend({
resolveOther: resolveOther,
resolveTemplate: resolveOther,
pluralizedTypes: null,

makeToString: function(factory, fullName) {
return '' + this.namespace.modulePrefix + '@' + fullName + ':';
Expand All @@ -141,6 +142,12 @@ define("ember/resolver",
init: function() {
this._super();
this._normalizeCache = makeDictionary();

this.pluralizedTypes = this.pluralizedTypes || makeDictionary();

if (!this.pluralizedTypes.config) {
this.pluralizedTypes.config = 'config';
}
},
normalize: function(fullName) {
return this._normalizeCache[fullName] || (this._normalizeCache[fullName] = this._normalize(fullName));
Expand All @@ -158,6 +165,10 @@ define("ember/resolver",
}
},

pluralize: function(type) {
return this.pluralizedTypes[type] || (this.pluralizedTypes[type] = type + 's');
},

podBasedLookupWithPrefix: function(podPrefix, parsedName) {
var fullNameWithoutType = parsedName.fullNameWithoutType;

Expand Down Expand Up @@ -193,7 +204,7 @@ define("ember/resolver",
},

defaultModuleName: function(parsedName) {
return this.prefix(parsedName) + '/' + parsedName.type + 's/' + parsedName.fullNameWithoutType;
return this.prefix(parsedName) + '/' + this.pluralize(parsedName.type) + '/' + parsedName.fullNameWithoutType;
},

prefix: function(parsedName) {
Expand Down
13 changes: 12 additions & 1 deletion packages/ember-resolver/lib/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ define("ember/resolver",
var Resolver = Ember.DefaultResolver.extend({
resolveOther: resolveOther,
resolveTemplate: resolveOther,
pluralizedTypes: null,

makeToString: function(factory, fullName) {
return '' + this.namespace.modulePrefix + '@' + fullName + ':';
Expand All @@ -140,6 +141,12 @@ define("ember/resolver",
init: function() {
this._super();
this._normalizeCache = makeDictionary();

this.pluralizedTypes = this.pluralizedTypes || makeDictionary();

if (!this.pluralizedTypes.config) {
this.pluralizedTypes.config = 'config';
}
},
normalize: function(fullName) {
return this._normalizeCache[fullName] || (this._normalizeCache[fullName] = this._normalize(fullName));
Expand All @@ -157,6 +164,10 @@ define("ember/resolver",
}
},

pluralize: function(type) {
return this.pluralizedTypes[type] || (this.pluralizedTypes[type] = type + 's');
},

podBasedLookupWithPrefix: function(podPrefix, parsedName) {
var fullNameWithoutType = parsedName.fullNameWithoutType;

Expand Down Expand Up @@ -192,7 +203,7 @@ define("ember/resolver",
},

defaultModuleName: function(parsedName) {
return this.prefix(parsedName) + '/' + parsedName.type + 's/' + parsedName.fullNameWithoutType;
return this.prefix(parsedName) + '/' + this.pluralize(parsedName.type) + '/' + parsedName.fullNameWithoutType;
},

prefix: function(parsedName) {
Expand Down
60 changes: 60 additions & 0 deletions packages/ember-resolver/tests/core_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -362,3 +362,63 @@ test("will not lookup non component templates in components/", function() {

resolver.resolve('template:foo-bar');
});

module("custom pluralization", {
teardown: resetRegistry
});

test("will use the pluralization specified for a given type", function() {
expect(1);

setupResolver({
namespace: {
modulePrefix: 'appkit'
},

pluralizedTypes: {
'sheep': 'sheep',
'octipus': 'octipii'
}
});

define('appkit/sheep/baaaaaa', [], function(){
ok(true, 'custom pluralization used');
return 'whatever';
});

resolver.resolve('sheep:baaaaaa');
});

test("will pluralize 'config' as 'config' by default", function() {
expect(1);

setupResolver();

define('appkit/config/environment', [], function(){
ok(true, 'config/environment is found');
return 'whatever';
});

resolver.resolve('config:environment');
});

test("'config' can be overridden", function() {
expect(1);

setupResolver({
namespace: {
modulePrefix: 'appkit'
},

pluralizedTypes: {
'config': 'super-duper-config'
}
});

define('appkit/super-duper-config/environment', [], function(){
ok(true, 'super-duper-config/environment is found');
return 'whatever';
});

resolver.resolve('config:environment');
});