emberjs/ember-inflector

Pluralize no longer works with the new register-helper method for Handlebars

jrhe opened this issue · 13 comments

jrhe commented

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].

https://github.com/stefanpenner/ember-inflector/blob/5e80bac26f6bc7ff7fc50386f3bee08468c601e8/addon/lib/helpers.js#L43

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.

screenshot 2015-03-26 18 44 59

which version of ember are you using?

jrhe commented

1.9.1

I'm not including ember-inflector directly, but from what I can tell in the source code, it is being included by something else (I think?).

I'm getting the following deprecation warning:

DEPRECATION: Using Ember.HTMLBars._registerHelper is deprecated. Helpers (even dashless ones) are automatically resolved. [deprecation id: ember-htmlbars.register-helper]

And I believe it is pointing to this line.

Am I looking in the right place? Looking at that code it looks like your makeHelper function shouldn't cause any issues.

I'm trying to figure out where this deprecation warning is coming from. Thanks!

Lib Version
Ember Inspector 1.8.3
Ember 1.13.6
Ember Data 1.13.7
jQuery 1.11.3

screen_shot_2015-08-07_at_5_53_22_am

@ryanjm update ember data to 1.13.8, that is the problem, it needed a inflector dependency bump as it uses inflector

Thanks @jcope2013. I just updated to 1.13.8 and still have the same issue. I'll dig into it more this weekend, but thanks for the direction.

Just to document my progress incase anyone else runs into this. I've not been able to fix it yet. I've cleared cache / made sure everything is up to date. But it looks like EmberTwiddle is having the same issue, even after updating it to 1.13.8 also. I think something else is missing.

@stefanpenner I think maybe this should be re-opened (or a new issue made) - if I goto EmberTwiddle like @ryanjm and edit twiddle.json from 1.13.7 to be 1.13.8 for Ember data I see the exact same deprecation warnings on _registerHelper and makeBoundHelper as I get in my Ember CLI 1.13.7 with Ember 1.13.6 and Data 1.13.8

I'm currently upgrading my app and trying to remove deprecations and I'm stuck at this too.

I'm also at Ember 1.13.6 and Ember data 1.13.8 like @adam-knights

changing the twiddle to http://builds.emberjs.com/tags/v1.13.8/ember-data.js makes it go away, can you try that?

@jcope2013 Agreed - that url in twiddle makes the deprecations go away. So I downloaded both that file and the cdnjs one and compared to the one I've got locally from bower - my local file is an exact match of the cdnjs one, ie the one that causes the warnings on twiddle.

So I guess the question is why is 1.13.8 of ember-data.js from either bower or cdnjs giving these warnings while the build tag file from emberjs.com file isn't?

The difference is at line 2322 onward, the file from bower and cdnjs both have the section below that builds.emberjs.com does not:

var ember$inflector$lib$lib$utils$register$helper$$default = ember$inflector$lib$lib$utils$register$helper$$registerHelper;

function ember$inflector$lib$lib$utils$register$helper$$registerHelperIteration1(name, helperFunction) {
  //earlier versions of ember with htmlbars used this
  ember$lib$main$$default.HTMLBars.helpers[name] = helperFunction;
}

function ember$inflector$lib$lib$utils$register$helper$$registerHelperIteration2(name, helperFunction) {
  //registerHelper has been made private as _registerHelper
  //this is kept here if anyone is using it
  ember$lib$main$$default.HTMLBars.registerHelper(name, helperFunction);
}

function ember$inflector$lib$lib$utils$register$helper$$registerHelperIteration3(name, helperFunction) {
  //latest versin of ember uses this
  ember$lib$main$$default.HTMLBars._registerHelper(name, helperFunction);
}
function ember$inflector$lib$lib$utils$register$helper$$registerHelper(name, helperFunction) {
  if (ember$lib$main$$default.HTMLBars) {
    var fn = ember$lib$main$$default.HTMLBars.makeBoundHelper(helperFunction);

    if (ember$lib$main$$default.HTMLBars._registerHelper) {
      if (ember$lib$main$$default.HTMLBars.helpers) {
        ember$inflector$lib$lib$utils$register$helper$$registerHelperIteration1(name, fn);
      } else {
        ember$inflector$lib$lib$utils$register$helper$$registerHelperIteration3(name, fn);
      }
    } else if (ember$lib$main$$default.HTMLBars.registerHelper) {
      ember$inflector$lib$lib$utils$register$helper$$registerHelperIteration2(name, fn);
    }
  } else if (ember$lib$main$$default.Handlebars) {
    ember$lib$main$$default.Handlebars.helper(name, helperFunction);
  }
}

/**
 *
 * If you have Ember Inflector (such as if Ember Data is present),
 * singularize a word. For example, turn "oxen" into "ox".
 *
 * Example:
 *
 * {{singularize myProperty}}
 * {{singularize "oxen"}}
 *
 * @for Ember.HTMLBars.helpers
 * @method singularize
 * @param {String|Property} word word to singularize
*/
ember$inflector$lib$lib$utils$register$helper$$default('singularize', function (params) {
  return ember$inflector$lib$lib$system$string$$singularize(params[0]);
});

/**
 *
 * If you have Ember Inflector (such as if Ember Data is present),
 * pluralize a word. For example, turn "ox" into "oxen".
 *
 * Example:
 *
 * {{pluralize count myProperty}}
 * {{pluralize 1 "oxen"}}
 * {{pluralize myProperty}}
 * {{pluralize "ox"}}
 *
 * @for Ember.HTMLBars.helpers
 * @method pluralize
 * @param {Number|Property} [count] count of objects
 * @param {String|Property} word word to pluralize
*/
ember$inflector$lib$lib$utils$register$helper$$default('pluralize', function (params) {
  var count, word;

  if (params.length === 1) {
    word = params[0];
    return ember$inflector$lib$lib$system$string$$pluralize(word);
  } else {
    count = params[0];
    word = params[1];

    if (count !== 1) {
      word = ember$inflector$lib$lib$system$string$$pluralize(word);
    }
    return count + ' ' + word;
  }
});

@adam-knights can you file an issue on ember data? i have a feeling they published 1.13.7 as 1.13.8 or the wrong 1.13.8 on bower

Submited issue as requested emberjs/data#3635