jeremyruppel / walrus

A bolder kind of mustache
http://documentup.com/jeremyruppel/walrus/
MIT License
215 stars 10 forks source link

Currencies extension to filter a number to US dollar #24

Closed hershmire closed 12 years ago

hershmire commented 12 years ago

Not sure if this is something you're interested in adding but I have a basic filter for making a number format to a US dollar. Tests are passing and I'm definitely open to further conversation on additions to this if you already had thoughts of your own creation.

Use example:

JSON data:

{
  "car" : 36000,
  "sandwich" : 9.25,
  "icecream" : 5.99
}

Walrus template:

<p>Car price (as is): {{car | :dollar}}</p>
<p>Car price (forced cents shown): {{car | :dollar( 0 )}}</p>
<p>Sandwich price (as is): {{sandwich | :dollar}}</p>
<p>Sandwich price (forced no cents shown): {{sandwich | :dollar( 0 )}}</p>
<p>Sandwich price (forced cents shown): {{sandwich | :dollar( 2 )}}</p>
<p>Icecream price (as is): {{icecream | :dollar}}</p>
<p>Icecream price (forced no cents shown): {{icecream | :dollar( 0 )}}</p>
<p>Icecream price (forced cents shown): {{icecream | :dollar( 2 )}}</p>

HTML output:

<p>Car price (as is): $36,000</p>
<p>Car price (forced cents shown): $36,000</p>
<p>Sandwich price (as is): $9.25</p>
<p>Sandwich price (forced no cents shown): $9</p>
<p>Sandwich price (forced cents shown): $9.25</p>
<p>Icecream price (as is): $5.99</p>
<p>Icecream price (forced no cents shown): $6</p>
<p>Icecream price (forced cents shown): $5.99</p>
jeremyruppel commented 12 years ago

Looks great man, thanks!