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

Single word handlebars helpers do not resolve #40

Closed
JohnColvin opened this issue Apr 16, 2014 · 3 comments
Closed

Single word handlebars helpers do not resolve #40

JohnColvin opened this issue Apr 16, 2014 · 3 comments

Comments

@JohnColvin
Copy link

We're in the process of converting an app from lineman to ember-cli. We have a percent handlebars helper which works fine in lineman, but doesn't resolve in cli.

We define percent handlebars helper in app/helpers:

Percent = ->
  Ember.Handlebars.helper "percent", (whole_number) ->
    whole_number.toFixed(0) + "%"
`export default Percent`

Attempting to use that helper results in this error:

Uncaught Error: <(subclass of Ember._MetamorphView):ember852> Handlebars error: Could not find property 'percent' on object {name: Cincinnati, utilization: 61.1}.

Changing the helper to per-cent fixes this issue. I think I've traced the cause of this issue, but I'm not sure how to fix it.

In ember-resolver/lib/core.js the extended Resolver's resolve method will call Ember's resolveHelper method.

Ember's resolveHelper method checks for the presence of a hyphen.

if (!container || name.indexOf('-') === -1) {
  return;
}

As far as I can tell, due to this it's not possible to have ember-cli resolve a single word handlebars helper. Am I missing something? Thanks for the help!

@stefanpenner
Copy link
Contributor

you are not missing anything, due to the ambiguity between bindable properties and helper names without a dash, we do not encourage the usage.

In addition, if we tried to resolve each potential property name we would slow ever ember app down to crawl, and it is likely impossible to introduce such a feature without massive caveats.

The way around this, if you really want a dashless helper, is it register the helper manually

@rwjblue
Copy link
Member

rwjblue commented Apr 16, 2014

This is intentional (the dash requirement) as doing a helper lookup for every property is extremely costly.

Swap your helper to something like:

Ember.Handlebars.helper "percent", (whole_number) ->
    whole_number.toFixed(0) + "%"

And include the following in your app.js:

import "app/helpers/percent";

@JohnColvin
Copy link
Author

Gotcha. Thanks for the quick help!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants