Skip to content

Commit

Permalink
feat(): allow _number to take an optional precision parameter
Browse files Browse the repository at this point in the history
Also include an `N` alias for `_number`;
  • Loading branch information
cueedee committed Feb 20, 2017
1 parent 4eef1bc commit 0d2059d
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 13 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,12 @@ See the [examples](https://github.com/marviq/madlib-locale/blob/develop/examples
{{_number number }}
```
Pass the number to format with alternative precision:
```hbs
{{_number number 2 }}
```
* Money
Pass the type as defined in localeFile and the money/amount value:
Expand Down
21 changes: 8 additions & 13 deletions src/madlib-locale.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -70,21 +70,16 @@
@translate( key, interpolation )

Handlebars.registerHelper( 't', translate )
Handlebars.registerHelper( 'T', _.compose( capitalize, translate ))

Handlebars.registerHelper( 'T', _.compose( capitalize, translate ) )
Handlebars.registerHelper( '_translate', translate )

Handlebars.registerHelper( '_date', ( type, date ) =>
@date( type, date )
)
Handlebars.registerHelper( '_date', _.bind( @date, @ ) )
Handlebars.registerHelper( '_money', _.bind( @money, @ ) )

Handlebars.registerHelper( '_money', ( currency, amount ) =>
@money( currency, amount )
)
number = _.bind( @number, @ )

Handlebars.registerHelper( '_number', ( number ) =>
@number( number )
)
Handlebars.registerHelper( 'N', number )
Handlebars.registerHelper( '_number', number )

# Set the default locale and return promise
#
Expand Down Expand Up @@ -167,8 +162,8 @@

return accounting.formatMoney( amount, sign, precision, thousand, decimal )

number: ( number ) ->
precision = objectUtils.getValue( 'formatting.number.precision', @locale, 3 )
number: ( number, precision ) ->
precision ?= objectUtils.getValue( 'formatting.number.precision', @locale, 3 )
decimal = objectUtils.getValue( 'formatting.number.decimalMarker', @locale, '.' )
thousand = objectUtils.getValue( 'formatting.number.thousandMarker', @locale, ',' )

Expand Down

0 comments on commit 0d2059d

Please sign in to comment.