I checked in a formatter that may help:

http://code.google.com/p/json-template/source/detail?r=274

See the unit test for how to use it.  Hopefully it isn't too obscure.
If people understand the formatter concept, then the syntax should be
clear -- otherwise it may look a bit funny.

Andy



On Wed, Jun 3, 2009 at 5:58 PM, Andy Chu<[email protected]> wrote:
> Yeah, that is a hole:
>
> http://groups.google.com/group/json-template/browse_thread/thread/1b3016093d7291d7/0471532731b74a7a?lnk=gst&q=predicates#0471532731b74a7a
>
> No one gave any feedback, but I knew that someone would run into this, as I 
> did.
>
> Generally, JSON Template avoids putting logic in templates.  But
> actually this distinction is too coarse -- we should avoid putting
> *application* logic in templates, but whether to display "people" or
> "person" is *not* application logic.  It's logic caused by English
> grammar basically. :)
>
> So that does belong in the template.  You shouldn't have strings like
> "people/person" in your native Python/whatever code.
>
> I think you could write a wrapper for your dictionary to include a
> boolean for pluralness.  That is, you would pass in a field name where
> you care about its plurality, and then it could decorate the data
> dictionary with a boolean too.  Then use that boolean in your template
> as a section.  I think this will work, although I haven't tried it
> yet.
>
> python/jsontemplate/datadict.py does something like this.
>
> If that works for you let me know.  I would consider adding the
> predicates, or maybe there is an even better solution.  The predicate
> scheme is nice though because it avoids adding any expressions to the
> language (no hacky ifequal, ifnotequal, iflessthan stuff).  There will
> just be a library of canned predicates, which are user-customizable,
> like there's a library of formatters.
>
> Andy
>
>
>
>
> On Wed, Jun 3, 2009 at 2:10 PM, Sasha <[email protected]> wrote:
>>
>> I started playing around with json-template and am generally impressed
>> by how simple it is. The one thing I'm stuck on is how/whether to add
>> new language constructs or formatters. I'd like to write as little non-
>> template code as possibly, but when porting over some old code there
>> is a bunch of things I need to do that aren't natively supported.
>>
>> As an example, I'd like to have branching sections based on whether a
>> list contains one element or several. I guess I could write this as a
>> formatter, but falling back to native code seems a bit hacky. Or maybe
>> I'm should try to change up the underlying code. What's the
>> recommended approach?
>>
>> (basic idea)
>> {.repeated section pictures one}
>>  (some stuff for single case)
>> {.or repeated section pictures}
>>  (some stuff for plural case)
>> {.end}
>> >>
>>
>

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "JSON 
Template" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/json-template?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to