Last active
December 18, 2015 16:39
-
-
Save amsul/5812749 to your computer and use it in GitHub Desktop.
Add the {{pluralize}} helper in Ember Handlebars templates.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Register the pluralize helper. | |
Ember.Handlebars.registerBoundHelper( 'pluralize', function( number, options ) { | |
var phraseMatch = ( options.hash.phrase || '{|s}' ).match( /(.*?)\{(.*?)\|(.*?)\}/ ) | |
Ember.assert( 'The optional "phrase" hash for {{pluralize}} should be formatted as <phrase to pluralize>{<singular ending>|<plural ending>}', phraseMatch ) | |
var word = phraseMatch[ 1 ], | |
singular = word + phraseMatch[ 2 ], | |
plural = word + phraseMatch[ 3 ] | |
return number == 1 ? singular : plural | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment