emberjs / ember-inflector Goto Github PK
View Code? Open in Web Editor NEWember-inflector goal is to be rails compatible.
License: MIT License
ember-inflector goal is to be rails compatible.
License: MIT License
Ember.Inflector.inflector.singularize('alumnus'); // "alumnu"
Not sure if this is the proper place to report, but ran into this issue today:
var inflector = Ember.Inflector.inflector;
inflector.singularize('drives')
// > "drife"
I'm also happy to take a crack at fixing this, but just wanted to ensure this fix actually belongs upstream and not in the app itself
during ember-data's es6ification this project was forgotten, now it is tricky to propagate changes/fixes from the source project to it being vendored in ember-data
cc @fivetanely
We do not export Ember.HTMLBars.helper
. See: https://github.com/emberjs/ember.js/blob/master/packages/ember-htmlbars/lib/main.js#L70-L79
https://github.com/stefanpenner/ember-inflector/blob/master/packages/ember-inflector/lib/helpers.js#L18-L20 needs to be:
Ember.HTMLBars._registerHelper('singularize', Ember.HTMLBars.makeBoundHelper(function(params){
return singularize(params[0]);
}));
I've been investigating emberjs/data#1447 and have narrowed the issue down to only applying to camel cased words. It would appear to be due to the lower casing of a word before checking for matching rules.
I have added a unit test to the test suite on my fork of the ember data repository but I don't know if you'd prefer the test to be submitted to that repository or this one?
And then just set up stuff on prototypes and Ember.String
Something like https://github.com/dreamerslab/node.inflection/ maybe?
Versions on my systems
ember-cli: 0.1.3
Ember: 0.1.7
Watchman: 3.0.0
Mac OS X: 10.10
Node: 0.11.14
I followed the instructions on the first page
npm install --save ember-inflector
ember generate ember-inflector
I then imported both ember-inflector.js, and ember-inflector.js.map to my brocfile, this didn't seem to be the cause of my issues as I was having the same issues before I imported them also
and none of the suggested solutions have been working, I am getting undefined when I do
Ember.Inflector.pluralize("taco");
and ember-inflector can't be resolved in the browser console when trying to import it
import Inflector from 'ember-inflector';
import {singularize, pluralize} from 'ember-inflector';
I tried taking out the node module and bower component then reinstalling just the bower component and just use the Ember.Inflector syntax in my app and still seeing same issues
any advice?
Would it be possible to get an ember-addon version of this? The other issue for creating a bower package would be helpful too, but an ember-addon would be great!
this involves me figuring out how interproject dependencies work
it appears that the util for selecting how the helpers are registered is not working properly for me
https://github.com/stefanpenner/ember-inflector/blob/master/addon/lib/utils/make-helper.js
I am getting the deprecated version of the helper makeBoundHelper
Though I cant seem to find what version of the inflector i am running?
I am on ember 1.13.7, ember-data 1.13.8, and ember-cli 1.13.8
This repository is missing a license file. I'm assuming it should be MIT...
Originally reported at emberjs/data#1282
I have found that I need to separately declare rules for camelCase and underscore versions of phrases. For example:
inflector = new Ember.Inflector();
inflector.plural(/$/, 's');
inflector.singular(/s$/, '');
inflector.uncountable('furry_platypus');
inflector.singularize('furry_platypus'); # furry_platypus
inflector.singularize('furryPlatypus'); # furryPlatypu
Particularly given Ember usually gracefully takes care of conversion between camelCase and underscore versions of classes, it seems like it would be helpful not to need to declare both:
inflector.uncountable('furry_platypus');
inflector.uncountable('furryPlatypus');
I haven't checked what rails does, maybe this feature is absent for compatibility with rails?
The sourcemap is already been generated, so it should just be an issue of getting broccoli to import it in the right place...
We may also need to update the broccoli config to use a different filepath for sourceURL
Currently, if a user wants to add a rule to the inflector, they have no guidance about where to do so. As a result, some people put their rules in the corresponding models, others in an initializer, and only @rwjblue does it correctly.
We're adding documentation to the Guides encouraging @rwjblue's approach, but ideally there would be a generator that would set things up along these lines:
// in app/app.js
// sets up Ember.Inflector
import './models/custom-inflector-rules';
// in app/models/custom-inflector-rules.js
var inflector = Ember.Inflector.inflector;
inflector.irregular('formula', 'formulae');
inflector.uncountable('advice');
I'm not sure whether this is a bug in the logic for the inflector or within extractUpdateRecord's improper calling of singularize.
Ember.Inflector.inflector.irregular('lens', 'lenses');
Ember.String.singularize('lens'); // "len"
If it's intended for singularize to properly handle already singularized words, I believe the logic for isIrregular to be insufficient. It only checks for irregularInverse for the 'lens' key, but it contains {lenses: 'lens'} and therefore proceeds with standard singularization.
Hi!
I've been working on an Ember Project (EmberCLI 1.13.8, Ember 2.0, Ember Data 2.0), and I've created a model 'gas'.
When using ember-data to query the store. this.store.query('gas')
the url that's built is /api/gas
instead of what I expected, which would be /api/gases
. I've created a custom adapter to deal with the situation, but I think this might be a problem with the ember-inflector.
I've created an Ember Twiddle to show the issue
Any thoughts? Thanks for the project!
From my terminal:
โ lol bundle exec rails c
Running via Spring preloader in process 52353
Loading development environment (Rails 4.2.5.1)
irb(main):001:0> 'criteria'.pluralize
=> "criteria"
Current Ember Inflector pluralizes to criterium
.
Helpers registered using Ember.Handlebars.helper
receive a number of positional args instead of an array of arguments as we are now expecting. This results in pluralize helper receiving count as its params argument rather than an array of [count, word]
.
I have attempted to pass a wrapped version of helperFunction
to Ember.Handlebars.helper
but haven't been able to get this working as ember-cli seems to be pushing two lots of ember-inflector into my compiled files, one of which I can't seem to edit.
{{pluralize 1.5 "meter"}}
results in 1.5 meter
.
This morning, I attempted to upgrade my app to ember-data
v1.13.9 which, in turn, upgraded ember-inflector
to v1.9.0. This caused one of my model async relationships to fail, because price
was incorrectly pluralized to price
.
Previously, using ember-data
v1.13.8 and ember-inflector
v1.7.0, price
was correctly pluralized to prices
.
The symptom is that, when my model attempts to look up its associated prices
via the DS.ActiveModelAdapter
, it looks for GET /api/price/:id
instead of GET /api/prices/:id
.
To reproduce the bug, simply open a shell / console with Ember imported:
// ember-inflector 1.7.0
inflector.pluralize('price');
// => 'prices'
// ember-inflector 1.9.0
inflector.pluralize('price');
// => 'price'
I attempted to workaround the issue, by adding my own inflection rule to an initializer...
Ember.Inflector.inflector.irregular('price', 'prices');
...but the incorrect singular /price
URL was still being requested.
Using ember inflector within an addon, we get this cryptic error. Does it mean anything to you?
Error: Expected a provider named 'null' , did you forget to register it?
at null.close (singularize.js:20)
Of the things I expected to happen, this was not one of them. Not sure whether rails does the same thing? Does not seem very helpful
like RSVP/backburner etc.
DEPRECATION: Using `Ember.HTMLBars.makeBoundHelper` is deprecated. Please refactor to using `Ember.Helper` or `Ember.Helper.helper`. [deprecation id: ember-htmlbars.make-bound-helper]
I'm seeing this deprecation warning that looks like it's coming from https://github.com/stefanpenner/ember-inflector/blob/bdb4165206c9fea9b27b3bb961d9b4885cee1a6c/addon/lib/utils/make-helper.js .
I'm not actually using inflector directly, but it's being pulled in from ember-data.
using ember-cli (like we do in ember) corrects this problem, and also uses a faster/better watcher and exposes a lovely express server for redirects (https://github.com/emberjs/ember.js/blob/master/server/index.js)
cc @fivetanley
When upgrading to the latest version I get the following error. I think it might be to do with the loader like in #40.
import Ember from 'ember';
^^^^^^
Unexpected reserved word
/Users/jon/Documents/Devon/occam/frontend/node_modules/ember-inflector/addon/index.js:3
import Ember from 'ember';
^^^^^^
SyntaxError: Unexpected reserved word
at exports.runInThisContext (vm.js:73:16)
at Module._compile (module.js:443:25)
at Object.Module._extensions..js (module.js:478:10)
at Module.load (module.js:355:32)
at Function.Module._load (module.js:310:12)
at Module.require (module.js:365:17)
at require (module.js:384:17)
at Function.Addon.lookup (/Users/jon/Documents/Devon/occam/frontend/node_modules/ember-cli/lib/models/addon.js:671:19)
at /Users/jon/Documents/Devon/occam/frontend/node_modules/ember-cli/lib/models/addons-factory.js:43:36
at visit (/Users/jon/Documents/Devon/occam/frontend/node_modules/ember-cli/lib/utilities/DAG.js:23:3)
at DAG.topsort (/Users/jon/Documents/Devon/occam/frontend/node_modules/ember-cli/lib/utilities/DAG.js:82:7)
at AddonsFactory.initializeAddons (/Users/jon/Documents/Devon/occam/frontend/node_modules/ember-cli/lib/models/addons-factory.js:40:9)
at Project.initializeAddons (/Users/jon/Documents/Devon/occam/frontend/node_modules/ember-cli/lib/models/project.js:313:36)
at Project.eachAddonCommand (/Users/jon/Documents/Devon/occam/frontend/node_modules/ember-cli/lib/models/project.js:364:10)
at module.exports (/Users/jon/Documents/Devon/occam/frontend/node_modules/ember-cli/lib/cli/lookup-command.js:46:13)
at CLI.<anonymous> (/Users/jon/Documents/Devon/occam/frontend/node_modules/ember-cli/lib/cli/cli.js:31:26)```
I tried adding
inflector.irregular('unitOfMeasure', 'unitsOfMeasure');
To my app and it doesn't work, it hits /api/unitOfMeasure, it should now be hitting /api/unitsOfMeasure
I created a unit test in /tests/unit/inflector-test.js that fails on both asserts in latest master:
test('unit of measure', function(assert) {
inflector.irregular('unitOfMeasure', 'unitsOfMeasure');
assert.equal(inflector.singularize('unitsOfMeasure'), 'unitOfMeasure', 'irregular singularization rule was applied');
assert.equal(inflector.pluralize('unitOfMeasure'), 'unitsOfMeasure', 'irregular pluralization rule was applied');
});
I had a quick debug, it seems to find the irregular rule ok and populate substitution
in the for loop, but then I think the return in that loop of return word.replace(rule, substitution);
doesn't do the job as word is unitOfMeasure
and rule is unitofmeasure
, so there is no match due to the casing?
Because of the project folder structure, the transpiled amd output will not work with the current loader.js#master or the current ember/loader version.
The workable loader must implement:
if (nameParts.length === 1) {
parentBase = nameParts;
} else {
parentBase = nameParts.slice(0, -1);
}
But this change does not work for other ember dependencies as {backburner,rsvp,router.js,router-recognizer}.
When using ember-cli, it seems like it would be helpful to support the same inflection patterns for dasherized and undasherized names. Instead, I find myself doing the following:
Ember.Inflector.inflector.uncountable('phrase-tones')
Ember.Inflector.inflector.uncountable('phraseTones')
Of course, if I always wanted anything ending in tones
to be uncountable, then I could just register the last word, but sometimes it's only class names that I want to be uncountable (i.e., in the case where each record represents a plural set of things).
Does the inflector know about word boundaries as presented in camelCase? This is a little tricky because of all-caps acronyms. Perhaps it could work as follows. If one registers the phrase-tones
case then it also registers the phraseTones case, but not viceversa.
The latest tag (1.9.4) is not being displayed as the latest release on the releases page.
//# sourceMappingURL=ember-inflector.js.map
node_modules/ember-inflector
contains a lol
directory that mirrors the bower_ember
folder - I'm not sure if either folders are needed for the npm install, those folders are not in the github repo.could be as easy as:
Ember.Handlebars.helper('pluralize', function(count, singular) {
var word = count == 1 ? singular : Ember.String.pluralize(singular);
return count + ' ' + word;
});
Need this in the brocfile for people who use this standalone. Ember data should do it once my pull request there makes it in.
Podium is singular but singularizes to podia (because of words like bacteria -> bacterium I presume).
This is a problem when you have a model named something like "in-common-person", where in place of "person", any member of the irregularPairs list is at the end of the dasherized list.
To repro:
Ember.String.singularize('in-common-person') // 'common-person'
Ember.String.singularize('in-common-man') // 'common-man'
//etc.
Because of this, any model named in this way is improperly referenced.
After pulling the latest from master, running bundle exec rake dist
no longer creates a distribution. Haven't had time to dig any deeper.
I can use Ember.Inflector.inflector.uncountable
to add a word such as 'criteria'
so that Ember's Inflector knows 'criteria'
is both the plural and singular form. After I do so, Ember.String.singularize('criteria')
returns 'criteria'
.
However, I cannot do the same for a word that is camel-cased, such as 'myCriteria'
. When I attempt to do so, Ember.String.singularize('myCriteria')
still returns 'myCriterium'
.
index.hbs
:
app.js
:
App = Ember.Application.create();
App.IndexController = Ember.Controller.extend({
plural: 'criteria',
pluralCamel: 'myCriteria',
fixed: false,
singular: function() {
return this.get('plural').singularize();
}.property('plural', 'fixed'),
singularCamel: function() {
return this.get('pluralCamel').singularize();
}.property('plural', 'fixed'),
actions: {
fix: function() {
Ember.Inflector.inflector.uncountable('criteria');
Ember.Inflector.inflector.uncountable('myCriteria');
this.set('fixed', true);
}
}
});
Re-submitted here per request from emberjs/data#1554.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.