On Mon, Sep 21, 2009 at 11:58 AM, Steven Roussey <[email protected]> wrote:
>
>
>> I'm not sure what you're getting at here.  Can you post a real
>> example?  "foo" and "advancedSetting" are BOTH keys in your JSON
>> dictionary.
>
> Yes, exactly.
>
>> The predicate is a function which receives a JSON node.  The JSON node
>> is named in the section.
>
> Yes, but...
>
> data={ moderator:true, post: {id:52, title:"Hi",
> message:"there"},... }
>
> {.section post moderator|true?}
>  <button id="{id}">Delete</button>
> {.end}
>
> The way I implemented it, if the text "moderator|" was omitted, the
> meaning would simply be a test on post|true? Having both json nodes
> means that I can step into the post node while testing on the
> moderator node.

OK, so you want to only display a delete button if the current user is
a moderator.  That's an interesting case because the moderator is
global and not part of the post.

I guess the short answer now is that you have to craft your JSON for
the template, and you would to put {"show-delete-button": true,
"title": ...} inside every post.

So the logic goes in the app instead of the template.  The philosophy
is to put "business logic" in the app and the template only deals with
display.  I would be interested to see how you would do this in other
template languages.

But I think there are too many degrees of freedom in what you propose.
 You aren't using the predicate part in your example.  Another option
is to have the predicate have access to the entire dictionary, rather
than just the current node.  Then the predicate could see "moderator".
 It is sort of a waste of space to put the same truth value in every
node.  I'll have to think about it.


> Also, I implemented parameters (to formatters and predicates).
>
> {.section post role|isValue("moderator")?}
>  <button id="{id}">Delete</button>
> {.or post role|isValue("writer")?}
>  <button id="{id}">Reply</button>
> {.end}
>
> {.section post|cleanlanguage("G") }
>  {.message}
> {.end}
>
> or
>
> {.section post }
>  {.message|cleanlanguage("G")}
> {.end}
>
> The parameters are appended. I'm not sure why you omitted parameters.
> (I only allow parameters that can be encoded as json). I can see now
> why you omitted expressions, and changed my version to strip that out
> and use predicate functions. But I don't see why there are no
> parameters. Yet.

So this is already possible.  See formatters.py for a Python example.
It will be possible in JS too, because the more_formatters arg is a
function *which returns functions*.  So you need to use closures in
JS.  This is the most flexible scheme, and doesn't confine users to
one kind of parameter passing syntax.  You can do what you did solely
with more_formatters and without touching the source.

The most prominent example is the 'template-file' formatter:
{node|template-file another_file.jsont}

TemplateFileInclude in formatters.py is a callable that returns
another function (a bound method)

thanks,
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