j***@public.gmane.org
2010-11-05 02:10:03 UTC
Status: New
Owner: ----
Labels: Type-Defect Priority-Medium
New issue 58 by elijahr: Add a LISP-style "let" statement
http://code.google.com/p/json-template/issues/detail?id=58
Sometimes it would be nice to have an explicit way of assigning the value
of one name to another so that, in situations where there is a name
collision, the template writer could be specific about choosing which name
they wanted rather than not have access to names higher up in the scope
chain. A good example of such a collision is detailed in issue #52 with
the name "url".
I think a "let" statement, such as LISP's, would work well here.
For example, here's the template and expansion dictionary from issue #52
and the documentation, with a "let" statement added.
{.section songs}
<h2>Songs in '{playlist-name}'</h2>
{.let playlist-url url}
<table width="100%">
{.repeated section @}
<tr>
<td><a href="{url-base|htmltag}{url|htmltag}">Play</a>
<td><i>{title}</i></td>
<td>{artist}</td>
<td><a href="{url-base|htmltag}{playlist-url|htmltag}">Link to
playlist</a>
</tr>
{.end}
</table>
{.end}
{.or}
<p><em>(No page content matches)</em></p>
{.end}
... combined with a data dictionary ...
{
"url": "happy!",
"url-base": "http://example.com/music/",
"playlist-name": "Epic Playlist",
"songs": [
{
"artist": "Grayceon",
"title": "Sounds Like Thunder"
},
{
"url": "2.mp3",
"artist": "Thou",
"title": "Their Hooves Carve Craters in the Earth"
}
]
}
Perhaps it is not the best example to illustrate the usefulness of this
language addition, but hopefully it is clear that it does solve an actual
problem.
Owner: ----
Labels: Type-Defect Priority-Medium
New issue 58 by elijahr: Add a LISP-style "let" statement
http://code.google.com/p/json-template/issues/detail?id=58
Sometimes it would be nice to have an explicit way of assigning the value
of one name to another so that, in situations where there is a name
collision, the template writer could be specific about choosing which name
they wanted rather than not have access to names higher up in the scope
chain. A good example of such a collision is detailed in issue #52 with
the name "url".
I think a "let" statement, such as LISP's, would work well here.
For example, here's the template and expansion dictionary from issue #52
and the documentation, with a "let" statement added.
{.section songs}
<h2>Songs in '{playlist-name}'</h2>
{.let playlist-url url}
<table width="100%">
{.repeated section @}
<tr>
<td><a href="{url-base|htmltag}{url|htmltag}">Play</a>
<td><i>{title}</i></td>
<td>{artist}</td>
<td><a href="{url-base|htmltag}{playlist-url|htmltag}">Link to
playlist</a>
</tr>
{.end}
</table>
{.end}
{.or}
<p><em>(No page content matches)</em></p>
{.end}
... combined with a data dictionary ...
{
"url": "happy!",
"url-base": "http://example.com/music/",
"playlist-name": "Epic Playlist",
"songs": [
{
"artist": "Grayceon",
"title": "Sounds Like Thunder"
},
{
"url": "2.mp3",
"artist": "Thou",
"title": "Their Hooves Carve Craters in the Earth"
}
]
}
Perhaps it is not the best example to illustrate the usefulness of this
language addition, but hopefully it is clear that it does solve an actual
problem.
--
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
To unsubscribe from this group, send email to json-template+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/***@public.gmane.org
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
To unsubscribe from this group, send email to json-template+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/***@public.gmane.org
For more options, visit this group at http://groups.google.com/group/json-template?hl=en.