设为首页收藏本站

LUPA开源社区

 找回密码
 注册
文章 帖子 博客
LUPA开源社区 首页 业界资讯 技术文摘 查看内容

开源产品系列:简单强大的模板语言JSON Template

2013-1-22 16:09| 发布者: 红黑魂| 查看: 1954| 评论: 0|来自: CSDN

摘要: JSON Template是一款非常强大的模板语言,目前有Python和JavaScript两个实现版。遵循Apache License 2.0许可。JSON Template使用起来也非常方便,只需把Python file或者JavaScript file拷贝到你的项目里即可,无任何 ...

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


酷毙

雷人

鲜花
1

鸡蛋

漂亮

刚表态过的朋友 (1 人)

  • 快毕业了,没工作经验,
    找份工作好难啊?
    赶紧去人才芯片公司磨练吧!!

最新评论

关于LUPA|人才芯片工程|人才招聘|LUPA认证|LUPA教育|LUPA开源社区 ( 浙B2-20090187 浙公网安备 33010602006705号   

返回顶部