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

When supplying arguments to a variadic filter, the argument must be declared on the object. #88

Closed rankers closed 9 years ago

rankers commented 9 years ago

When rendering dates I implemented a variadic filter as it states in the documentation. I find having to declare the format of the date as a property on my object or as a key in my dictionary a bit cumbersome. I would like to be able to pass a string format as the second argument to my date formatter filter. Is there any way I can force the argument to come through in the arguments list? At the moment I have to have a predefined set of date formats described as short, medium, long etc. that I then add to the safe mustache keys set along with all the objects properties.

groue commented 9 years ago

Hello @rankers.

Your solution of a set of date formats described as short, medium, long etc. works, and it is correct. You could also replace your variadic filter {{ format(date, long) }} by {{longFormat(date)}}, and provide a configured NSDateFormatter for the key longFormat (see the NSFormatter Guide).

I agree it can be a bit cumbersome when you have many different formats. Yet this is the only available solution at this time.

It's not the first time that support for literals is requested (see #37, #54, #81, #62). I'm reluctant to implement it since I'd like GRMustache to remain compatible with other Mustache implementations, and Mustache has no support for literals. Adding support for them introduces some difficult compatibility issues.

I may still consider a pull request that updates GRMustacheExpressionParser with literal support. If it is of good quality, the compatibility issues with other Mustache implementations could be alleviated.

rankers commented 9 years ago

Ahh yes - I see the closed issues - reading through #54 I can see the complexity around literals. I think I'll stick with the current solution then. Thank you for the suggestions.

groue commented 9 years ago

You're welcome. Happy Mustache, @rankers!