On Tue, Sep 22, 2009 at 3:29 PM, Steven Roussey <[email protected]> wrote:
>
>> >  {.section post}
>> >   Title: {title}
>> >   Body: {body}
>> >   {section @ @.parent.is-moderator?}
>>
>> Why do you need that?  I think it's a lot simpler if you if you leave
>> out the "predicate_scope" and just have the predicate have access to
>> the whole stack of namespaces, as I described in the bug.
>
> But then everything has to be a predicate function. Which has to be
> implemented in both JS and the server side language. If you have
> someone (like a designer) working on templates, they are not the same
> person writing the JS/PHP/etc. And it's easier to have someone add an
> extra node to JSON than to write extra functions to check on that
> extra node in the json.

Right.  So I think the answer is that predicates need to be able to
take arguments, just like formatters can.  So the original syntax

{.section node predicate?}

isn't sufficient.  As I mentioned formatters don't really take
arguments -- the thing after | in {foo|...} is an uninterpreted string
to JSON template, and the app code can interpret things as arugments.

So then everything after the node name and before | can also be an
uninterpreted string (althoug this conflicts a bit with
http://code.google.com/p/json-template/issues/detail?id=26)

The syntax I think is fairly similar to what you propose, but it's an
important difference.

{.section <node> <predicate>}

So you can spell it like:

{.section @ true? moderator}
  <button {id}>
{.end}

IMO that is a little ugly, so I would prefer to come up with a convention like:

{.section @ if-moderator}
{.section @ if-base-url}

"if-" is a prefix, and then the thing after the - is a string which
you can test for.  This is the most flexible thing, and adds less
complexity than argument parsing in the template language itself.

def Predicates(p):
  if p.startswith("if-"):
    return lambda context: bool(context.Lookup(p[len("if-") : ])  #
look up "moderator" in the context, and return its truth value
  else:
    return None

t = Template(predicates=Predicates)

Does that make sense?  It's higher order functional programming again.

Andy

--~--~---------~--~----~------------~-------~--~----~
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