Andy Chu wrote:
> Hey, thanks for the suggestion.  This has crossed my mind, but so far
> no one else has brought it up.  How about giving the keys and values
> special names, e.g. treat it as a 2 element object with "name" and
> "value" fields, like:
> 

It seems like this could be done without adding more reserved words to 
the language.

.repeated user_chosen_1 user_chosen_2

Then user_chosen_1 becomes the name of each member (in user_chosen_2) 
and the cursor (@) assumes the value for each member.

As suggested in ticket 13 [1], one of 'repeated' or 'section' could go 
in '.repeated section'.  My suggestion would be to give some meaning to 
'section' and to keep 'repeated'.

Data dictionaries already can't use members named 'length' with a value 
of 0 (in the js implementation [2]).  I think it would be unfortunate to 
take the names 'name' and 'value' as well.

Tim

[1] http://code.google.com/p/json-template/issues/detail?id=13
[2] I'll create a ticket for this.


> List:
> {.repeated section pages}
>   {name} {value.url}
> {.end}
> 
> Page 0 URL: {page0.url}
> 
> -->
> 
> List:
> zero foo
> one bar
> 
> Page 0 Url: bar
> 
> It would have to work with nested dictionaries too.
> 
>> If this is something that is not already handled in a different way, I
>> think it could be implemented in a mostly backwards compatible way
>> (breaking where templates use substitution for a variable named "section").
>>
>> If this email doesn't make any sense, I could rephrase it by starting
>> with the collapsed data dictionary and asking "how can I create a list
>> of links from this (and allow for deep linking without data duplication)?"
> 
> It make sense, and can be done without breaking compatibility, since
> repeated sections only take lists now.
> 
> But in general, JSON Template can't handle arbitrary JSON.  It's
> supposed to be JSON you craft for the template specifically.
> 
> For example, it doesn't handle JSON where a: 1 or a: [1, 2] -- the
> JSON has to be transformed so the value is always a list.
> 
> To do this within the existing system, I would write a function that
> annotates the data dictionary.  Say you get a bunch of rows of URLs
> from a database.
> 
> rows:
> 
> (zero, foo)
> (one, bar)
> 
> Now I would write a function to turn that into JSON:
> 
> {
>   pages-list: [{
>             "title": "zero",
>             "url": "foo"
>         }, {
>             "title": "one",
>             "url": "bar"
>         }],
>   "zero": "foo",
>   "one": "bar"
> }
> 
> So to play devil's advocate, there's no real duplication there.  It's
> just some transformations in the code, which you always need anyway.
> I think I would have to see an actual example of this.  Is it
> something you really ran into?
> 
> Andy
> 
> > 


-- 
Tim Schaub
OpenGeo - http://opengeo.org
Expert service straight from the developers.

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