Discussion:
Nested arrays with {.repeated section}
Andrey Fedorov
2009-11-18 18:38:20 UTC
Permalink
I have code which is saying something along the lines of:

<table>
{.repeated section cells}
<tr>
{.repeated section @}
<td class="cell">@</td>
{.end}
</tr>
{.end}
</table>

Running in the context {"cells":[[1,1,1],[1,1,1],[1,1,1]]}

The two @ are supposed to refer to different iterators. This code
seems to freeze up - I'm guessing it's because doing a repeated
section on @ breaks things. Is there a better (working?) way of
writing this?

Can't find this in the documentation or list history, sorry if it's
not a new question.

Cheers,
Andrey

--

You received this message because you are subscribed to the Google Groups "JSON Template" group.
To post to this group, send email to json-template-/JYPxA39Uh5TLH3MbocFF+G/***@public.gmane.org
For more options, visit this group at http://groups.google.com/group/json-template?hl=en.
Andy Chu
2009-11-19 04:13:15 UTC
Permalink
     <table>
         {.repeated section cells}
             <tr>
                 {.end}
             </tr>
         {.end}
     </table>
Running in the context {"cells":[[1,1,1],[1,1,1],[1,1,1]]}
seems to freeze up - I'm guessing it's because doing a repeated
writing this?
Can't find this in the documentation or list history, sorry if it's
not a new question.
Interesting, I thought this should work but indeed it doesn't. I see
the issue -- the way the context works, it's never changing @ to be
"1" -- only [1,1,1].

The simplest workaround is to make your JSON like:

{"cells": [
{"row": [1,1,1]},
{"row": [1,1,1]},
{"row": [1,1,1]},
]
}

I'll have to think about how/if this should work. It is kind of a
corner case. It definitely shouldn't cause an infinite loop though.

What is the exact use case here? Or did you just stumble on this?

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 json-template-/JYPxA39Uh5TLH3MbocFF+G/***@public.gmane.org
For more options, visit this group at http://groups.google.com/group/json-template?hl=.
Andy Chu
2009-11-19 04:29:58 UTC
Permalink
Nevermind, I figured it out. You know it's a bug when fixing it
*simplifies* the code rather than adding another case. Nice catch.

http://code.google.com/p/json-template/issues/detail?id=44

Which implementation were you using?

Andy
     <table>
         {.repeated section cells}
             <tr>
                 {.end}
             </tr>
         {.end}
     </table>
Running in the context {"cells":[[1,1,1],[1,1,1],[1,1,1]]}
seems to freeze up - I'm guessing it's because doing a repeated
writing this?
Can't find this in the documentation or list history, sorry if it's
not a new question.
Cheers,
Andrey
--
You received this message because you are subscribed to the Google Groups "JSON Template" group.
For more options, visit this group at http://groups.google.com/group/json-template?hl=en.
--

You received this message because you are subscribed to the Google Groups "JSON Template" group.
To post to this group, send email to json-template-/JYPxA39Uh5TLH3MbocFF+G/***@public.gmane.org
For more options, visit this group at http://groups.google.com/group/json-template?hl=.
Oliver Oli
2009-11-19 13:17:30 UTC
Permalink
I think I stumbled upon the same issue a few weeks ago, but thought
it's me not understanding jsontemplates. As I figured out the
workaround too, it was not a big issue anyway.

jsontemplate.py on google code was updated at the same time you fixed
the bug, but it's clearly different from _jsontemplate.py in the
mercurial repository.
Nevermind, I figured it out.  You know it's a bug when fixing it
*simplifies* the code rather than adding another case.  Nice catch.
http://code.google.com/p/json-template/issues/detail?id=44
Which implementation were you using?
Andy
     <table>
         {.repeated section cells}
             <tr>
                 {.end}
             </tr>
         {.end}
     </table>
Running in the context {"cells":[[1,1,1],[1,1,1],[1,1,1]]}
seems to freeze up - I'm guessing it's because doing a repeated
writing this?
Can't find this in the documentation or list history, sorry if it's
not a new question.
Cheers,
Andrey
--

You received this message because you are subscribed to the Google Groups "JSON Template" group.
To post to this group, send email to json-template-/JYPxA39Uh5TLH3MbocFF+G/***@public.gmane.org
For more options, visit this group at http://groups.google.com/group/json-template?hl=.
Andy Chu
2009-11-19 16:28:22 UTC
Permalink
Post by Oliver Oli
I think I stumbled upon the same issue a few weeks ago, but thought
it's me not understanding jsontemplates. As I figured out the
workaround too, it was not a big issue anyway.
jsontemplate.py on google code was updated at the same time you fixed
the bug, but it's clearly different from _jsontemplate.py in  the
mercurial repository.
Hm? I intended to make a direct copy, and it looks like it to me:

+D:\dev\hg\json-template\python\jsontemplate>md5sum jsontemplate.py
cb25fc84919458512213b5ddf65b6b2d *jsontemplate.py

+D:\dev\hg\json-template\python\jsontemplate>md5sum _jsontemplate.py
cb25fc84919458512213b5ddf65b6b2d *_jsontemplate.py

+D:\dev\hg\json-template\python\jsontemplate>diff jsontemplate.py
_jsontemplate.py

Did you pull?

Andy

--

You received this message because you are subscribed to the Google Groups "JSON Template" group.
To post to this group, send email to json-template-/JYPxA39Uh5TLH3MbocFF+G/***@public.gmane.org
For more options, visit this group at http://groups.google.com/group/json-template?hl=.
Oliver Oli
2009-11-19 17:19:45 UTC
Permalink
I downloaded it again from
http://code.google.com/p/json-template/downloads/list

it seems to be an older version

$ md5 jsontemplate.py
MD5 (jsontemplate.py) = daac178999e6cd19d7046b97139ff417

$ md5 _jsontemplate.py
MD5 (_jsontemplate.py) = cb25fc84919458512213b5ddf65b6b2d
Post by Andy Chu
Post by Oliver Oli
I think I stumbled upon the same issue a few weeks ago, but thought
it's me not understanding jsontemplates. As I figured out the
workaround too, it was not a big issue anyway.
jsontemplate.py on google code was updated at the same time you fixed
the bug, but it's clearly different from _jsontemplate.py in  the
mercurial repository.
+D:\dev\hg\json-template\python\jsontemplate>md5sum jsontemplate.py
cb25fc84919458512213b5ddf65b6b2d *jsontemplate.py
+D:\dev\hg\json-template\python\jsontemplate>md5sum _jsontemplate.py
cb25fc84919458512213b5ddf65b6b2d *_jsontemplate.py
+D:\dev\hg\json-template\python\jsontemplate>diff jsontemplate.py
_jsontemplate.py
Did you pull?
Andy
--

You received this message because you are subscribed to the Google Groups "JSON Template" group.
To post to this group, send email to json-template-/JYPxA39Uh5TLH3MbocFF+G/***@public.gmane.org
For more options, visit this group at http://groups.google.com/group/json-template?hl=.
Andy Chu
2009-11-19 17:47:50 UTC
Permalink
Post by Oliver Oli
I downloaded it again from
http://code.google.com/p/json-template/downloads/list
it seems to be an older version
$ md5 jsontemplate.py
MD5 (jsontemplate.py) = daac178999e6cd19d7046b97139ff417
$ md5 _jsontemplate.py
MD5 (_jsontemplate.py) = cb25fc84919458512213b5ddf65b6b2d
I think you didn't pull. The one in your workspace is the older one.

Andy

--

You received this message because you are subscribed to the Google Groups "JSON Template" group.
To post to this group, send email to json-template-/JYPxA39Uh5TLH3MbocFF+G/***@public.gmane.org
For more options, visit this group at http://groups.google.com/group/json-template?hl=.
Andrey Fedorov
2009-11-19 13:25:22 UTC
Permalink
Cool, thanks. My use case is very similar to the example, just with
strings instead of numbers.

Was using the version linked from the main site:

http://json-template.googlecode.com/files/json-template.js

Should I check one out from SVN to get the fix?

- Andrey

Sent from my cell. Please forgive abbreviations and typos.
Post by Andy Chu
Nevermind, I figured it out. You know it's a bug when fixing it
*simplifies* the code rather than adding another case. Nice catch.
http://code.google.com/p/json-template/issues/detail?id=44
Which implementation were you using?
Andy
On Wed, Nov 18, 2009 at 10:38 AM, Andrey Fedorov
Post by Andrey Fedorov
<table>
{.repeated section cells}
<tr>
{.end}
</tr>
{.end}
</table>
Running in the context {"cells":[[1,1,1],[1,1,1],[1,1,1]]}
seems to freeze up - I'm guessing it's because doing a repeated
writing this?
Can't find this in the documentation or list history, sorry if it's
not a new question.
Cheers,
Andrey
--
You received this message because you are subscribed to the Google
Groups "JSON Template" group.
For more options, visit this group at http://groups.google.com/group/json-template?hl=en
.
--
You received this message because you are subscribed to the Google
Groups "JSON Template" group.
For more options, visit this group at http://groups.google.com/group/json-template?hl=
.
--

You received this message because you are subscribed to the Google Groups "JSON Template" group.
To post to this group, send email to json-template-/JYPxA39Uh5TLH3MbocFF+G/***@public.gmane.org
For more options, visit this group at http://groups.google.com/group/json-template?hl=.
Andy Chu
2009-11-19 16:28:47 UTC
Permalink
Post by Andrey Fedorov
Cool, thanks. My use case is very similar to the example, just with
strings instead of numbers.
http://json-template.googlecode.com/files/json-template.js
Should I check one out from SVN to get the fix?
The latest one I released should also have the fix. In the download
description, it shows the revision number it's copied from.

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 json-template-/JYPxA39Uh5TLH3MbocFF+G/***@public.gmane.org
For more options, visit this group at http://groups.google.com/group/json-template?hl=.
Andrey Fedorov
2009-11-19 17:03:49 UTC
Permalink
Yup, the latest one works great. Thanks!

There isn't any way to access the outer @, is there? For example, in
tornado's templates, I'd do -

<table>
{% for i, n in enumerate(cells) %}
<tr>
{% for j, colr in enumerate(n) %}
<td class="cell" id="cell_{{i}}_by_{{j}}"
style="background: {{colr}};"></td>
{% end %}
</tr>
{% end %}
</table>

- Andrey
Post by Andy Chu
Post by Andrey Fedorov
Cool, thanks. My use case is very similar to the example, just with
strings instead of numbers.
http://json-template.googlecode.com/files/json-template.js
Should I check one out from SVN to get the fix?
The latest one I released should also have the fix. In the download
description, it shows the revision number it's copied from.
thanks,
Andy
--
You received this message because you are subscribed to the Google Groups
"JSON Template" group.
For more options, visit this group at
http://groups.google.com/group/json-template?hl=.
--

You received this message because you are subscribed to the Google Groups "JSON Template" group.
To post to this group, send email to json-template-/JYPxA39Uh5TLH3MbocFF+G/***@public.gmane.org
For more options, visit this group at http://groups.google.com/group/json-template?hl=.
Andy Chu
2009-11-19 17:47:30 UTC
Permalink
Post by Andrey Fedorov
Yup, the latest one works great. Thanks!
tornado's templates, I'd do -
    <table>
        {% for i, n in enumerate(cells) %}
            <tr>
                {% for j, colr in enumerate(n) %}
                    <td class="cell" id="cell_{{i}}_by_{{j}}"
style="background: {{colr}};"></td>
                {% end %}
           </tr>
       {% end %}
    </table>
- Andrey
I think you're asking for @index there. @index will give you the
inner one. I don't think it's implemented but if you need it,
***@index should give you an outer index.

It might have to be something like ***@.@index, which is pretty
ugly. But generally to get a table, using an array of objects is more
conventional than a 2D array, which will avoid this ugliness.

Andy

--

You received this message because you are subscribed to the Google Groups "JSON Template" group.
To post to this group, send email to json-template-/JYPxA39Uh5TLH3MbocFF+G/***@public.gmane.org
For more options, visit this group at http://groups.google.com/group/json-template?hl=.
Loading...