groue / GRMustache

Flexible and production-ready Mustache templates for MacOS Cocoa and iOS
http://mustache.github.com/
MIT License
1.44k stars 190 forks source link

Helpers as data formatters #20

Closed amarcadet closed 12 years ago

amarcadet commented 12 years ago

Hi,

I'm looking for a way to use helpers as data formatters.

In your sample code you show a way to call NSLocalizedString for each value inside a {{localize}} tag. What I want to do is to create a helper called "date" that, through a NSDateFormatter, will always format a date to specific format, "yyyy-MM-dd" for example.

Problem is, the GRMustacheSection doesn't offer the data itself but the string representation of the data.

I've looked around the GRMustacheTemplateDelegate and it seems that GRMustacheInvocation offers closer information from what I want but using this delegate force me to reimplement always the same code to format my date object.

Is it possible to expose a property on GRMustacheSection to grant access to the data and not to the "rendered" value ?

I know this change the meaning of helpers but I hope you find this idea quite interesting.

Maybe your library does offer what I'm looking for and I miss it, if so, sorry for the inconvenience.

Thanks

groue commented 12 years ago

Sections have no direct access to the data. That's a constraint in the Mustache language itself.

There is a GRMustache guide about number formatting. It may well be relevant about date formatting as well: https://github.com/groue/GRMustache/blob/master/Guides/sample_code/number_formatting.md

amarcadet commented 12 years ago

Works like a charm!

Thanks!