Skip to content

Commit 9fd8128

Browse files
committed
Merge pull request #86 from stefanpenner/subword-uncountable-fix
Corrected behaviour where words that contain uncountable subwords were being treated as uncountable words
2 parents 5eb8993 + 2fe334f commit 9fd8128

File tree

4 files changed

+19
-10
lines changed

4 files changed

+19
-10
lines changed

addon/lib/system/inflector.js

+7-7
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ import Ember from 'ember';
33
var capitalize = Ember.String.capitalize;
44

55
var BLANK_REGEX = /^\s*$/;
6-
var LAST_WORD_DASHED_REGEX = /([\w/-]+[_/-])([a-z\d]+$)/;
7-
var LAST_WORD_CAMELIZED_REGEX = /([\w/-]+)([A-Z][a-z\d]*$)/;
6+
var LAST_WORD_DASHED_REGEX = /([\w/-]+[_/-\s])([a-z\d]+$)/;
7+
var LAST_WORD_CAMELIZED_REGEX = /([\w/-\s]+)([A-Z][a-z\d]*$)/;
88
var CAMELIZED_REGEX = /[A-Z][a-z\d]*$/;
99

1010
function loadUncountable(rules, uncountable) {
@@ -241,7 +241,7 @@ Inflector.prototype = {
241241
*/
242242
inflect: function(word, typeRules, irregular) {
243243
var inflection, substitution, result, lowercase, wordSplit,
244-
firstPhrase, lastWord, isBlank, isCamelized, rule;
244+
firstPhrase, lastWord, isBlank, isCamelized, rule, isUncountable;
245245

246246
isBlank = !word || BLANK_REGEX.test(word);
247247

@@ -260,10 +260,10 @@ Inflector.prototype = {
260260
lastWord = wordSplit[2].toLowerCase();
261261
}
262262

263-
for (rule in this.rules.uncountable) {
264-
if (lowercase.match(rule+"$")) {
265-
return word;
266-
}
263+
isUncountable = this.rules.uncountable[lowercase] || this.rules.uncountable[lastWord];
264+
265+
if (isUncountable) {
266+
return word;
267267
}
268268

269269
for (rule in this.rules.irregular) {

bower.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "ember-inflector",
3-
"version": "1.8.0",
3+
"version": "1.9.1",
44
"dependencies": {
55
"ember": "1.13.5",
66
"ember-cli-shims": "ember-cli/ember-cli-shims#0.0.3",

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "ember-inflector",
3-
"version": "1.9.0",
3+
"version": "1.9.1",
44
"description": "ember-inflector goal is to be rails compatible.",
55
"directories": {
66
"doc": "doc",

tests/unit/inflector-test.js

+10-1
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,6 @@ test('words containing irregular and uncountable words can be pluralized', funct
318318
var inflector = new Ember.Inflector(Ember.Inflector.defaultRules);
319319
assert.equal(inflector.pluralize('woman'), 'women');
320320
assert.equal(inflector.pluralize('salesperson'), 'salespeople');
321-
assert.equal(inflector.pluralize('pufferfish'), 'pufferfish');
322321
});
323322

324323

@@ -329,6 +328,16 @@ test('words containing irregular and uncountable words can be singularized', fun
329328
assert.equal(inflector.singularize('pufferfish'), 'pufferfish');
330329
});
331330

331+
test('partial words containing uncountable words can be pluralized', function(assert) {
332+
var inflector = new Ember.Inflector(Ember.Inflector.defaultRules);
333+
assert.equal(inflector.pluralize('price'), 'prices');
334+
});
335+
336+
test('partial words containing uncountable words can be singularized', function(assert) {
337+
var inflector = new Ember.Inflector(Ember.Inflector.defaultRules);
338+
assert.equal(inflector.singularize('subspecies'), 'subspecy');
339+
});
340+
332341
test('CamelCase and UpperCamelCase is preserved for irregular and uncountable pluralizations', function(assert) {
333342
var inflector = new Ember.Inflector(Ember.Inflector.defaultRules);
334343
assert.equal(inflector.pluralize('SuperWoman'), 'SuperWomen');

0 commit comments

Comments
 (0)