saker
v1.1.1
Published
Saker is a template engine for Node.js and browsers, it is lightweight, powerfull and easy to use.
Downloads
15
Maintainers
Readme
Saker
Full documentation is at https://eshengsky.github.io/saker/.
完整文档请查看https://eshengsky.github.io/saker/。
Saker is a template engine for Node.js and browsers, it is lightweight, powerfull and easy to use.
The greatest feature is, Saker minimizes the number of characters and keystrokes required in a file, and enables a fast, fluid coding workflow. Unlike most template syntaxes, you do not need to interrupt your coding to explicitly denote server blocks within your HTML. See Example for preview.
Saker是一个可以用于Node.js和浏览器端的模板引擎,轻量、强大、易于使用。其最大的特点是,尽可能地减少了模板文件中的额外字符和击键数,支持快速流畅的编码流程。不同于大多数的模板引擎语法,你无须打断你的编码来显式表明HTML中的服务器代码 —— Saker能够智能识别哪些是HTML哪些是服务器脚本。可以查看示例代码作为预览。
Comparison 比较
Let's compare Saker with other hot template engines.
Saker和当前较流行的几款模板引擎(Jade、Handlebars、ejs)的比较。
Live Demo 在线演示
You can test drive Saker online here.
你可以在这里测试Saker。
Installation 安装
$ npm install saker
Example 示例
This is a very simple and representative sample, it shows a name list when code is 1, and if the gender is female, the <li> tag has a class 'pink'.
这是一个非常简单又很典型的例子,当code的值为1时会显示一个名单,如果gender字段是female,则<li>标签还会添加'pink'类。
data 数据
{
"code" : 1,
"data": [{
"id" : 1,
"name" : "Sky",
"gender" : "male"
}, {
"id" : 2,
"name" : "Kathy",
"gender" : "female"
}]
}
template 模板
@{ this.layout = null }
<h2>Name List</h2>
<article>
@if(code === 1) {
<ul>
@{
data.forEach(function(person) {
<li class="@(person.gender === 'female' ? 'pink' : '')">
<a href="/details/@person.id">@person.name</a>
</li>
});
}
</ul>
} else {
<p>Sorry, no data!</p>
}
</article>
result 结果
<h2>Name List</h2>
<article>
<ul>
<li>
<a href="/details/1">Sky</a>
</li>
<li class="pink">
<a href="/details/2">Kathy</a>
</li>
</ul>
</article>
For more examples, please see examples
folder, it includes 3 examples each based on:
更多示例请查看examples
目录,其包含了3个示例分别基于:
- the native Node.js server 原生Node.js server
- the Express framework Express框架
- the browser side 浏览器端
Syntax 语法
As you see above, Saker uses '@' as the default mark symbol (support custom) - the codes after it represent server-side scripts.
The following is the syntax cheat sheet, for more details you can see Syntax Reference.
正如你在上面看到的,Saker使用'@'作为默认的标记符号(支持自定义)——在这之后的代码都视作是服务器端脚本。下面是一个语法速查,更详细的文档请查看Syntax Reference。
Test 测试
You can execute the following script in terminal to run test.
你可以在终端执行下面的脚本来运行测试。
$ npm test
License 许可
The MIT License (MIT)
Copyright (c) 2016 Sky
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.