On Thu, Sep 24, 2009 at 10:41 PM, Steven Roussey <[email protected]> wrote:
>
>
>> For the parameter handling, see my mail about the template-file
>> formatter. I have had this conversation unsuccessfully before -- I
>> guess the higher order programming is unconventional to some, but if
>> you look at the Java version, you'll see what it looks like just using
>> plain classes.
>>
>> Basically JSON Template supports arguments, but it does not
>> *implement* them. It's done by user code via
>> more_formatters/more_predicates, so that people can choose their own
>> argument style. This is important to understand about the design.
>
> I'm confused. The only difference is that I don't use more_formatters
> (leaving it for *really* special occasions). In the version I posted,
> it doesn't interpret the parameters at all, it simply gives the text
> to the function for it to interpret. I was listening to your argument
> and agreed (and was able to create stuff that looked much better than
> I had before to boot). I simply moved the code around a bit to make
> using that functionality easier. Note this is the reverse of what I
> had said/done earlier in the week (or last week) when I had put
> operators and the like in there.
OK, I see. So I think you went partway, but not as "extreme" as I'm
advocating : )
if (formatter === undefined) {
var matches = format_str.match(_CALL_RE);
if (matches && (formatter =
DEFAULT_FORMATTERS[matches[1].trim()]))
{
var args = matches[2].trim();
formatter = [formatter,args];
}
};
So here you're separating the name and the arguments. This will work
in most cases, but I allow even more flexibility, and there is an
example in formatters.py:
http://code.google.com/p/json-template/source/browse/trunk/python/jsontemplate/formatters.py
If you look at Plural, it will do this:
{num|plural? data datum}
--> "datum" if num = 1
--> "data" if num > 1
But what if you want spaces in your arguments? It lets you do this:
{num|plural?.there are many.there is one}
The first character after "plural?" is the argument separator now.
This is like sed/perl: you can do s/foo/bar, or you can do
s.this/has/slashes/.replacement.string.too.
This isn't a huge deal, but I would want to have this flexibility,
especially since it doesn't cost anything.
> As for the code, it wouldn't work out of the box, I should have
> mentioned that. It wasn't meant to. I use some utility functions that
OK yeah I was a little confused about that, with .trim() and Ext.
I'll have to look at it in more detail, but in general it looks like
the right idea. It's a little hard to consume outside of a patch
though. Generally I try to look at the examples of templates when
looking at code -- it's a little hard to try to extract what the final
syntax is from the code.
How about I generate some cross-language tests and do it in Python,
and do you want to follow up with JavaScript and/or PHP?
And what do you think about {.moderator?} vs {.if moderator} ?
The chaining is important. Either of these looks wrong:
{.if singular}
there is one
{.else}
{.if plural}
there are many
{.else}
there are None
{.end}
{.end}
(Too ugly, bad indentation)
{.if singular}
there is one
{.if plural} <-- this would be normally be elif
there is one
{.else}
there are none
{.end}
(Not what you expect of if/else/end)
Instead this looks cleanest to me:
{.singular?}
there is one
{.plural?}
there are many
{.or}
there are None
{.end}
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
-~----------~----~----~----~------~----~------~--~---