Handlebars Text Helpers

Hey all-

I’ve extracted a bunch of code from our application that adds a new helper for Ember.Handlebars called registerTextHelper. This helper eases development of textual transforms. Currently, I’m using it for our {{t}}, {{l}}, and {{simpleFormat}} helpers. I think the current implementation of {{loc}} lacks the ability to dynamically inject strings, and this would satisfy that use case with out of the box with a single line of code:

Ember.Handlebars.registerTextHelper('loc', Ember.String.loc, /`(.*?)`/g);

The {{loc}} helper could now have dynamically interpolated strings on the view. I think this can be abused, but in this context, I believe it is within scope and the use case of:

{{#each App.currencies}}
  {{loc "currency.`this`"}}
{{/each}}

Is hard not to see like a “win” in my mind.

In addition to {{loc}}, I’ve posted gists for integration with I18n-js via the {{t}} and {{l}} helpers. In the near future, I’ll add our Rails-y {{simpleFormat}} helper, which globs together Rails’ simple_format and auto_link helpers.

For the code, visit https://github.com/paddle8/ember-text-helper

Registering a handlebars helper inside another helper, very meta. :slight_smile: This is very nifty, Thanks.

1 Like

This seems pretty interesting. It’s fun to see people doing creative new things, though in this case I definitely do worry about the potential for abuse.

I agree with your statement, @pwagenet- this helper has a bit too much power that’s very easily used / abused. I think the benefits for simplifying text helpers outweighs its cons for me, at least.