Ember Cli Inflector adjustments

泪湿孤枕 提交于 2019-12-10 14:32:57

问题


Where/how can i adjust the Ember.Inflector Class / create an instance of it that ember-cli picks up?

Thanks!


回答1:


I placed it in the model file and it worked fine:

import DS from 'ember-data';
import Ember from 'ember';

var inflector = Ember.Inflector.inflector;
inflector.irregular('nota', 'notas');
inflector.singular(/nota/, 'nota');

export default DS.Model.extend({
  title: DS.attr('string'),
  description: DS.attr('string'),
  language: DS.attr('string'),
  body: DS.attr('string')
});



回答2:


I generated an initializer and put this data there. This ensures it loads before anything that might need it. Like the model, adapter, or serializer.

initializers/inflector.js

import Ember from 'ember';
export function initialize(/* container, application */) {
  var inflector = Ember.Inflector.inflector;
  inflector.uncountable('aamc-pcrs');
}

export default {
  name: 'inflector',
  initialize: initialize
};



回答3:


The Ember Guides covers this in Models - Customizing Adapters:

Create the file app/models/custom-inflector-rules.js:

import Inflector from 'ember-inflector';

const inflector = Inflector.inflector;

inflector.irregular('formula', 'formulae');
inflector.uncountable('advice');

// Meet Ember Inspector's expectation of an export
export default {};

Then in app/app.js add the line:

import './models/custom-inflector-rules';

And if you want to use this in a unit test for a serializer/adapter then you can just import the custom-inflector-rules file into the test.



来源:https://stackoverflow.com/questions/24593483/ember-cli-inflector-adjustments

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!