On Thu, Oct 1, 2009 at 9:10 AM, Steven Roussey <[email protected]> wrote:
>
> On Oct 1, 1:36 am, Andy Chu <[email protected]> wrote:
>> OK, I like that, with one refinement. ".if" is just a syntactic
>> shortcut for for ".section @". So these are the same:
>
> Yes, in fact, that is the way I started.
>
> But after I started looking at adding formatters to that section, and
> then I added parameters to both formatters and the predicate, the
> template started getting way too confusing.
>
> I ended up with:
>
> {.section data|convert smilies ?other|is "night"?}
OK, but the way I'm thinking about it now there is no target for
predicates. So it goes like this
{.section <name> [<predicate?>] [ | <formatter> ]}
e.g.
{.section data is "night"? | convert smilies}
That's an extreme case where both the predicate and formatter have
arguments, and I don't think that is too bad. And note that you can
also nest them if you want:
{.section data is "night"?}
{.section|convert smilies}
stuff
{.end}
{.end}
or
{.section data|convert smilies}
{.section @ is "night"?}
stuff
{.end}
{.end}
If you don't have a subdictionary: then it will look like this:
{.section|convert smilies}
{.if is "night"?}
stuff
{.end}
{.end}
which is totally managable.
> I had to put the extra ? in there so I could figure out where the
> formatter ended and the predicate began. In fact, the first question
> mark seemed more important than the second. I converted a big real
> life template to json-template and looked at it and didn't like all
> the confusing syntax. Actually, I understood it fine, but the thought
> of selling that off to others is what got me. If I had formatters on
> the section, then what was the target for the predicate? So I had to
> add that in, in case it was different. (PS: no, I didn't get section
> formatters all working correctly in the first place).
>
> At any rate, this syntax seemed better with a complex template (even
> if internally redundant):
>
> {.if other is "night"}
> {.section data|convert smilies}
>
> Internally, I have them both as sections. Every section has a section
> name, predicate section name (predicate target), and a predicate. So
> the above is:
>
> {.if other is "night"}
> {.section data|convert smilies}
>
> is this:
>
> {.section @ ?other is "night"?}
> {.section data|convert smilies ?data|convert smilies|true?}
I don't quite see this, but without the concept of "target", I think
it becomes a lot simpler.
> If it weren't for the idea of formatters (and their arguments) coming
> to sections someday, it would be a bit easier. Putting the predicate
> in the same line takes that option off the table.
But as mentioned above, people can always split them.
> Also, it can be nice to have a way to test a condition without pushing
> on the context stack. Ideally, at least.
In my proposal ".if" never pushes anything. ".if" is a synonym for
".section @", which doesn't move the stack. We can also use the idea
of testing attributes without pushing:
{data: 1}
{.if attr data} # attr is a predicate that tests for bool(argument)
{.end}
I can even abbreviate attr as some punctuation:
{.if data?} # ? is a predicate that tests for bool(argument)
{.end}
The predicate is an uninterpreted string so this is valid. There is
no built-in name/argument parsing.
> Later today, I'll backport a cut of the above and put it on the code
> review site....
OK cool. I don't think it is too far from what I'm suggesting. BTW
the easiest way I see to implement formatters on sections is to change
'callback' temporarily. If a section has a formatter, create a
callback that collects things in an array and pass it to _Execute.
Then join the fragments into a string, format them, and call
callback(formatted_str). The recursion will restore 'callback' to the
user-defined value.
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
-~----------~----~----~----~------~----~------~--~---