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"?}
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?}
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.
Also, it can be nice to have a way to test a condition without pushing
on the context stack. Ideally, at least.
Later today, I'll backport a cut of the above and put it on the code
review site....
-steve--
>
> {.section @ singular?} # Optional second argument is a predicate
> one
> {.or plural?}
> many
> {.or}
> none
> {.end}
>
> {.if singular?}
> one
> {.or plural?}
> many
> {.or}
> none
> {.end}
>
> This will make the implemention simpler than what I put there for
> Python. It will extend well to formatters on sections too.
>
> Repeated sections don't get predicates. Sections and repeated
> sections will diverge a bit, which I think is good.
>
> 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
-~----------~----~----~----~------~----~------~--~---