http://www.csdn.net/article/2013-01-22/2813859-JSON-Template
摘要:JSON Template是JSON模板的补充,是一款非常强大的模板语言,使用起来也非常方便,只需把Python file或者JavaScript file拷贝到你的项目里即可,无任何约束限制。
JSON Template是一款非常强大的模板语言,目前有Python和JavaScript两个实现版。遵循Apache License 2.0许可。
JSON Template使用起来也非常方便,只需把Python file或者JavaScript file拷贝到你的项目里即可,无任何约束限制。
简单示例
- >>> import jsontemplate
- >>> jsontemplate.expand('Hello {name}', {'name': 'world'})
- 'Hello world'
这个例子看起来与people.*非常相似,JavaScript版是对这个API的直接转换。
完整例子
下面提取了几个被广泛使用的例子。
A template string
- {# This is a comment and will be removed from the output.}
- {.section songs}
- <h2>Songs in '{playlist-name}'</h2>
- <table width="100%">
- {.repeated section @}
- <tr>
- <td><a href="{url-base|htmltag}{url|htmltag}">Play</a>
- <td><i>{title}</i></td>
- <td>{artist}</td>
- </tr>
- {.end}
- </table>
- {.or}
- <p><em>(No page content matches)</em></p>
- {.end}
combined with a data dictionary
- {
- "url-base": "http://example.com/music/",
- "playlist-name": "Epic Playlist",
- "songs": [
- {
- "url": "1.mp3",
- "artist": "Grayceon",
- "title": "Sounds Like Thunder"
- },
- {
- "url": "2.mp3",
- "artist": "Thou",
- "title": "Their Hooves Carve Craters in the Earth"
- }
- ]
- }
点击查看更多JavaScript示例。
有哪些特征:
- JSON Template是JSON模板的补充
- 简单易读的语法,即使是非专业程序员也可以轻松编辑模板文件
- 默认“格式化”设置,因此很容易获取escaping/security权利
- 可扩展特定应用程序格式
- 这种较小程度的自定义语法可以解决许多领域里的问题(不仅仅是Web方面)
- 定义良好的声明、面向数据API,并且使用JSON作为数据模型
- 点击查看更多特征
项目首页:http://code.google.com/p/json-template/
下载地址:http://code.google.com/p/json-template/downloads/list
详细介绍及教程:http://json-template.googlecode.com/svn/trunk/doc/Introducing-JSON-Template.html