打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
[开源推荐]简单强大的模板语言JSON Template

JSON Template是一款非常强大的模板语言,目前有Python和JavaScript两个实现版。遵循Apache License 2.0许可。

JSON Template使用起来也非常方便,只需把Python file或者JavaScript file拷贝到你的项目里即可,无任何约束限制。

简单示例

  1. >>> import jsontemplate  
  2. >>> jsontemplate.expand('Hello {name}', {'name''world'})  
  3. 'Hello world' 

 这个例子看起来与people.*非常相似,JavaScript版是对这个API的直接转换。

完整例子

下面提取了几个被广泛使用的例子。

A template string

  1. {# This is a comment and will be removed from the output.}  
  2.  
  3. {.section songs}  
  4.   <h2>Songs in '{playlist-name}'</h2>  
  5.  
  6.   <table width="100%">  
  7.   {.repeated section @}  
  8.     <tr>  
  9.       <td><a href="{url-base|htmltag}{url|htmltag}">Play</a>  
  10.       <td><i>{title}</i></td>  
  11.       <td>{artist}</td>  
  12.     </tr>  
  13.   {.end}  
  14.   </table>  
  15. {.or}  
  16.   <p><em>(No page content matches)</em></p>  
  17. {.end} 

combined with a data dictionary

  1. {  
  2.   "url-base""http://example.com/music/",   
  3.   "playlist-name""Epic Playlist",   
  4.   "songs": [  
  5.     {  
  6.       "url""1.mp3",   
  7.       "artist""Grayceon",   
  8.       "title""Sounds Like Thunder" 
  9.     },   
  10.     {  
  11.       "url""2.mp3",   
  12.       "artist""Thou",   
  13.       "title""Their Hooves Carve Craters in the Earth" 
  14.     }  
  15.   ]  

点击查看更多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

本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
New Pop Songs Playlist 2020 TOP 40 Songs of 2020
New English Song 2021 Latest English Songs 2021 English Pop Songs Playlist
JSON数据格式
漂亮的白色开衫外套(有图解)
像专业人员一样开发 Ajax 应用程序,第 1 部分: 使用 Prototype Java...
【python实现网络爬虫(14)】python爬取酷狗中多类型音乐步骤详解(附全部源代码)
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服