码迷,mamicode.com
首页 > 其他好文 > 详细

juicer前端模板引擎

时间:2016-11-05 02:41:03      阅读:272      评论:0      收藏:0      [点我收藏+]

标签:函数   item   定义函数   模板   nbsp   定义   str   java   前端   

Juicer

中文文档:http://www.juicer.name/docs/docs_zh_cn.html
官网:http://juicer.name/

一个Javascript模板引擎的实现和优化(http://www.open-open.com/lib/view/open1335161835655.html)完全剥离html和代码逻辑,便于多人协作和后期的代码维护。
市面上众多的模板引擎,诸如Mustache, jQuery tmpl, Kissy template, ejs, doT, nTenjin。
“如无必要,勿增实体。” 这是著名的奥卡姆剃须刀法则,简单的说就是避免重复造轮子。

 

语法

a. ${变量}
支持自定义函数。(通过自定义函数你可以实现很多有趣的功能,类似 ${data|links} 就可以 通过事先定义的自定义函数 links 直接对 data 拼装出<a href=".." alt=".." /> ).

可以看得出,结果被转义了,如果我们上边使用 $${item|links} 就会得到我们预期的结果,这就是下边即将提到的避免转义。
var json = {
value: ‘<strong>juicer</strong>‘
};
var escape_tpl=‘${value}‘;
var unescape_tpl=‘$${value}‘;
juicer(escape_tpl, json); //输出 ‘&lt;strong&gt;juicer&lt;/strong&gt;‘
juicer(unescape_tpl, json); //输出 ‘<strong>juicer</strong>‘


{@each list as item,index}
{@if index===3}
the index is 3, the value is ${item.prop}
{@else if index === 4}
the index is 4, the value is ${item.prop}
{@else}
the index is not 3, the value is ${item.prop}
{@/if}
{@/each}

 

juicer前端模板引擎

标签:函数   item   定义函数   模板   nbsp   定义   str   java   前端   

原文地址:http://www.cnblogs.com/lsx1993/p/6032068.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!