clojurewerkz / money

A Clojure library that deals with monetary values and currencies. Built on top of Joda Money.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Support money output formatting

glenjamin opened this issue · comments

Apologies if this already in somewhere, but I can't seem to find it in the API.

Joda Money provides http://joda-money.sourceforge.net/apidocs/org/joda/money/format/MoneyFormatter.html for outputting money nicely, but this is only available by reaching through to Joda from clojure at the moment.

Also, it would be nice to implement the hiccup HtmlRenderer protocol, but I suspect that is out of scope for this project? https://github.com/weavejester/hiccup/blob/master/src/hiccup/compiler.clj#L57

Yes, formatting is not currently supported. Hiccup formatter can be added as an optional feature, similar to how Monger and Welle have core.cache implementations and cheshire integration.

For reference, here's what I threw into my project for now:

(extend-protocol HtmlRenderer
  Money
  (render-html [money]
    (-> (MoneyFormatterBuilder.)
        (.appendCurrencySymbolLocalized)
        (.appendAmountLocalized)
        (.toFormatter (Locale/UK))
        (.print money))))

@glenjamin please try clojurewerkz.money.format/format (which will use the same formatter as you provided, and optionally takes locale as the 2nd argument) in 1.3.0-beta2. Hiccup integration is available in clojurewerkz.money.hiccup. I need to update the docs but there are tests and a couple of examples in the change log. Hiccup integration only requires compiling the namespace.

Cheers, that works nicely.

I had a bit of trouble sorting out the java default locale via system properties but I've got it sorted now, not sure if its worth trying to make that easier via this api though.

1.3.0 is out