
Security News
Happy Birthday, Shai-Hulud
It has been one year since Shai-Hulud made its first appearance on npm.
fork from https://github.com/jojoin/tppl
做了以下改动:
js-tppl============
编写模板
使用一个type="text/html"的script标签存放模板:
<script id="test" type="text/html">
[: if (title){ :]
[: for (var i=0;i<list.length;i++) { :]
<div>[:=i:]. [:=list[i].user:]</div>
[:}:]
[:=this.name||"name is not found !":]
[:}:]
</script>
渲染模板
var data = {
title: '标签',
list: ['文艺', '博客', '摄影', '电影', '民谣', '旅行', '吉他']
};
var html = tppl(document.getElementById('test').innerHTML, data);
============
返回模板渲染函数render(data)
返回渲染函数。
var tpl = "..." , data = {...};
var render = tppl(tpl); //渲染函数
var html = render(data); //重复使用
============
| 字段 | 类型 | 值 | 说明 |
|---|---|---|---|
| openTag | String | [: | 逻辑语法开始标签 |
| closeTag | String | :] | 逻辑语法结束标签 |
| valueTag | String | = | 输出变量开始标签,结合openTag使用 |
以上字段均可以通过 options参数替换
变量默认值
为未定义的或值为假的变量给出默认值:
[:=foo||"变量foo存在但值为假":]
[:=this.foo||"变量foo不存在或为假!":]
避免未定义的变量引起系统崩溃
若模板中定义了一个变量输出,但传入数据中却没有这个变量,模板解析就会出错,从而引起整个程序的崩溃。如果无法确保数据完整性,仍然有方法可以对其成员进行探测。在需要检测的变量前加关键字 this,如:
[: if (this.dataName !== undefined) { :]
[:= dataName :]
[: } :]
也可为不存在的变量设置默认值:
[:=this.foo||"变量foo不存在或为假!":]
其它判断:
[:=foo ? 1 : 0:]
[:=this.foo ? "存在" : "变量foo不存在或为假!":]
============
============

"第一梯队"效率测试:

tppl 的编译渲染速度是著名的 jQuery 作者 John Resig 开发的 tmpl 的 43 倍!与第二名 artTemplate 也有一倍的差距。 查看 性能测试 ,单次结果不一定准确,请多测几次。
============
Released under the MIT, BSD, and GPL Licenses
============
© 杨捷 yangjie@jojoin.com
FAQs
js模板引擎
We found that js-tppl demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.

Security News
It has been one year since Shai-Hulud made its first appearance on npm.

Research
/Security News
Operators behind PolinRider used a compromised GitHub account to plant malware in four development versions of a Packagist package with 700,000+ downloads.

Security News
GitHub Actions now supports cache-mode, a least-privilege control on the Actions cache aimed at the cache poisoning technique behind recent compromises.