{
  "name": "art-template",
  "description": "JavaScript Template Engine",
  "homepage": "http://aui.github.com/artTemplate/",
  "keywords": [
    "util",
    "functional",
    "template"
  ],
  "author": {
    "name": "tangbin",
    "email": "sugarpie.tang@gmail.com"
  },
  "repository": {
    "type": "git",
    "url": "git://github.com/aui/artTemplate.git"
  },
  "main": "./src/template.js",
  "version": "2.0.3-rc5",
  "license": "BSD",
  "readme": "# artTemplate\n###### 新一代 javascript 模板引擎\n=================\n\nartTemplate 是新一代 javascript 模板引擎，它在 v8 中的渲染效率可接近 javascript 性能极限，在 chrome 下渲染效率测试中分别是知名引擎 Mustache 与 micro tmpl 的 25 、 32 倍（[性能测试](http://aui.github.com/artTemplate/test/test-speed.html)）。\n\n引擎支持调试。若渲染中遇到错误，调试器可精确定位到产生异常的模板语句，解决前端模板难以调试的问题（[详情](http://aui.github.io/artTemplate/demo/debug.html)）。\n\n另外，artTemplate 的模板还支持使用自动化工具预编译，支持将模板转换为 js 文件。\n\n## 快速上手\n\n###\t引用引擎\n\n\t<script src=\"dist/template.js\"></script>\n\t\n直接下载 [template.js](https://raw.github.com/aui/artTemplate/master/dist/template.js)\n\n### 编写模板\n\n使用一个``type=\"text/html\"``的``script``标签存放模板：\n\t\n\t<script id=\"test\" type=\"text/html\">\n\t<h1><%=title%></h1>\n\t<ul>\n    \t<%for(i = 0; i < list.length; i ++) {%>\n        \t<li>条目内容 <%=i + 1%> ：<%=list[i]%></li>\n    \t<%}%>\n\t</ul>\n\t</script>\n\t\n模板逻辑语法开始与结束的界定符号为``<%`` 与``%>``，若``<%``后面紧跟``=``号则输出变量内容。\n\n### 渲染模板\n\n``template.render(id, data)``\n\t\n\tvar data = {\n\t\ttitle: '标签',\n\t\tlist: ['文艺', '博客', '摄影', '电影', '民谣', '旅行', '吉他']\n\t};\n\tvar html = template.render('test', data);\n\tdocument.getElementById('content').innerHTML = html;\n\n\n[演示](http://aui.github.com/artTemplate/demo/basic.html)\n\n\n## 嵌入子模板\n\n``<%include(id, [data])%>``语句可以嵌入子模板，其中第二个参数是可选的，它默认传入当前的数据。\n\n\t<script id=\"test\" type=\"text/html\">\n\t<h1><%=title%></h1>\n\t<%include('list')%>\n\t</script>\n\t\n\t<script id=\"list\" type=\"text/html\">\n\t<ul>\n    \t<%for(i = 0; i < list.length; i ++) {%>\n        \t<li>条目内容 <%=i + 1%> ：<%=list[i]%></li>\n    \t<%}%>\n\t</ul>\n\t</script>\n\t\n[演示](http://aui.github.com/artTemplate/demo/include.html)\n\n## 不转义HTML\n\n模板引擎默认数据包含的 HTML 字符进行转义以避免 XSS 漏洞，若不需要转义的地方可使用``<%=#value%>``（兼容v2.0.3 版本之前使用的``<%==value%>``）。\n\n\t<script id=\"test\" type=\"text/html\">\n\t<%=#value%>\n\t</script>\n\t\n若需要关闭默认转义，可以设置``template.isEscape = false``。\n\n[演示](http://aui.github.com/artTemplate/demo/no-escape.html)\n\n## 在js中存放模板\n\n``template.compile([id], source)``将返回一个渲染函数。其中 id 参数是可选的，如果使用了 id 参数，可以使用``template.render(id, data)``渲染模板。\n\n\tvar source =\n\t  '<ul>'\n\t+    '<% for (var i = 0; i < list.length; i ++) { %>'\n\t+        '<li>索引 <%= i + 1 %> ：<%= list[i] %></li>'\n\t+    '<% } %>'\n\t+ '</ul>';\n\t\n\tvar data = {\n\t    list: ['文艺', '博客', '摄影', '电影', '民谣', '旅行', '吉他']\n\t};\n\t\n\tvar render = template.compile(source);\n\tvar html = render(data);\n\tdocument.getElementById('content').innerHTML = html;\n\t\n[演示](http://aui.github.com/artTemplate/demo/compile.html)\n\n## 添加辅助方法\n\n``template.helper(name, callback)``辅助方法一般用来进行字符串替换，如 UBB 替换、脏话替换等。\n\n例如扩展一个UBB替换方法：\n\n\ttemplate.helper('$ubb2html', function (content) {\n    \treturn content\n    \t.replace(/\\[b\\]([^\\[]*?)\\[\\/b\\]/igm, '<b>$1</b>')\n    \t.replace(/\\[i\\]([^\\[]*?)\\[\\/i\\]/igm, '<i>$1</i>')\n    \t.replace(/\\[u\\]([^\\[]*?)\\[\\/u\\]/igm, '<u>$1</u>')\n    \t.replace(/\\[url=([^\\]]*)\\]([^\\[]*?)\\[\\/url\\]/igm, '<a href=\"$1\">$2</a>')\n    \t.replace(/\\[img\\]([^\\[]*?)\\[\\/img\\]/igm, '<img src=\"$1\" />');\n\t});\n\t\n在模板中的使用方式：\n\n\t<%=$ubb2html(content) %>\n\t\n注意：引擎不会对辅助方法输出的 HTML 字符进行转义。\n\t\n[演示](http://aui.github.com/artTemplate/demo/helper.html)\n\n## 设置界定符\n\n若前端模板语法与后端语法产生冲突，可以修改模板引擎界定符，例如：\n\n\ttemplate.openTag = \"<!--[\";\n\ttemplate.closeTag = \"]-->\";\n\t\n[演示](http://aui.github.com/artTemplate/demo/tag.html)\n\n## 自定义语法\n\nartTemplate 提供一个语法扩展用来简化模板逻辑语法。简洁语法示例：\n\n\t{{if admin}}\n    \t<h3>{{title}}</h3>\n    \t<ul>\n    \t    {{each list}}\n            \t<li>{{$index + 1}}: {{$value}}</li>\n       \t\t{{/each}}\n    \t</ul>\n\t{{/if}}\n\n请引用 dist/[template-simple.js](https://raw.github.com/aui/artTemplate/master/dist/template-simple.js) 即可使用简洁语法。\n\t\n[完整简洁语法说明](https://github.com/aui/artTemplate/wiki/自定义语法扩展说明)\n\n##\tNodeJS\n\n###\t安装\n\n\t$ npm install art-template -g\n\t\n###\t使用\n\n\tvar template = require('art-template');\n\t\n（简洁语法版请 ``require('art-template/dist/template-simple')``）\n\n## 自动化工具\n\n### 预编译工具\n\n使用它可以让前端模版不再受浏览器的限制，支持如后端模版一样按文件放置、include 语句等特性，可以像后端一样书写前端模板！\n\n项目主页：<https://github.com/aui/tmodjs>\n\n### 抽取工具\n\n[./tools/combine.html](http://aui.github.com/artTemplate/tools/combine.html)\n\n可以把 HTML 中的模板提取出来以便把模板嵌入到 js 文件中。\n\n与编译工具不同的是，抽取后的模板仍然依赖引擎运行。\n\n## 模板编码规范\n\n1、不能使用 javascript 关键字作为模板变量(包括 ECMA5 严格模式下新增的关键字):\n\n> break, case, catch, continue, debugger, default, delete, do, else, false, finally, for, function, if, in, instanceof, new, null, return, switch, this, throw, true, try, typeof, var, void, while, with, abstract, boolean, byte, char, class, const, double, enum, export, extends, final, float, goto, implements, import, int, interface, long, native, package, private, protected, public, short, static, super, synchronized, throws, transient, volatile, arguments, let, yield\n\n2、模板运行在沙箱中，内部无法访问外部变量，除非给模板定义辅助方法。例如：\n\n\ttemplate.helper('Math', Math)\n\n> 模板中若任意引用外部对象，复杂的依赖管理将会让项目难以维护，这种方式将利于后续模板迁移（包括通过工具预编译）。\n\n\n## 更新记录\n\n###\tv2.0.3\n\n1.\t优化辅助方法性能\n2.\tNodeJS 用户可以通过 npm 获取 artTemplate：``$ npm install art-template -g``\n3.\t不转义输出语句推荐使用``<%=#value%>``（兼容 v2.0.3 版本之前使用的``<%==value%>``），而简版语法则可以使用``{{#value}}``\n4.\t提供简版语法的合并版本 dist/[template-simple.js](https://raw.github.com/aui/artTemplate/master/dist/template-simple.js)\n\n### v2.0.2\n\n1.\t优化自定义语法扩展，减少体积\n2.\t[重要]为了最大化兼容第三方库，自定义语法扩展默认界定符修改为``{{``与``}}``。\n3.\t修复合并工具的BUG [#25](https://github.com/aui/artTemplate/issues/25)\n4.\t公开了内部缓存，可以通过``template.cache``访问到编译后的函数\n5.\t公开了辅助方法缓存，可以通过``template.helpers``访问到\n6.\t优化了调试信息\n\n### v2.0.1\n\n1.\t修复模板变量静态分析的[BUG](https://github.com/aui/artTemplate/pull/22)\n\n### v2.0 release\n\n1.\t编译工具更名为 atc，成为 artTemplate 的子项目单独维护：<https://github.com/cdc-im/atc>\n\n### v2.0 beta5\n\n1. 修复编译工具可能存在重复依赖的问题。感谢 @warmhug\n2. 修复``include``内部实现可能产生上下文不一致的问题。感谢 @warmhug\n3. 支持使用拖拽文件到``compile.cmd``图标上进行单独编译\n\n### v2.0 beta4\n\n1. 修复编译工具在压缩模板可能导致 HTML 意外截断的问题。感谢 @warmhug\n2. 完善编译工具对``include``支持支持，可以支持不同目录之间模板嵌套\n3. 修复编译工具没能正确处理自定义语法插件的辅助方法\n\n### v2.0 beta1\n\n1.\t对非String、Number类型的数据不输出，而Function类型求值后输出。\n2.\t默认对html进行转义输出，原文输出可使用``<%==value%>``（备注：v2.0.3推荐使用``<%=#value%>``），也可以关闭默认的转义功能``template.isEscape = false``。\n3.\t增加批处理工具支持把模板编译成不依赖模板引擎的 js 文件，可通过 RequireJS、SeaJS 等模块加载器进行异步加载。\n\n## 授权协议\n\nReleased under the MIT, BSD, and GPL Licenses\n\n============\n\n[所有演示例子](http://aui.github.com/artTemplate/demo/index.html) | [引擎原理](http://cdc.tencent.com/?p=5723)\n\n© cdc.tencent.com\n",
  "readmeFilename": "README.md",
  "bugs": {
    "url": "https://github.com/aui/artTemplate/issues"
  },
  "_id": "art-template@2.0.3-rc5",
  "dist": {
    "shasum": "1494e9698b6f8d36892e4967691e7a9667ef41c7"
  },
  "_from": "art-template@",
  "_resolved": "https://registry.npmjs.org/art-template/-/art-template-2.0.3-rc5.tgz"
}
