> {.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.

At the moment I'm using this:

{.section node-a} -- predicate function named 'true' applied to node-a
{.section node-a predicate?} -- predicate applied to node-a
{.section node-a node-b?}  -- predicate is assumed as 'true' applied
on node-b (since node-b is not found as a predicate)
{.section node-a node-b|predicate?}
{.section node-a|formatter node-b|predicate?}

Also:

{.section node-a ?predicate?} -- predicate applied to node-a
{.section node-a ?node-b?}  -- predicate is assumed as 'true' applied
on node-b (since node-b is not found as a predicate)
{.section node-a ?node-b|predicate?}
{.section node-a|formatter ?node-b|predicate?}

I have the exta ? in the beginning as optional, and make the predicate
part more greedy for the regular expression than the node-a|formatter
part. The more I work with it, the more I'll know how well that works.
So far, it works in all the simple and complex cases I've created. I
wish ¿ was easier to type. Then I'd use:

{.section node-a ¿predicate?} -- predicate applied to node-a
{.section node-a ¿node-b?}  -- predicate is assumed as 'true' applied
on node-b (since node-b is not found as a predicate)
{.section node-a ¿node-b|predicate?}
{.section node-a|formatter ¿node-b|predicate?}

That looks cooler, but only Spanish language keyboard users would find
it helpful.

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

Personally, I'd use 'if:', as it makes base-url look like the json
node (that it is). Although at this point, why not:

{.if base-url} -- same as section, but scope is @ and predicate is
'true' function applied on base-url (the predicate scope)

{.end}


Speaking of parameters:

{.section post ¿role|isValue("moderator")?}

is something I have working at the moment, though I changed 'isValue'
to just 'is', and since I have the ( and ) as optional, I have this
working too

{.section post ¿role|is "moderator"?}


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


I'll ponder that overnight.
--~--~---------~--~----~------------~-------~--~----~
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