{"_id":"velocity.js","_rev":"45-c63a29ac482edb4da22aa1b354e07045","name":"velocity.js","description":"Velocity Template Language(VTL) for JavaScript","dist-tags":{"latest":"0.3.4"},"versions":{"0.0.1":{"name":"velocity.js","description":"Velocity Template Language(VTL) for JavaScript","version":"0.0.1","keywords":["velocity template"],"repository":{"type":"git","url":"git://github.com/shepherdwind/velocity.js.git"},"engines":{"node":">=0.8.0"},"main":"src/velocity.js","bin":{"handlebars":"bin/velocity"},"readme":"Velocity Template Language(VTL) for JavaScript\n---------------------------------------------\n\nJavaScript版本VTL，Velocity是基于Java的模板引擎，veloctiy.js是JS版本的实现，实现\n依据[velocity user guide](http://velocity.apache.org/engine/devel/user-guide.html)。\n","_id":"velocity.js@0.0.1","dist":{"shasum":"7571dcf3645216e3b1b4c639068031404200d447","tarball":"https://registry.npmjs.org/velocity.js/-/velocity.js-0.0.1.tgz","integrity":"sha512-h+RJq7rRB5EVMjMYsn2QiV0LZ1g3Du+WdDlmaiIGiOZlmNpDXyXP2Tp+RTm3hTyXNX5yWLGcKl0m+OX3Nho47w==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIDuJ5px3G5CQ6mmLWnUGcXRDMLaW7fx22OCCqXaqTrFJAiBsrymxlyPtLy72gyBF9LiJrx6JsTpoe2dQPP0H1CfonA=="}]},"_npmVersion":"1.1.62","_npmUser":{"name":"shepherdwind","email":"eward.song@gmail.com"},"maintainers":[{"name":"shepherdwind","email":"eward.song@gmail.com"}],"directories":{}},"0.1.1":{"name":"velocity.js","description":"Velocity Template Language(VTL) for JavaScript","version":"0.1.1","keywords":["velocity template"],"repository":{"type":"git","url":"git://github.com/shepherdwind/velocity.js.git"},"engines":{"node":">=0.8.0"},"main":"src/velocity.js","bin":{"velocity":"bin/velocity"},"readme":"Velocity Template Language(VTL) for JavaScript\n---------------------------------------------\n\nJavaScript版本VTL，Velocity是基于Java的模板引擎，veloctiy.js是JS版本的实现。\n\n特点：\n\n- 语法分析和模板渲染分离(参考xtemplate方案)，本地编译模板\n- 基本完全支持velocity语法\n- 支持模板之间相互引用，依据kissy木块加载机制(可推及其他模块加载器)\n\n##Documents\n\n[velocity user guide](http://velocity.apache.org/engine/devel/user-guide.html)\n\n##Use\n\nvelocity.js使用分为web端和本地使用，web端作为一个模板引擎，本地作为node模板使用。\nweb端，使用build/velocity，本地通过npm安装`npm install velocity.js`。\n\n###On Web\n\nweb浏览器使用，作为KISSY的一个模块，编译通过`Cakefile`完成，同样可以编译适用其他\n库，使用js在`build/veloctiy/`目录中: \n\n- `index.js` Velocity解释器\n- `parse.js` Velocity语法分析器\n\n把语法分析和解释器分开，为了方便在本地编译语法书，在web端少做一些计算。本地编译\n模板的思路，源自KISSY的[xtemplate](http://docs.kissyui.com/docs/html/api/component/xtemplate/)。\n\n虽然语法解释器可以在浏览器端执行，但是，不推荐那么使用。\n\n第一种方式，解释和语法分析同时执行：\n\n  ```js\nKISSY.use('velocity/index, velocity/parse', function(S, Velocity, Parser){\n  var html = (S.all('#tpl').html());\n  var asts = Parser.parse(html);\n  var compile = new Velocity(asts);\n  console.log(compile.render());\n});\n  ```\n  \n第二种方式，线下编译：\n\n```\n使用velocity命令行工具打包\nveloctiy --build *.vm\nveloctiy -b *.vm\n```\n\n浏览器使用：\n\n```js\nKISSY.use('velocity/index, web/directives', function(S, Velocity, asts){\n  var compile = new Velocity(asts);\n  console.log(compile.render());\n});\n```\n\n###模板引用\n\n支持模板使用`#parse('file.vm')`形式引用其他模板，在web端引用依据kissy的模块加载\n机制。\n\n```html\n#parse(\"web/macro.vm\")\n#set( $parts = [\"volva\",\"stipe\",\"annulus\",\"gills\",\"pileus\"] )\n#set( $cellbgcol = \"#CC00FF\" )\n<table>\n  #tablerows( $cellbgcol $parts )\n</table>\n```\n\nmacro.vm中定义：\n\n```\n#macro( tablerows $color $somelist )\n  #foreach( $something in $somelist )\n    <tr><td bgcolor=$color>$something</td></tr>\n  #end\n#end\n```\n\n###On nodejs\n\nnode端和web端api使用一致。\n","_id":"velocity.js@0.1.1","dist":{"shasum":"2f049192826d4df47dc028deb3b55da854cc5b0a","tarball":"https://registry.npmjs.org/velocity.js/-/velocity.js-0.1.1.tgz","integrity":"sha512-9K7e4Mufx2fQYyuaFv6zFRA2VO1h4WoaANjo29owBSd5HNP1uUUvMe2ldsYHl734h4tbz6i63FHNPdKtoN/6Wg==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIHyluYdqlSd+10VzaW6akiOHLvZgBZTi1pUbTLMDhx6cAiATsZOMPLfvS6N9rneZPdXZM8+ABcubxZAFhTirqc1LJQ=="}]},"_npmVersion":"1.1.62","_npmUser":{"name":"shepherdwind","email":"eward.song@gmail.com"},"maintainers":[{"name":"shepherdwind","email":"eward.song@gmail.com"}],"directories":{}},"0.1.2":{"name":"velocity.js","description":"Velocity Template Language(VTL) for JavaScript","version":"0.1.2","keywords":["velocity template"],"repository":{"type":"git","url":"git://github.com/shepherdwind/velocity.js.git"},"engines":{"node":">=0.8.0"},"main":"src/velocity.js","bin":{"velocity":"bin/velocity"},"readme":"##Velocity - Template Engine\n\nvelocity.js是velocity模板语法的javascript实现。\n[Velocity](http://velocity.apache.org/) 是基于Java的模板引擎，广泛应用在阿里集\n体各个子公司。Velocity模板适用于大量模板使用的场景，支持复杂的逻辑运算，包含\n基本数据类型、变量赋值和函数等功能。\n\nvelocity.js特点：\n\n- 支持客户端和服务器端使用\n- 语法是富逻辑的，构成门微型的语言\n- 语法分析和模板渲染分离\n- 基本完全支持velocity语法\n- 浏览器使用支持模板之间相互引用，依据kissy木块加载机制\n- 三个Helper，友好的数据模拟解决方案\n- [Vim Syntax](https://github.com/shepherdwind/vim-velocity)\n\n##Install\n\nvia npm:\n\n```bash\n$ npm install velocity.js\n```\n\n##Broswer Support\n\n点击[此处](http://git.shepherdwind.com/velocity.js/try/index.html)可以体验web\n端velocity语法解析过程，注：使用ACE作为代码编辑器，仅支持高级浏览器访问。\n\n执行`cake`命令进行打包velocity.js浏览器端脚本:\n\n```bash\n$ cake --build\n```\n\n需要cli下安装coffeejs，暂时打包是为kissy所使用的，velocity.js需要的一些常用的\necma5功能，比如`foreach, some, isArray`等，在node环境下是自带的功能，而web端的兼\n容是交给已有的类库解决。需要自行提供一组跨浏览器的api，比如kissy打包：\n\n```js\n  //api map\n  var utils = {\n    forEach : S.each,\n    some    : S.some,\n    mixin   : S.mix,\n    guid    : S.guid,\n    isArray : S.isArray,\n    indexOf : S.indexOf,\n    keys    : S.keys,\n    now     : S.now\n  };\n\n```\n\nVelocity语法具有很高的容错能力，类似于html结构的解析，同时语法规则复杂，所以语法\n解释器执行性能可能比较慢，`velocity.js`把语法结构分析运算和语法执行两个过程独立出来，\n第一步，语法结构分析返回一个数组(语法树)，描述velocity语法，语法执行使用数据和语\n法树，计算模板最终结果。\n\n执行build后，得到两个文件，分别是`build/velocity/`下的`index.js`和`parse.js`，两者\n相互独立，`parse.js`语法分析过程可以放在本地完成，执行命令：\n\n把语法分析和模板拼接分开，为了方便在本地编译语法树，减少在web端js运算。本地编译\n模板的思路，源自KISSY的[xtemplate](http://docs.kissyui.com/docs/html/api/component/xtemplate/)。\n\n虽然语法解释器可以在浏览器端执行，但是，不推荐那么使用。\n\n```bash\n#使用velocity命令行工具打包\nveloctiy --build *.vm\nveloctiy -b *.vm\n```\n\n源码中`test/web/`目录的js，一部分就是线下编译后的得到的，此处可[直接访问](http://git.shepherdwind.com/velocity.js/web/index.html)。\n\n##Public API\n\n###node_module\n\n```js\nvar Velocity = require('../src/velocity');\n\n//1. 直接解析\nVelocity.render('string of velocity', context);\n\n//2. 使用Parser和Compile\nvar Parser = Velocity.Parser;\nvar Compile = Velocity.Compile;\n\nvar asts = Parser.parse('string of velocity');\n(new Compile(asts)).render(context);\n```\n####context\n\n`context`是一个对象，可以为空，执行中`$foo.bar`，访问路径是`context.foo.bar`，\n`context`的属性可以是函数，和vm中定义保持一致。\n\n###On Broswer\n\n1 . 使用线下打包方案：\n\n```js\nKISSY.use('velocity/index, web/directives', function(S, Velocity, asts){\n  var compile = new Velocity(asts);\n  S.all('body').html(compile.render());\n});\n```\n\n2 . 使用线上编译：\n\n```js\nKISSY.use('velocity/index, velocity/parse', function(S, Velocity, Parser){\n  var html = (S.all('#tpl').html());\n  var asts = Parser.parse(html);\n  var compile = new Velocity(asts);\n  console.log(compile.render());\n});\n```\n\n两者的区别在于asts的获取，第一种方式，直接取asts，第二种，需要首先执行语法分析过\n程。\n\n##Syntax\n\n具体语法请访问官网文档：[velocity user guide](http://velocity.apache.org/engine/devel/user-guide.html)。\n\n###Directives\n\nDirectives支持`set`, `foreach`, `if|else|elseif`, `macro`, `parse`, `break`。不\n支持有，`stop`, `evaluate`, `define`，感觉这些语法比较偏，用处不大，暂时没有实现。\n其中`parse`，在web端，使用kissy的模块加载器加载，需要首先线下编译打包，[例子](http://git.shepherdwind.com/velocity.js/web/index.html)。\n\n###foreach\n\nforeach在velocity中对对象的遍历，和js有区别，java中对象是一个map，需要通过方法\n`keyset`来获取map中的key，foreach循环写法等同于js的for in循环，感觉有点怪异。在\n一个foreach，有一个`$foreach`的对象可以使用，此变量作用域为当前循环范围。\n\n```\n#foreach($num as [1..5])\n  index => $foreach.index \n  count => $foreach.count\n  #if (!$foreach.hasNext) end #end\n#end\n结果：\nindex => 0\ncount => 1\n\nindex => 1\ncount => 2\n...\nindex => 4\ncount => 5\nend\n```\n\n###string\n\nvelocity中字符串求值和php类似，双引号字符串里面的变量会被替换变量对应的值，单引\n号原样返回，推荐尽量使用单引号，那样性能好一些。此外，双引号中变量替换，没有再次\n调用语法分析器，而是使用正则，只支持简单的引用替换，比如`\"$varname1 $foo.bar\"`，\n`\"$foo.bar[1] $foo.bar()\"`都不支持。如果需要完整支持字符串双引号，需要反复调用语\n法分析器，考虑到性能，基本引用基本够用了，vm本身支持强大的变量赋值，可以先赋值，\n在放入字符串，或者使用加法进行字符串拼接。\n\n在java中可能大量使用双引号方式，因为java对象无法自动转换类型，双引号做类型转换用，\n而在web端，js无此需要。\n\n###velocity\n\n```\nUsage: velocity [options] [file ...]\n\nOptions:\n\n  -h, --help         output usage information\n  -V, --version      output the version number\n  -b, --build        build .vm file to js ast module of kissy\n\nExample:\n\n  # parse vm file\n  $ velocity a.vm \n\n  # parse vm file with json data\n  $ velocity a.vm  a.json\n\n  # build asts module of kissy\n  $ velocity *.vm\n```\n\n##Helper\n\nHelper提供一些额外的功能，都在`src/helper/`目录下，使用方式参考`test/`下对应文件，\nHelper功能还在开发中，可能不太完善。\n\n- `structure` 获取vm中所有变量的结构: `$foo.bar` => `foo: {bar: 'string'}`\n- `backstep` vm逆推，根据velocity文件和解析后的结果，计算数据结构和内容\n- `jsonify` 把vm转换为json结构，去除其中的html标签，比如：\n\n```\nhello world $foo.name.\n=>\n{foo: { name: $foo.name }}\n```\n\n##License\n\n(The MIT License)\n\nCopyright (c) 2012-2013 Eward Song<eward.song@gmail.com>\n\nPermission is hereby granted, free of charge, to any person obtaining a copy of\nthis software and associated documentation files (the 'Software'), to deal in\nthe Software without restriction, including without limitation the rights to\nuse, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of\nthe Software, and to permit persons to whom the Software is furnished to do so,\nsubject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS\nFOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR\nCOPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER\nIN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN\nCONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n","_id":"velocity.js@0.1.2","dist":{"shasum":"93e744cbd1face9d77588c2825dcc79d90b9df34","tarball":"https://registry.npmjs.org/velocity.js/-/velocity.js-0.1.2.tgz","integrity":"sha512-sXnfl9BgqCuGA4Jk+k3TVUpPp6LW4WV6IRc3Gpu56JfD3ackS7MMQ39v6qu47snvC4NVfDgbvhZDE7V6vM/LOA==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQDAZdNEDYbIWBuZvX+M5X1ZmGoPoRJe3xz6S8C9gIA8IwIhAKf6b8usTVEBgj5k+2pY95RdRpkcJ+gl5HTFTxVROYT7"}]},"_npmVersion":"1.1.62","_npmUser":{"name":"shepherdwind","email":"eward.song@gmail.com"},"maintainers":[{"name":"shepherdwind","email":"eward.song@gmail.com"}],"directories":{}},"0.1.3":{"name":"velocity.js","description":"Velocity Template Language(VTL) for JavaScript","version":"0.1.3","keywords":["velocity template"],"repository":{"type":"git","url":"git://github.com/shepherdwind/velocity.js.git"},"engines":{"node":">=0.8.0"},"main":"src/velocity.js","bin":{"velocity":"bin/velocity"},"readme":"##Velocity - Template Engine\n\nvelocity.js是velocity模板语法的javascript实现。\n[Velocity](http://velocity.apache.org/) 是基于Java的模板引擎，广泛应用在阿里集\n体各个子公司。Velocity模板适用于大量模板使用的场景，支持复杂的逻辑运算，包含\n基本数据类型、变量赋值和函数等功能。\n\n\n##Features\n\n- 支持客户端和服务器端使用\n- 语法是富逻辑的，构成门微型的语言\n- 语法分析和模板渲染分离\n- 基本完全支持velocity语法\n- 浏览器使用支持模板之间相互引用，依据js模块加载机制，比如kissy\n- 三个Helper，友好的数据模拟解决方案\n- [Vim Syntax](https://github.com/shepherdwind/vim-velocity)\n\n##Install\n\nvia npm:\n\n```bash\n$ npm install velocity.js\n```\n\n##Broswer Support\n\n点击[此处](http://git.shepherdwind.com/velocity.js/try/index.html)可以体验web\n端velocity语法解析过程，注：使用ACE作为代码编辑器，仅支持高级浏览器访问。\n\n执行`cake`命令进行打包velocity.js浏览器端脚本:\n\n```bash\n$ cake --build\n```\n\n需要cli下安装coffeejs，暂时打包是为kissy所使用的，velocity.js需要的一些常用的\necma5功能，比如`foreach, some, isArray`等，在node环境下是自带的功能，而web端的兼\n容是交给已有的类库解决。需要自行提供一组跨浏览器的api，比如kissy打包：\n\n```js\n  //api map\n  var utils = {\n    forEach : S.each,\n    some    : S.some,\n    mixin   : S.mix,\n    guid    : S.guid,\n    isArray : S.isArray,\n    indexOf : S.indexOf,\n    keys    : S.keys,\n    now     : S.now\n  };\n\n```\n\nVelocity语法具有很高的容错能力，类似于html结构的解析，同时语法规则复杂，所以语法\n解释器执行性能可能比较慢，`velocity.js`把语法结构分析运算和语法执行两个过程独立出来，\n第一步，语法结构分析返回一个数组(语法树)，描述velocity语法，语法执行使用数据和语\n法树，计算模板最终结果。\n\n执行build后，得到两个文件，分别是`build/velocity/`下的`index.js`和`parse.js`，两者\n相互独立，`parse.js`语法分析过程可以放在本地完成，执行命令：\n\n把语法分析和模板拼接分开，为了方便在本地编译语法树，减少在web端js运算。本地编译\n模板的思路，源自KISSY的[xtemplate](http://docs.kissyui.com/docs/html/api/component/xtemplate/)。\n\n虽然语法解释器可以在浏览器端执行，但是，不推荐那么使用。\n\n```bash\n#使用velocity命令行工具打包\nveloctiy --build *.vm\nveloctiy -b *.vm\n```\n\n源码中`test/web/`目录的js，一部分就是线下编译后的得到的，此处可[直接访问](http://git.shepherdwind.com/velocity.js/web/index.html)。\n\n##Public API\n\n###node_module\n\n```js\nvar Velocity = require('../src/velocity');\n\n//1. 直接解析\nVelocity.render('string of velocity', context);\n\n//2. 使用Parser和Compile\nvar Parser = Velocity.Parser;\nvar Compile = Velocity.Compile;\n\nvar asts = Parser.parse('string of velocity');\n(new Compile(asts)).render(context);\n```\n####context\n\n`context`是一个对象，可以为空，执行中`$foo.bar`，访问路径是`context.foo.bar`，\n`context`的属性可以是函数，和vm中定义保持一致。\n\n###On Broswer\n\n1 . 使用线下打包方案：\n\n```js\nKISSY.use('velocity/index, web/directives', function(S, Velocity, asts){\n  var compile = new Velocity(asts);\n  S.all('body').html(compile.render());\n});\n```\n\n2 . 使用线上编译：\n\n```js\nKISSY.use('velocity/index, velocity/parse', function(S, Velocity, Parser){\n  var html = (S.all('#tpl').html());\n  var asts = Parser.parse(html);\n  var compile = new Velocity(asts);\n  console.log(compile.render());\n});\n```\n\n两者的区别在于asts的获取，第一种方式，直接取asts，第二种，需要首先执行语法分析过\n程。\n\n##Syntax\n\n具体语法请访问官网文档：[velocity user guide](http://velocity.apache.org/engine/devel/user-guide.html)。\n\n###Directives\n\nDirectives支持`set`, `foreach`, `if|else|elseif`, `macro`, `parse`, `break`。不\n支持有，`stop`, `evaluate`, `define`，感觉这些语法比较偏，用处不大，暂时没有实现。\n其中`parse`，在web端，使用kissy的模块加载器加载，需要首先线下编译打包，[例子](http://git.shepherdwind.com/velocity.js/web/index.html)。\n\n###foreach\n\nforeach在velocity中对对象的遍历，和js有区别，java中对象是一个map，需要通过方法\n`keyset`来获取map中的key，foreach循环写法等同于js的for in循环，感觉有点怪异。在\n一个foreach，有一个`$foreach`的对象可以使用，此变量作用域为当前循环范围。\n\n```\n#foreach($num as [1..5])\n  index => $foreach.index \n  count => $foreach.count\n  #if (!$foreach.hasNext) end #end\n#end\n结果：\nindex => 0\ncount => 1\n\nindex => 1\ncount => 2\n...\nindex => 4\ncount => 5\nend\n```\n\n###string\n\nvelocity中字符串求值和php类似，双引号字符串里面的变量会被替换变量对应的值，单引\n号原样返回，推荐尽量使用单引号，那样性能好一些。此外，双引号中变量替换，没有再次\n调用语法分析器，而是使用正则，只支持简单的引用替换，比如`\"$varname1 $foo.bar\"`，\n`\"$foo.bar[1] $foo.bar()\"`都不支持。如果需要完整支持字符串双引号，需要反复调用语\n法分析器，考虑到性能，基本引用基本够用了，vm本身支持强大的变量赋值，可以先赋值，\n在放入字符串，或者使用加法进行字符串拼接。\n\n在java中可能大量使用双引号方式，因为java对象无法自动转换类型，双引号做类型转换用，\n而在web端，js无此需要。\n\n###velocity\n\n```\nUsage: velocity [options] [file ...]\n\nOptions:\n\n  -h, --help         output usage information\n  -V, --version      output the version number\n  -b, --build        build .vm file to js ast module of kissy\n\nExample:\n\n  # parse vm file\n  $ velocity a.vm \n\n  # parse vm file with json data\n  $ velocity a.vm  a.json\n\n  # build asts module of kissy\n  $ velocity *.vm\n```\n\n##Helper\n\nHelper提供一些额外的功能，都在`src/helper/`目录下，使用方式参考`test/`下对应文件，\nHelper功能还在开发中，可能不太完善。\n\n- `structure` 获取vm中所有变量的结构: `$foo.bar` => `foo: {bar: 'string'}`\n- `backstep` vm逆推，根据velocity文件和解析后的结果，计算数据结构和内容\n- `jsonify` 把vm转换为json结构，去除其中的html标签，比如：\n\n```\nhello world $foo.name.\n=>\n{foo: { name: $foo.name }}\n```\n\n##License\n\n(The MIT License)\n\nCopyright (c) 2012-2013 Eward Song<eward.song@gmail.com>\n\nPermission is hereby granted, free of charge, to any person obtaining a copy of\nthis software and associated documentation files (the 'Software'), to deal in\nthe Software without restriction, including without limitation the rights to\nuse, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of\nthe Software, and to permit persons to whom the Software is furnished to do so,\nsubject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS\nFOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR\nCOPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER\nIN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN\nCONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n","_id":"velocity.js@0.1.3","dist":{"shasum":"3ceb66acabf544a2bc735f2f277d52237ac2d9cc","tarball":"https://registry.npmjs.org/velocity.js/-/velocity.js-0.1.3.tgz","integrity":"sha512-a7wIrmyIO7bTPBTWezsfF12b+siqfenkaZSmcQmXAHdy8Drs9COD/WTVJa09fpvYZKGaWurhx6JcBdXV7+OR+Q==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQCAK1/ztZsSutidcZ7i1WRueGEYvE0VRD+2QJmvwQGBpwIhAOmqCV4Wq0ZbVtsbfXrIYM+myyvVJu6CN/VyEX8rKh3v"}]},"_npmVersion":"1.1.62","_npmUser":{"name":"shepherdwind","email":"eward.song@gmail.com"},"maintainers":[{"name":"shepherdwind","email":"eward.song@gmail.com"}],"directories":{}},"0.1.4":{"name":"velocity.js","description":"Velocity Template Language(VTL) for JavaScript","version":"0.1.4","keywords":["velocity template"],"repository":{"type":"git","url":"git://github.com/shepherdwind/velocity.js.git"},"engines":{"node":">=0.8.0"},"main":"src/velocity.js","bin":{"velocity":"bin/velocity"},"readme":"##Velocity - Template Engine\n\nvelocity.js是velocity模板语法的javascript实现。\n[Velocity](http://velocity.apache.org/) 是基于Java的模板引擎，广泛应用在阿里集\n体各个子公司。Velocity模板适用于大量模板使用的场景，支持复杂的逻辑运算，包含\n基本数据类型、变量赋值和函数等功能。\n\n\n##Features\n\n- 支持客户端和服务器端使用\n- 语法是富逻辑的，构成门微型的语言\n- 语法分析和模板渲染分离\n- 基本完全支持velocity语法\n- 浏览器使用支持模板之间相互引用，依据js模块加载机制，比如kissy\n- 三个Helper，友好的数据模拟解决方案\n- [Vim Syntax](https://github.com/shepherdwind/vim-velocity)\n\n##Install\n\nvia npm:\n\n```bash\n$ npm install velocity.js\n```\n\n##Broswer Support\n\n点击[此处](http://git.shepherdwind.com/velocity.js/try/index.html)可以体验web\n端velocity语法解析过程，注：使用ACE作为代码编辑器，仅支持高级浏览器访问。\n\n执行`cake`命令进行打包velocity.js浏览器端脚本:\n\n```bash\n$ cake --build\n```\n\n需要cli下安装coffeejs，暂时打包是为kissy所使用的，velocity.js需要的一些常用的\necma5功能，比如`foreach, some, isArray`等，在node环境下是自带的功能，而web端的兼\n容是交给已有的类库解决。需要自行提供一组跨浏览器的api，比如kissy打包：\n\n```js\n  //api map\n  var utils = {\n    forEach : S.each,\n    some    : S.some,\n    mixin   : S.mix,\n    guid    : S.guid,\n    isArray : S.isArray,\n    indexOf : S.indexOf,\n    keys    : S.keys,\n    now     : S.now\n  };\n\n```\n\nVelocity语法具有很高的容错能力，类似于html结构的解析，同时语法规则复杂，所以语法\n解释器执行性能可能比较慢，`velocity.js`把语法结构分析运算和语法执行两个过程独立出来，\n第一步，语法结构分析返回一个数组(语法树)，描述velocity语法，语法执行使用数据和语\n法树，计算模板最终结果。\n\n执行build后，得到两个文件，分别是`build/velocity/`下的`index.js`和`parse.js`，两者\n相互独立，`parse.js`语法分析过程可以放在本地完成，执行命令：\n\n把语法分析和模板拼接分开，为了方便在本地编译语法树，减少在web端js运算。本地编译\n模板的思路，源自KISSY的[xtemplate](http://docs.kissyui.com/docs/html/api/component/xtemplate/)。\n\n虽然语法解释器可以在浏览器端执行，但是，不推荐那么使用。\n\n```bash\n#使用velocity命令行工具打包\nveloctiy --build *.vm\nveloctiy -b *.vm\n```\n\n源码中`test/web/`目录的js，一部分就是线下编译后的得到的，此处可[直接访问](http://git.shepherdwind.com/velocity.js/web/index.html)。\n\n##Public API\n\n###node_module\n\n```js\nvar Velocity = require('../src/velocity');\n\n//1. 直接解析\nVelocity.render('string of velocity', context);\n\n//2. 使用Parser和Compile\nvar Parser = Velocity.Parser;\nvar Compile = Velocity.Compile;\n\nvar asts = Parser.parse('string of velocity');\n(new Compile(asts)).render(context);\n```\n####context\n\n`context`是一个对象，可以为空，执行中`$foo.bar`，访问路径是`context.foo.bar`，\n`context`的属性可以是函数，和vm中定义保持一致。\n\n###On Broswer\n\n1 . 使用线下打包方案：\n\n```js\nKISSY.use('velocity/index, web/directives', function(S, Velocity, asts){\n  var compile = new Velocity(asts);\n  S.all('body').html(compile.render());\n});\n```\n\n2 . 使用线上编译：\n\n```js\nKISSY.use('velocity/index, velocity/parse', function(S, Velocity, Parser){\n  var html = (S.all('#tpl').html());\n  var asts = Parser.parse(html);\n  var compile = new Velocity(asts);\n  console.log(compile.render());\n});\n```\n\n两者的区别在于asts的获取，第一种方式，直接取asts，第二种，需要首先执行语法分析过\n程。\n\n##Syntax\n\n具体语法请访问官网文档：[velocity user guide](http://velocity.apache.org/engine/devel/user-guide.html)。\n\n###Directives\n\nDirectives支持`set`, `foreach`, `if|else|elseif`, `macro`, `parse`, `break`。不\n支持有，`stop`, `evaluate`, `define`，感觉这些语法比较偏，用处不大，暂时没有实现。\n其中`parse`，在web端，使用kissy的模块加载器加载，需要首先线下编译打包，[例子](http://git.shepherdwind.com/velocity.js/web/index.html)。\n\n###foreach\n\nforeach在velocity中对对象的遍历，和js有区别，java中对象是一个map，需要通过方法\n`keyset`来获取map中的key，foreach循环写法等同于js的for in循环，感觉有点怪异。在\n一个foreach，有一个`$foreach`的对象可以使用，此变量作用域为当前循环范围。\n\n```\n#foreach($num as [1..5])\n  index => $foreach.index \n  count => $foreach.count\n  #if (!$foreach.hasNext) end #end\n#end\n结果：\nindex => 0\ncount => 1\n\nindex => 1\ncount => 2\n...\nindex => 4\ncount => 5\nend\n```\n\n###string\n\nvelocity中字符串求值和php类似，双引号字符串里面的变量会被替换变量对应的值，单引\n号原样返回，推荐尽量使用单引号，那样性能好一些。此外，双引号中变量替换，没有再次\n调用语法分析器，而是使用正则，只支持简单的引用替换，比如`\"$varname1 $foo.bar\"`，\n`\"$foo.bar[1] $foo.bar()\"`都不支持。如果需要完整支持字符串双引号，需要反复调用语\n法分析器，考虑到性能，基本引用基本够用了，vm本身支持强大的变量赋值，可以先赋值，\n在放入字符串，或者使用加法进行字符串拼接。\n\n在java中可能大量使用双引号方式，因为java对象无法自动转换类型，双引号做类型转换用，\n而在web端，js无此需要。\n\n###velocity\n\n```\nUsage: velocity [options] [file ...]\n\nOptions:\n\n  -h, --help         output usage information\n  -V, --version      output the version number\n  -b, --build        build .vm file to js ast module of kissy\n\nExample:\n\n  # parse vm file\n  $ velocity a.vm \n\n  # parse vm file with json data\n  $ velocity a.vm  a.json\n\n  # build asts module of kissy\n  $ velocity *.vm\n```\n\n##Helper\n\nHelper提供一些额外的功能，都在`src/helper/`目录下，使用方式参考`test/`下对应文件，\nHelper功能还在开发中，可能不太完善。\n\n- `structure` 获取vm中所有变量的结构: `$foo.bar` => `foo: {bar: 'string'}`\n- `backstep` vm逆推，根据velocity文件和解析后的结果，计算数据结构和内容\n- `jsonify` 把vm转换为json结构，去除其中的html标签，比如：\n\n```\nhello world $foo.name.\n=>\n{foo: { name: $foo.name }}\n```\n\n##License\n\n(The MIT License)\n\nCopyright (c) 2012-2013 Eward Song<eward.song@gmail.com>\n\nPermission is hereby granted, free of charge, to any person obtaining a copy of\nthis software and associated documentation files (the 'Software'), to deal in\nthe Software without restriction, including without limitation the rights to\nuse, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of\nthe Software, and to permit persons to whom the Software is furnished to do so,\nsubject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS\nFOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR\nCOPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER\nIN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN\nCONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n","_id":"velocity.js@0.1.4","dist":{"shasum":"6c8664afb930d9bd4f7960018f5ee35da5427d17","tarball":"https://registry.npmjs.org/velocity.js/-/velocity.js-0.1.4.tgz","integrity":"sha512-WFzUgDi8hTHTg50U6bpUJi7s5VD90t4gmAXjCwvbUsKJlpdeycpWqqhGcAQMbv3bEH3JgXSa9EHJJM0aW5JKLA==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQDR3e/WfjX/A0ERShvuDiE79qYMX1FzPZA3yMudMfpKNQIgIkD6wsTMqbUQKaUhMGxCiu3qb6aa1NlEe9lK93Qqr1I="}]},"_npmVersion":"1.1.62","_npmUser":{"name":"shepherdwind","email":"eward.song@gmail.com"},"maintainers":[{"name":"shepherdwind","email":"eward.song@gmail.com"}],"directories":{}},"0.2.0":{"name":"velocity.js","description":"Velocity Template Language(VTL) for JavaScript","version":"0.2.0","keywords":["velocity template"],"homepage":"http://git.shepherdwind.com/velocity.js/","repository":{"type":"git","url":"git://github.com/shepherdwind/velocity.js.git"},"engines":{"node":">=0.8.0"},"main":"src/velocity.js","bin":{"velocity":"bin/velocity"},"scripts":{"test":"make test"},"readme":"##Velocity - Template Engine\n\nvelocity.js是velocity模板语法的javascript实现。\n[Velocity](http://velocity.apache.org/) 是基于Java的模板引擎，广泛应用在阿里集\n体各个子公司。Velocity模板适用于大量模板使用的场景，支持复杂的逻辑运算，包含\n基本数据类型、变量赋值和函数等功能。\n\n\n##Features\n\n- 支持客户端和服务器端使用\n- 语法是富逻辑的，构成门微型的语言\n- 语法分析和模板渲染分离\n- 基本完全支持velocity语法\n- 浏览器使用支持模板之间相互引用，依据js模块加载机制，比如kissy\n- 三个Helper，友好的数据模拟解决方案\n- [Vim Syntax](https://github.com/shepherdwind/vim-velocity)\n\n##Install\n\nvia npm:\n\n```bash\n$ npm install velocity.js\n```\n\n##Broswer Support\n\n点击[此处](http://git.shepherdwind.com/velocity.js/try/index.html)可以体验web\n端velocity语法解析过程，注：使用ACE作为代码编辑器，仅支持高级浏览器访问。\n\n执行`cake`命令进行打包velocity.js浏览器端脚本:\n\n```bash\n$ cake --build\n```\n\n需要cli下安装coffeejs，暂时打包是为kissy所使用的，velocity.js需要的一些常用的\necma5功能，比如`foreach, some, isArray`等，在node环境下是自带的功能，而web端的兼\n容是交给已有的类库解决。需要自行提供一组跨浏览器的api，比如kissy打包：\n\n```js\n  //api map\n  var utils = {\n    forEach : S.each,\n    some    : S.some,\n    mixin   : S.mix,\n    guid    : S.guid,\n    isArray : S.isArray,\n    indexOf : S.indexOf,\n    keys    : S.keys,\n    now     : S.now\n  };\n\n```\n\nVelocity语法具有很高的容错能力，类似于html结构的解析，同时语法规则复杂，所以语法\n解释器执行性能可能比较慢，`velocity.js`把语法结构分析运算和语法执行两个过程独立出来，\n第一步，语法结构分析返回一个数组(语法树)，描述velocity语法，语法执行使用数据和语\n法树，计算模板最终结果。\n\n执行build后，得到两个文件，分别是`build/velocity/`下的`index.js`和`parse.js`，两者\n相互独立，`parse.js`语法分析过程可以放在本地完成，执行命令：\n\n把语法分析和模板拼接分开，为了方便在本地编译语法树，减少在web端js运算。本地编译\n模板的思路，源自KISSY的[xtemplate](http://docs.kissyui.com/docs/html/api/component/xtemplate/)。\n\n虽然语法解释器可以在浏览器端执行，但是，不推荐那么使用。\n\n```bash\n#使用velocity命令行工具打包\nveloctiy --build *.vm\nveloctiy -b *.vm\n```\n\n源码中`test/web/`目录的js，一部分就是线下编译后的得到的，此处可[直接访问](http://git.shepherdwind.com/velocity.js/web/index.html)。\n\n##Public API\n\n###node_module\n\n```js\nvar Velocity = require('../src/velocity');\n\n//1. 直接解析\nVelocity.render('string of velocity', context);\n\n//2. 使用Parser和Compile\nvar Parser = Velocity.Parser;\nvar Compile = Velocity.Compile;\n\nvar asts = Parser.parse('string of velocity');\n(new Compile(asts)).render(context);\n```\n####context\n\n`context`是一个对象，可以为空，执行中`$foo.bar`，访问路径是`context.foo.bar`，\n`context`的属性可以是函数，和vm中定义保持一致。\n\n###On Broswer\n\n1 . 使用线下打包方案：\n\n```js\nKISSY.use('velocity/index, web/directives', function(S, Velocity, asts){\n  var compile = new Velocity(asts);\n  S.all('body').html(compile.render());\n});\n```\n\n2 . 使用线上编译：\n\n```js\nKISSY.use('velocity/index, velocity/parse', function(S, Velocity, Parser){\n  var html = (S.all('#tpl').html());\n  var asts = Parser.parse(html);\n  var compile = new Velocity(asts);\n  console.log(compile.render());\n});\n```\n\n两者的区别在于asts的获取，第一种方式，直接取asts，第二种，需要首先执行语法分析过\n程。\n\n##Syntax\n\n具体语法请访问官网文档：[velocity user guide](http://velocity.apache.org/engine/devel/user-guide.html)。\n\n###Directives\n\nDirectives支持`set`, `foreach`, `if|else|elseif`, `macro`, `parse`, `break`。不\n支持有，`stop`, `evaluate`, `define`，感觉这些语法比较偏，用处不大，暂时没有实现。\n其中`parse`，在web端，使用kissy的模块加载器加载，需要首先线下编译打包，[例子](http://git.shepherdwind.com/velocity.js/web/index.html)。\n\n###foreach\n\nforeach在velocity中对对象的遍历，和js有区别，java中对象是一个map，需要通过方法\n`keyset`来获取map中的key，foreach循环写法等同于js的for in循环，感觉有点怪异。在\n一个foreach，有一个`$foreach`的对象可以使用，此变量作用域为当前循环范围。\n\n```\n#foreach($num as [1..5])\n  index => $foreach.index \n  count => $foreach.count\n  #if (!$foreach.hasNext) end #end\n#end\n结果：\nindex => 0\ncount => 1\n\nindex => 1\ncount => 2\n...\nindex => 4\ncount => 5\nend\n```\n\n###string\n\nvelocity中字符串求值和php类似，双引号字符串里面的变量会被替换变量对应的值，单引\n号原样返回，推荐尽量使用单引号，那样性能好一些。此外，双引号中变量替换，没有再次\n调用语法分析器，而是使用正则，只支持简单的引用替换，比如`\"$varname1 $foo.bar\"`，\n`\"$foo.bar[1] $foo.bar()\"`都不支持。如果需要完整支持字符串双引号，需要反复调用语\n法分析器，考虑到性能，基本引用基本够用了，vm本身支持强大的变量赋值，可以先赋值，\n在放入字符串，或者使用加法进行字符串拼接。\n\n在java中可能大量使用双引号方式，因为java对象无法自动转换类型，双引号做类型转换用，\n而在web端，js无此需要。\n\n###velocity\n\n```\nUsage: velocity [options] [file ...]\n\nOptions:\n\n  -h, --help         output usage information\n  -V, --version      output the version number\n  -b, --build        build .vm file to js ast module of kissy\n\nExample:\n\n  # parse vm file\n  $ velocity a.vm \n\n  # parse vm file with json data\n  $ velocity a.vm  a.json\n\n  # build asts module of kissy\n  $ velocity *.vm\n```\n\n##Helper\n\nHelper提供一些额外的功能，都在`src/helper/`目录下，使用方式参考`test/`下对应文件，\nHelper功能还在开发中，可能不太完善。\n\n- `structure` 获取vm中所有变量的结构: `$foo.bar` => `foo: {bar: 'string'}`\n- `backstep` vm逆推，根据velocity文件和解析后的结果，计算数据结构和内容\n- `jsonify` 把vm转换为json结构，去除其中的html标签，比如：\n\n```\nhello world $foo.name.\n=>\n{foo: { name: $foo.name }}\n```\n\n##License\n\n(The MIT License)\n\nCopyright (c) 2012-2013 Eward Song<eward.song@gmail.com>\n\nPermission is hereby granted, free of charge, to any person obtaining a copy of\nthis software and associated documentation files (the 'Software'), to deal in\nthe Software without restriction, including without limitation the rights to\nuse, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of\nthe Software, and to permit persons to whom the Software is furnished to do so,\nsubject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS\nFOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR\nCOPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER\nIN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN\nCONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n","_id":"velocity.js@0.2.0","dist":{"shasum":"9b4e8d0a57aeb3280ae4bc58bf8c1441e4671bde","tarball":"https://registry.npmjs.org/velocity.js/-/velocity.js-0.2.0.tgz","integrity":"sha512-+e/C8RpW1wnoULmmG+6ya6WpvZoEm0bSRnSiVHoYtq3BdFjpCsFxYRZMFoMVfMehn5/d/U5QXzW4jPDy6OpQ9w==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQDnKnMt3qmPdXavErwWOWu8PPIAkRuePs9KAXKO1wl+YgIgTiAw4pYMLfgAqR7f/0NnFhUpGHt1czmsQaVBra/KyrM="}]},"_npmVersion":"1.1.62","_npmUser":{"name":"shepherdwind","email":"eward.song@gmail.com"},"maintainers":[{"name":"shepherdwind","email":"eward.song@gmail.com"}],"directories":{}},"0.2.1":{"name":"velocity.js","description":"Velocity Template Language(VTL) for JavaScript","version":"0.2.1","keywords":["velocity template"],"homepage":"http://git.shepherdwind.com/velocity.js/","repository":{"type":"git","url":"git://github.com/shepherdwind/velocity.js.git"},"engines":{"node":">=0.8.0"},"main":"src/velocity.js","bin":{"velocity":"bin/velocity"},"scripts":{"test":"make test"},"readme":"##Velocity - Template Engine\n\n[![Build Status](https://secure.travis-ci.org/shepherdwind/velocity.js.png)](https://travis-ci.org/shepherdwind/velocity.js)\n\nvelocity.js是velocity模板语法的javascript实现。\n[Velocity](http://velocity.apache.org/) 是基于Java的模板引擎，广泛应用在阿里集\n体各个子公司。Velocity模板适用于大量模板使用的场景，支持复杂的逻辑运算，包含\n基本数据类型、变量赋值和函数等功能。\n\n\n##Features\n\n- 支持客户端和服务器端使用\n- 语法是富逻辑的，构成门微型的语言\n- 语法分析和模板渲染分离\n- 基本完全支持velocity语法\n- 浏览器使用支持模板之间相互引用，依据js模块加载机制，比如kissy\n- 三个Helper，友好的数据模拟解决方案\n- [Vim Syntax](https://github.com/shepherdwind/vim-velocity)\n\n##Install\n\nvia npm:\n\n```bash\n$ npm install velocity.js\n```\n\n##Broswer Support\n\n兼容ie6+，chrome等其他浏览器，[test case](http://git.shepherdwind.com/velocity.js/runner/tests.html)\n\n点击[此处](http://git.shepherdwind.com/velocity.js/try/index.html)可以体验web\n端velocity语法解析过程，注：使用ACE作为代码编辑器，仅支持高级浏览器访问。\n\n执行`cake`命令进行打包velocity.js浏览器端脚本:\n\n```bash\n$ cake --build\n```\n\n需要cli下安装coffeejs，暂时打包是为kissy所使用的，velocity.js需要的一些常用的\necma5功能，比如`foreach, some, isArray`等，在node环境下是自带的功能，而web端的兼\n容是交给已有的类库解决。需要自行提供一组跨浏览器的api，比如kissy打包：\n\n```js\n  //api map\n  var utils = {\n    forEach : S.each,\n    some    : S.some,\n    mixin   : S.mix,\n    guid    : S.guid,\n    isArray : S.isArray,\n    indexOf : S.indexOf,\n    keys    : S.keys,\n    now     : S.now\n  };\n\n```\n\nVelocity语法具有很高的容错能力，类似于html结构的解析，同时语法规则复杂，所以语法\n解释器执行性能可能比较慢，`velocity.js`把语法结构分析运算和语法执行两个过程独立出来，\n第一步，语法结构分析返回一个数组(语法树)，描述velocity语法，语法执行使用数据和语\n法树，计算模板最终结果。\n\n执行build后，得到两个文件，分别是`build/velocity/`下的`index.js`和`parse.js`，两者\n相互独立，`parse.js`语法分析过程可以放在本地完成，执行命令：\n\n把语法分析和模板拼接分开，为了方便在本地编译语法树，减少在web端js运算。本地编译\n模板的思路，源自KISSY的[xtemplate](http://docs.kissyui.com/docs/html/api/component/xtemplate/)。\n\n虽然语法解释器可以在浏览器端执行，但是，不推荐那么使用。\n\n```bash\n#使用velocity命令行工具打包\nveloctiy --build *.vm\nveloctiy -b *.vm\n```\n\n源码中`test/web/`目录的js，一部分就是线下编译后的得到的，此处可[直接访问](http://git.shepherdwind.com/velocity.js/web/index.html)。\n\n##Public API\n\n###node_module\n\n```js\nvar Velocity = require('../src/velocity');\n\n//1. 直接解析\nVelocity.render('string of velocity', context);\n\n//2. 使用Parser和Compile\nvar Parser = Velocity.Parser;\nvar Compile = Velocity.Compile;\n\nvar asts = Parser.parse('string of velocity');\n(new Compile(asts)).render(context);\n```\n####context\n\n`context`是一个对象，可以为空，执行中`$foo.bar`，访问路径是`context.foo.bar`，\n`context`的属性可以是函数，和vm中定义保持一致。\n\n###On Broswer\n\n1 . 使用线下打包方案：\n\n```js\nKISSY.use('velocity/index, web/directives', function(S, Velocity, asts){\n  var compile = new Velocity(asts);\n  S.all('body').html(compile.render());\n});\n```\n\n2 . 使用线上编译：\n\n```js\nKISSY.use('velocity/index, velocity/parse', function(S, Velocity, Parser){\n  var html = (S.all('#tpl').html());\n  var asts = Parser.parse(html);\n  var compile = new Velocity(asts);\n  console.log(compile.render());\n});\n```\n\n两者的区别在于asts的获取，第一种方式，直接取asts，第二种，需要首先执行语法分析过\n程。\n\n##Syntax\n\n具体语法请访问官网文档：[velocity user guide](http://velocity.apache.org/engine/devel/user-guide.html)。\n\n###Directives\n\nDirectives支持`set`, `foreach`, `if|else|elseif`, `macro`, `parse`, `break`。不\n支持有，`stop`, `evaluate`, `define`，感觉这些语法比较偏，用处不大，暂时没有实现。\n其中`parse`，在web端，使用kissy的模块加载器加载，需要首先线下编译打包，[例子](http://git.shepherdwind.com/velocity.js/web/index.html)。\n\n###foreach\n\nforeach在velocity中对对象的遍历，和js有区别，java中对象是一个map，需要通过方法\n`keyset`来获取map中的key，foreach循环写法等同于js的for in循环，感觉有点怪异。在\n一个foreach，有一个`$foreach`的对象可以使用，此变量作用域为当前循环范围。\n\n```\n#foreach($num as [1..5])\n  index => $foreach.index \n  count => $foreach.count\n  #if (!$foreach.hasNext) end #end\n#end\n结果：\nindex => 0\ncount => 1\n\nindex => 1\ncount => 2\n...\nindex => 4\ncount => 5\nend\n```\n\n###string\n\nvelocity中字符串求值和php类似，双引号字符串里面的变量会被替换变量对应的值，单引\n号原样返回，推荐尽量使用单引号，那样性能好一些。此外，双引号中变量替换，没有再次\n调用语法分析器，而是使用正则，只支持简单的引用替换，比如`\"$varname1 $foo.bar\"`，\n`\"$foo.bar[1] $foo.bar()\"`都不支持。如果需要完整支持字符串双引号，需要反复调用语\n法分析器，考虑到性能，基本引用基本够用了，vm本身支持强大的变量赋值，可以先赋值，\n在放入字符串，或者使用加法进行字符串拼接。\n\n在java中可能大量使用双引号方式，因为java对象无法自动转换类型，双引号做类型转换用，\n而在web端，js无此需要。\n\n###velocity\n\n```\nUsage: velocity [options] [file ...]\n\nOptions:\n\n  -h, --help         output usage information\n  -V, --version      output the version number\n  -b, --build        build .vm file to js ast module of kissy\n\nExample:\n\n  # parse vm file\n  $ velocity a.vm \n\n  # parse vm file with json data\n  $ velocity a.vm  a.json\n\n  # build asts module of kissy\n  $ velocity *.vm\n```\n\n##Helper\n\nHelper提供一些额外的功能，都在`src/helper/`目录下，使用方式参考`test/`下对应文件，\nHelper功能还在开发中，可能不太完善。\n\n- `structure` 获取vm中所有变量的结构: `$foo.bar` => `foo: {bar: 'string'}`\n- `backstep` vm逆推，根据velocity文件和解析后的结果，计算数据结构和内容\n- `jsonify` 把vm转换为json结构，去除其中的html标签，比如：\n\n```\nhello world $foo.name.\n=>\n{foo: { name: $foo.name }}\n```\n\n##License\n\n(The MIT License)\n\nCopyright (c) 2012-2013 Eward Song<eward.song@gmail.com>\n\nPermission is hereby granted, free of charge, to any person obtaining a copy of\nthis software and associated documentation files (the 'Software'), to deal in\nthe Software without restriction, including without limitation the rights to\nuse, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of\nthe Software, and to permit persons to whom the Software is furnished to do so,\nsubject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS\nFOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR\nCOPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER\nIN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN\nCONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n","_id":"velocity.js@0.2.1","dist":{"shasum":"29b79a2fb7b2dd9f0974fb01813e09026f170930","tarball":"https://registry.npmjs.org/velocity.js/-/velocity.js-0.2.1.tgz","integrity":"sha512-36UG3T4oEZnsmpGI8B05sEhcYVy746t1AyEJ5CdnJBcHh1ylk7I74U+DbpSJEDwsGp4jIICP8QhA5GFheAyC/w==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCICBvzegLbOfH6wJOHnrCmPm3oLFKIXbk/BqClw0vNqrcAiEA2i4o5nLDeLlXot1f6WRuKeID+7UR6+zYkr8DjH/x8Qw="}]},"_npmVersion":"1.1.62","_npmUser":{"name":"shepherdwind","email":"eward.song@gmail.com"},"maintainers":[{"name":"shepherdwind","email":"eward.song@gmail.com"}]},"0.2.2":{"name":"velocity.js","description":"Velocity Template Language(VTL) for JavaScript","version":"0.2.2","keywords":["velocity template"],"homepage":"http://git.shepherdwind.com/velocity.js/","repository":{"type":"git","url":"git://github.com/shepherdwind/velocity.js.git"},"engines":{"node":">=0.8.0"},"main":"src/velocity.js","bin":{"velocity":"bin/velocity"},"scripts":{"test":"make test"},"readme":"##Velocity - Template Engine\n\n[![Build Status](https://secure.travis-ci.org/shepherdwind/velocity.js.png)](https://travis-ci.org/shepherdwind/velocity.js)\n\nvelocity.js是velocity模板语法的javascript实现。\n[Velocity](http://velocity.apache.org/) 是基于Java的模板引擎，广泛应用在阿里集\n体各个子公司。Velocity模板适用于大量模板使用的场景，支持复杂的逻辑运算，包含\n基本数据类型、变量赋值和函数等功能。\n\n\n##Features\n\n- 支持客户端和服务器端使用\n- 语法是富逻辑的，构成门微型的语言\n- 语法分析和模板渲染分离\n- 基本完全支持velocity语法\n- 浏览器使用支持模板之间相互引用，依据js模块加载机制，比如kissy\n- 三个Helper，友好的数据模拟解决方案\n- [Vim Syntax](https://github.com/shepherdwind/vim-velocity)\n\n##Install\n\nvia npm:\n\n```bash\n$ npm install velocity.js\n```\n\n##Broswer Support\n\n兼容ie6+，chrome等其他浏览器，[test case](http://git.shepherdwind.com/velocity.js/runner/tests.html)\n\n点击[此处](http://git.shepherdwind.com/velocity.js/try/index.html)可以体验web\n端velocity语法解析过程，注：使用ACE作为代码编辑器，仅支持高级浏览器访问。\n\n执行`cake`命令进行打包velocity.js浏览器端脚本:\n\n```bash\n$ cake --build\n```\n\n需要cli下安装coffeejs，暂时打包是为kissy所使用的，velocity.js需要的一些常用的\necma5功能，比如`foreach, some, isArray`等，在node环境下是自带的功能，而web端的兼\n容是交给已有的类库解决。需要自行提供一组跨浏览器的api，比如kissy打包：\n\n```js\n  //api map\n  var utils = {\n    forEach : S.each,\n    some    : S.some,\n    mixin   : S.mix,\n    guid    : S.guid,\n    isArray : S.isArray,\n    indexOf : S.indexOf,\n    keys    : S.keys,\n    now     : S.now\n  };\n\n```\n\nVelocity语法具有很高的容错能力，类似于html结构的解析，同时语法规则复杂，所以语法\n解释器执行性能可能比较慢，`velocity.js`把语法结构分析运算和语法执行两个过程独立出来，\n第一步，语法结构分析返回一个数组(语法树)，描述velocity语法，语法执行使用数据和语\n法树，计算模板最终结果。\n\n执行build后，得到两个文件，分别是`build/velocity/`下的`index.js`和`parse.js`，两者\n相互独立，`parse.js`语法分析过程可以放在本地完成，执行命令：\n\n把语法分析和模板拼接分开，为了方便在本地编译语法树，减少在web端js运算。本地编译\n模板的思路，源自KISSY的[xtemplate](http://docs.kissyui.com/docs/html/api/component/xtemplate/)。\n\n虽然语法解释器可以在浏览器端执行，但是，不推荐那么使用。\n\n```bash\n#使用velocity命令行工具打包\nveloctiy --build *.vm\nveloctiy -b *.vm\n```\n\n源码中`test/web/`目录的js，一部分就是线下编译后的得到的，此处可[直接访问](http://git.shepherdwind.com/velocity.js/web/index.html)。\n\n##Public API\n\n###node_module\n\n```js\nvar Velocity = require('../src/velocity');\n\n//1. 直接解析\nVelocity.render('string of velocity', context);\n\n//2. 使用Parser和Compile\nvar Parser = Velocity.Parser;\nvar Compile = Velocity.Compile;\n\nvar asts = Parser.parse('string of velocity');\n(new Compile(asts)).render(context);\n```\n####context\n\n`context`是一个对象，可以为空，执行中`$foo.bar`，访问路径是`context.foo.bar`，\n`context`的属性可以是函数，和vm中定义保持一致。\n\n###On Broswer\n\n1 . 使用线下打包方案：\n\n```js\nKISSY.use('velocity/index, web/directives', function(S, Velocity, asts){\n  var compile = new Velocity(asts);\n  S.all('body').html(compile.render());\n});\n```\n\n2 . 使用线上编译：\n\n```js\nKISSY.use('velocity/index, velocity/parse', function(S, Velocity, Parser){\n  var html = (S.all('#tpl').html());\n  var asts = Parser.parse(html);\n  var compile = new Velocity(asts);\n  console.log(compile.render());\n});\n```\n\n两者的区别在于asts的获取，第一种方式，直接取asts，第二种，需要首先执行语法分析过\n程。\n\n##Syntax\n\n具体语法请访问官网文档：[velocity user guide](http://velocity.apache.org/engine/devel/user-guide.html)。\n\n###Directives\n\nDirectives支持`set`, `foreach`, `if|else|elseif`, `macro`, `parse`, `break`。不\n支持有，`stop`, `evaluate`, `define`，感觉这些语法比较偏，用处不大，暂时没有实现。\n其中`parse`，在web端，使用kissy的模块加载器加载，需要首先线下编译打包，[例子](http://git.shepherdwind.com/velocity.js/web/index.html)。\n\n###foreach\n\nforeach在velocity中对对象的遍历，和js有区别，java中对象是一个map，需要通过方法\n`keyset`来获取map中的key，foreach循环写法等同于js的for in循环，感觉有点怪异。在\n一个foreach，有一个`$foreach`的对象可以使用，此变量作用域为当前循环范围。\n\n```\n#foreach($num as [1..5])\n  index => $foreach.index \n  count => $foreach.count\n  #if (!$foreach.hasNext) end #end\n#end\n结果：\nindex => 0\ncount => 1\n\nindex => 1\ncount => 2\n...\nindex => 4\ncount => 5\nend\n```\n\n###string\n\nvelocity中字符串求值和php类似，双引号字符串里面的变量会被替换变量对应的值，单引\n号原样返回，推荐尽量使用单引号，那样性能好一些。此外，双引号中变量替换，没有再次\n调用语法分析器，而是使用正则，只支持简单的引用替换，比如`\"$varname1 $foo.bar\"`，\n`\"$foo.bar[1] $foo.bar()\"`都不支持。如果需要完整支持字符串双引号，需要反复调用语\n法分析器，考虑到性能，基本引用基本够用了，vm本身支持强大的变量赋值，可以先赋值，\n在放入字符串，或者使用加法进行字符串拼接。\n\n在java中可能大量使用双引号方式，因为java对象无法自动转换类型，双引号做类型转换用，\n而在web端，js无此需要。\n\n###velocity\n\n```\nUsage: velocity [options] [file ...]\n\nOptions:\n\n  -h, --help         output usage information\n  -V, --version      output the version number\n  -b, --build        build .vm file to js ast module of kissy\n\nExample:\n\n  # parse vm file\n  $ velocity a.vm \n\n  # parse vm file with json data\n  $ velocity a.vm  a.json\n\n  # build asts module of kissy\n  $ velocity *.vm\n```\n\n##Helper\n\nHelper提供一些额外的功能，都在`src/helper/`目录下，使用方式参考`test/`下对应文件，\nHelper功能还在开发中，可能不太完善。\n\n- `structure` 获取vm中所有变量的结构: `$foo.bar` => `foo: {bar: 'string'}`\n- `backstep` vm逆推，根据velocity文件和解析后的结果，计算数据结构和内容\n- `jsonify` 把vm转换为json结构，去除其中的html标签，比如：\n\n```\nhello world $foo.name.\n=>\n{foo: { name: $foo.name }}\n```\n\n##License\n\n(The MIT License)\n\nCopyright (c) 2012-2013 Eward Song<eward.song@gmail.com>\n\nPermission is hereby granted, free of charge, to any person obtaining a copy of\nthis software and associated documentation files (the 'Software'), to deal in\nthe Software without restriction, including without limitation the rights to\nuse, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of\nthe Software, and to permit persons to whom the Software is furnished to do so,\nsubject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS\nFOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR\nCOPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER\nIN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN\nCONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n","_id":"velocity.js@0.2.2","dist":{"shasum":"2493aad259c59774c2fb69b2f17017a9b2ffbe52","tarball":"https://registry.npmjs.org/velocity.js/-/velocity.js-0.2.2.tgz","integrity":"sha512-UWnsoTkq+1/DZQGg09+DF44LcuFzz6SGXeNxDZkkfxxa+YK0MukEORB6sy0fYQ0xbiYVz11p2brPjICr0cnZRg==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIFVI38p0fgtDEqhLW2263qqxKJl1gqg7y6ljhgGBBkvdAiAwYfkYOV4SDLPk0LwskXiZmjgfPi1auPiPGCXhrZIJsw=="}]},"_npmVersion":"1.1.62","_npmUser":{"name":"shepherdwind","email":"eward.song@gmail.com"},"maintainers":[{"name":"shepherdwind","email":"eward.song@gmail.com"}]},"0.2.3":{"name":"velocity.js","description":"Velocity Template Language(VTL) for JavaScript","version":"0.2.3","keywords":["velocity template"],"homepage":"http://git.shepherdwind.com/velocity.js/","repository":{"type":"git","url":"git://github.com/shepherdwind/velocity.js.git"},"engines":{"node":">=0.8.0"},"main":"src/velocity.js","bin":{"velocity":"bin/velocity"},"scripts":{"test":"make test"},"readme":"##Velocity - Template Engine\n\n[![Build Status](https://secure.travis-ci.org/shepherdwind/velocity.js.png)](https://travis-ci.org/shepherdwind/velocity.js)\n\nvelocity.js是velocity模板语法的javascript实现。\n[Velocity](http://velocity.apache.org/) 是基于Java的模板引擎，广泛应用在阿里集\n体各个子公司。Velocity模板适用于大量模板使用的场景，支持复杂的逻辑运算，包含\n基本数据类型、变量赋值和函数等功能。\n\n\n##Features\n\n- 支持客户端和服务器端使用\n- 语法是富逻辑的，构成门微型的语言\n- 语法分析和模板渲染分离\n- 基本完全支持velocity语法\n- 浏览器使用支持模板之间相互引用，依据js模块加载机制，比如kissy\n- 三个Helper，友好的数据模拟解决方案\n- [Vim Syntax](https://github.com/shepherdwind/vim-velocity)\n\n##Install\n\nvia npm:\n\n```bash\n$ npm install velocity.js\n```\n\n##Broswer Support\n\n兼容ie6+，chrome等其他浏览器，[test case](http://git.shepherdwind.com/velocity.js/runner/tests.html)\n\n点击[此处](http://git.shepherdwind.com/velocity.js/try/index.html)可以体验web\n端velocity语法解析过程，注：使用ACE作为代码编辑器，仅支持高级浏览器访问。\n\n执行`cake`命令进行打包velocity.js浏览器端脚本:\n\n```bash\n$ cake --build\n```\n\n需要cli下安装coffeejs，暂时打包是为kissy所使用的，velocity.js需要的一些常用的\necma5功能，比如`foreach, some, isArray`等，在node环境下是自带的功能，而web端的兼\n容是交给已有的类库解决。需要自行提供一组跨浏览器的api，比如kissy打包：\n\n```js\n  //api map\n  var utils = {\n    forEach : S.each,\n    some    : S.some,\n    mixin   : S.mix,\n    guid    : S.guid,\n    isArray : S.isArray,\n    indexOf : S.indexOf,\n    keys    : S.keys,\n    now     : S.now\n  };\n\n```\n\nVelocity语法具有很高的容错能力，类似于html结构的解析，同时语法规则复杂，所以语法\n解释器执行性能可能比较慢，`velocity.js`把语法结构分析运算和语法执行两个过程独立出来，\n第一步，语法结构分析返回一个数组(语法树)，描述velocity语法，语法执行使用数据和语\n法树，计算模板最终结果。\n\n执行build后，得到两个文件，分别是`build/velocity/`下的`index.js`和`parse.js`，两者\n相互独立，`parse.js`语法分析过程可以放在本地完成，执行命令：\n\n把语法分析和模板拼接分开，为了方便在本地编译语法树，减少在web端js运算。本地编译\n模板的思路，源自KISSY的[xtemplate](http://docs.kissyui.com/docs/html/api/component/xtemplate/)。\n\n虽然语法解释器可以在浏览器端执行，但是，不推荐那么使用。\n\n```bash\n#使用velocity命令行工具打包\nveloctiy --build *.vm\nveloctiy -b *.vm\n```\n\n源码中`test/web/`目录的js，一部分就是线下编译后的得到的，此处可[直接访问](http://git.shepherdwind.com/velocity.js/web/index.html)。\n\n##Public API\n\n###node_module\n\n```js\nvar Velocity = require('../src/velocity');\n\n//1. 直接解析\nVelocity.render('string of velocity', context);\n\n//2. 使用Parser和Compile\nvar Parser = Velocity.Parser;\nvar Compile = Velocity.Compile;\n\nvar asts = Parser.parse('string of velocity');\n(new Compile(asts)).render(context);\n```\n####context\n\n`context`是一个对象，可以为空，执行中`$foo.bar`，访问路径是`context.foo.bar`，\n`context`的属性可以是函数，和vm中定义保持一致。\n\n###On Broswer\n\n1 . 使用线下打包方案：\n\n```js\nKISSY.use('velocity/index, web/directives', function(S, Velocity, asts){\n  var compile = new Velocity(asts);\n  S.all('body').html(compile.render());\n});\n```\n\n2 . 使用线上编译：\n\n```js\nKISSY.use('velocity/index, velocity/parse', function(S, Velocity, Parser){\n  var html = (S.all('#tpl').html());\n  var asts = Parser.parse(html);\n  var compile = new Velocity(asts);\n  console.log(compile.render());\n});\n```\n\n两者的区别在于asts的获取，第一种方式，直接取asts，第二种，需要首先执行语法分析过\n程。\n\n##Syntax\n\n具体语法请访问官网文档：[velocity user guide](http://velocity.apache.org/engine/devel/user-guide.html)。\n\n###Directives\n\nDirectives支持`set`, `foreach`, `if|else|elseif`, `macro`, `parse`, `break`。不\n支持有，`stop`, `evaluate`, `define`，感觉这些语法比较偏，用处不大，暂时没有实现。\n其中`parse`，在web端，使用kissy的模块加载器加载，需要首先线下编译打包，[例子](http://git.shepherdwind.com/velocity.js/web/index.html)。\n\n###foreach\n\nforeach在velocity中对对象的遍历，和js有区别，java中对象是一个map，需要通过方法\n`keyset`来获取map中的key，foreach循环写法等同于js的for in循环，感觉有点怪异。在\n一个foreach，有一个`$foreach`的对象可以使用，此变量作用域为当前循环范围。\n\n```\n#foreach($num as [1..5])\n  index => $foreach.index \n  count => $foreach.count\n  #if (!$foreach.hasNext) end #end\n#end\n结果：\nindex => 0\ncount => 1\n\nindex => 1\ncount => 2\n...\nindex => 4\ncount => 5\nend\n```\n\n###string\n\nvelocity中字符串求值和php类似，双引号字符串里面的变量会被替换变量对应的值，单引\n号原样返回，推荐尽量使用单引号，那样性能好一些。此外，双引号中变量替换，没有再次\n调用语法分析器，而是使用正则，只支持简单的引用替换，比如`\"$varname1 $foo.bar\"`，\n`\"$foo.bar[1] $foo.bar()\"`都不支持。如果需要完整支持字符串双引号，需要反复调用语\n法分析器，考虑到性能，基本引用基本够用了，vm本身支持强大的变量赋值，可以先赋值，\n在放入字符串，或者使用加法进行字符串拼接。\n\n在java中可能大量使用双引号方式，因为java对象无法自动转换类型，双引号做类型转换用，\n而在web端，js无此需要。\n\n###velocity\n\n```\nUsage: velocity [options] [file ...]\n\nOptions:\n\n  -h, --help         output usage information\n  -V, --version      output the version number\n  -b, --build        build .vm file to js ast module of kissy\n\nExample:\n\n  # parse vm file\n  $ velocity a.vm \n\n  # parse vm file with json data\n  $ velocity a.vm  a.json\n\n  # build asts module of kissy\n  $ velocity *.vm\n```\n\n##Helper\n\nHelper提供一些额外的功能，都在`src/helper/`目录下，使用方式参考`test/`下对应文件，\nHelper功能还在开发中，可能不太完善。\n\n- `structure` 获取vm中所有变量的结构: `$foo.bar` => `foo: {bar: 'string'}`\n- `backstep` vm逆推，根据velocity文件和解析后的结果，计算数据结构和内容\n- `jsonify` 把vm转换为json结构，去除其中的html标签，比如：\n\n```\nhello world $foo.name.\n=>\n{foo: { name: $foo.name }}\n```\n\n##License\n\n(The MIT License)\n\nCopyright (c) 2012-2013 Eward Song<eward.song@gmail.com>\n\nPermission is hereby granted, free of charge, to any person obtaining a copy of\nthis software and associated documentation files (the 'Software'), to deal in\nthe Software without restriction, including without limitation the rights to\nuse, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of\nthe Software, and to permit persons to whom the Software is furnished to do so,\nsubject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS\nFOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR\nCOPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER\nIN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN\nCONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n","_id":"velocity.js@0.2.3","dist":{"shasum":"f040ce80e56be23fb076d944b68653ff6cdc08be","tarball":"https://registry.npmjs.org/velocity.js/-/velocity.js-0.2.3.tgz","integrity":"sha512-wv86e6T8SHBQJ808M0AIudLGFVuABHsvM5eO0sH2M1Hw9goFyjC+wziO+C1C/mzf/4Uc0loewYwgWI1GmMZtpQ==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQCIBa6uOP67PSSWZfUZVfF9nyuqmYyiLQmyW+MtTQ+wfQIgNY/KuXNzUL6vUNSWstQEYb3kHdW+x4B1rdCCV40ozpg="}]},"_npmVersion":"1.1.62","_npmUser":{"name":"shepherdwind","email":"eward.song@gmail.com"},"maintainers":[{"name":"shepherdwind","email":"eward.song@gmail.com"}]},"0.2.4":{"name":"velocity.js","description":"Velocity Template Language(VTL) for JavaScript","version":"0.2.4","keywords":["velocity template"],"homepage":"http://git.shepherdwind.com/velocity.js/","repository":{"type":"git","url":"git://github.com/shepherdwind/velocity.js.git"},"engines":{"node":">=0.8.0"},"main":"src/velocity.js","bin":{"velocity":"bin/velocity"},"scripts":{"test":"make test"},"readme":"##Velocity - Template Engine\n\n[![Build Status](https://secure.travis-ci.org/shepherdwind/velocity.js.png)](https://travis-ci.org/shepherdwind/velocity.js)\n\nvelocity.js是velocity模板语法的javascript实现。\n[Velocity](http://velocity.apache.org/) 是基于Java的模板引擎，广泛应用在阿里集\n体各个子公司。Velocity模板适用于大量模板使用的场景，支持复杂的逻辑运算，包含\n基本数据类型、变量赋值和函数等功能。\n\n\n##Features\n\n- 支持客户端和服务器端使用\n- 语法是富逻辑的，构成门微型的语言\n- 语法分析和模板渲染分离\n- 基本完全支持velocity语法\n- 浏览器使用支持模板之间相互引用，依据js模块加载机制，比如kissy\n- 三个Helper，友好的数据模拟解决方案\n- [Vim Syntax](https://github.com/shepherdwind/vim-velocity)\n\n##Install\n\nvia npm:\n\n```bash\n$ npm install velocity.js\n```\n\n##Broswer Support\n\n兼容ie6+，chrome等其他浏览器，[test case](http://git.shepherdwind.com/velocity.js/runner/tests.html)\n\n点击[此处](http://git.shepherdwind.com/velocity.js/try/index.html)可以体验web\n端velocity语法解析过程，注：使用ACE作为代码编辑器，仅支持高级浏览器访问。\n\n执行`cake`命令进行打包velocity.js浏览器端脚本:\n\n```bash\n$ cake --build\n```\n\n需要cli下安装coffeejs，暂时打包是为kissy所使用的，velocity.js需要的一些常用的\necma5功能，比如`foreach, some, isArray`等，在node环境下是自带的功能，而web端的兼\n容是交给已有的类库解决。需要自行提供一组跨浏览器的api，比如kissy打包：\n\n```js\n  //api map\n  var utils = {\n    forEach : S.each,\n    some    : S.some,\n    mixin   : S.mix,\n    guid    : S.guid,\n    isArray : S.isArray,\n    indexOf : S.indexOf,\n    keys    : S.keys,\n    now     : S.now\n  };\n\n```\n\nVelocity语法具有很高的容错能力，类似于html结构的解析，同时语法规则复杂，所以语法\n解释器执行性能可能比较慢，`velocity.js`把语法结构分析运算和语法执行两个过程独立出来，\n第一步，语法结构分析返回一个数组(语法树)，描述velocity语法，语法执行使用数据和语\n法树，计算模板最终结果。\n\n执行build后，得到两个文件，分别是`build/velocity/`下的`index.js`和`parse.js`，两者\n相互独立，`parse.js`语法分析过程可以放在本地完成，执行命令：\n\n把语法分析和模板拼接分开，为了方便在本地编译语法树，减少在web端js运算。本地编译\n模板的思路，源自KISSY的[xtemplate](http://docs.kissyui.com/docs/html/api/component/xtemplate/)。\n\n虽然语法解释器可以在浏览器端执行，但是，不推荐那么使用。\n\n```bash\n#使用velocity命令行工具打包\nveloctiy --build *.vm\nveloctiy -b *.vm\n```\n\n源码中`test/web/`目录的js，一部分就是线下编译后的得到的，此处可[直接访问](http://git.shepherdwind.com/velocity.js/web/index.html)。\n\n##Public API\n\n###node_module\n\n```js\nvar Velocity = require('../src/velocity');\n\n//1. 直接解析\nVelocity.render('string of velocity', context);\n\n//2. 使用Parser和Compile\nvar Parser = Velocity.Parser;\nvar Compile = Velocity.Compile;\n\nvar asts = Parser.parse('string of velocity');\n(new Compile(asts)).render(context);\n```\n####context\n\n`context`是一个对象，可以为空，执行中`$foo.bar`，访问路径是`context.foo.bar`，\n`context`的属性可以是函数，和vm中定义保持一致。\n\n###On Broswer\n\n1 . 使用线下打包方案：\n\n```js\nKISSY.use('velocity/index, web/directives', function(S, Velocity, asts){\n  var compile = new Velocity(asts);\n  S.all('body').html(compile.render());\n});\n```\n\n2 . 使用线上编译：\n\n```js\nKISSY.use('velocity/index, velocity/parse', function(S, Velocity, Parser){\n  var html = (S.all('#tpl').html());\n  var asts = Parser.parse(html);\n  var compile = new Velocity(asts);\n  console.log(compile.render());\n});\n```\n\n两者的区别在于asts的获取，第一种方式，直接取asts，第二种，需要首先执行语法分析过\n程。\n\n##Syntax\n\n具体语法请访问官网文档：[velocity user guide](http://velocity.apache.org/engine/devel/user-guide.html)。\n\n###Directives\n\nDirectives支持`set`, `foreach`, `if|else|elseif`, `macro`, `parse`, `break`。不\n支持有，`stop`, `evaluate`, `define`，感觉这些语法比较偏，用处不大，暂时没有实现。\n其中`parse`，在web端，使用kissy的模块加载器加载，需要首先线下编译打包，[例子](http://git.shepherdwind.com/velocity.js/web/index.html)。\n\n###foreach\n\nforeach在velocity中对对象的遍历，和js有区别，java中对象是一个map，需要通过方法\n`keyset`来获取map中的key，foreach循环写法等同于js的for in循环，感觉有点怪异。在\n一个foreach，有一个`$foreach`的对象可以使用，此变量作用域为当前循环范围。\n\n```\n#foreach($num as [1..5])\n  index => $foreach.index \n  count => $foreach.count\n  #if (!$foreach.hasNext) end #end\n#end\n结果：\nindex => 0\ncount => 1\n\nindex => 1\ncount => 2\n...\nindex => 4\ncount => 5\nend\n```\n\n###string\n\nvelocity中字符串求值和php类似，双引号字符串里面的变量会被替换变量对应的值，单引\n号原样返回，推荐尽量使用单引号，那样性能好一些。此外，双引号中变量替换，没有再次\n调用语法分析器，而是使用正则，只支持简单的引用替换，比如`\"$varname1 $foo.bar\"`，\n`\"$foo.bar[1] $foo.bar()\"`都不支持。如果需要完整支持字符串双引号，需要反复调用语\n法分析器，考虑到性能，基本引用基本够用了，vm本身支持强大的变量赋值，可以先赋值，\n在放入字符串，或者使用加法进行字符串拼接。\n\n在java中可能大量使用双引号方式，因为java对象无法自动转换类型，双引号做类型转换用，\n而在web端，js无此需要。\n\n###velocity\n\n```\nUsage: velocity [options] [file ...]\n\nOptions:\n\n  -h, --help         output usage information\n  -V, --version      output the version number\n  -b, --build        build .vm file to js ast module of kissy\n\nExample:\n\n  # parse vm file\n  $ velocity a.vm \n\n  # parse vm file with json data\n  $ velocity a.vm  a.json\n\n  # build asts module of kissy\n  $ velocity *.vm\n```\n\n##Helper\n\nHelper提供一些额外的功能，都在`src/helper/`目录下，使用方式参考`test/`下对应文件，\nHelper功能还在开发中，可能不太完善。\n\n- `structure` 获取vm中所有变量的结构: `$foo.bar` => `foo: {bar: 'string'}`\n- `backstep` vm逆推，根据velocity文件和解析后的结果，计算数据结构和内容\n- `jsonify` 把vm转换为json结构，去除其中的html标签，比如：\n\n```\nhello world $foo.name.\n=>\n{foo: { name: $foo.name }}\n```\n\n##License\n\n(The MIT License)\n\nCopyright (c) 2012-2013 Eward Song<eward.song@gmail.com>\n\nPermission is hereby granted, free of charge, to any person obtaining a copy of\nthis software and associated documentation files (the 'Software'), to deal in\nthe Software without restriction, including without limitation the rights to\nuse, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of\nthe Software, and to permit persons to whom the Software is furnished to do so,\nsubject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS\nFOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR\nCOPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER\nIN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN\nCONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n","_id":"velocity.js@0.2.4","dist":{"shasum":"95cab4435c56f2ab1df34b5577ccc20ed4c08cde","tarball":"https://registry.npmjs.org/velocity.js/-/velocity.js-0.2.4.tgz","integrity":"sha512-20kib0aXOvzhpNz9NF8lm4DXlTrVWHU6KfNNXZrVp+/leeOIBSVVqsE2wC012dJuUVb8EUO21gjtyyrQppsaOw==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIEa9RnaVGraWLVjTsYg9u4EndIosO1m7prnfwhc+7D7wAiEApS57NinWLZgpdphxPEx8Ya9Gt1i167G9oDxXjTPfKyY="}]},"_npmVersion":"1.1.62","_npmUser":{"name":"shepherdwind","email":"eward.song@gmail.com"},"maintainers":[{"name":"shepherdwind","email":"eward.song@gmail.com"}]},"0.2.5":{"name":"velocity.js","description":"Velocity Template Language(VTL) for JavaScript","version":"0.2.5","keywords":["velocity template"],"homepage":"http://git.shepherdwind.com/velocity.js/","repository":{"type":"git","url":"git://github.com/shepherdwind/velocity.js.git"},"engines":{"node":">=0.8.0"},"main":"src/velocity.js","bin":{"velocity":"bin/velocity"},"scripts":{"test":"make test"},"readme":"##Velocity - Template Engine\n\n[![Build Status](https://secure.travis-ci.org/shepherdwind/velocity.js.png)](https://travis-ci.org/shepherdwind/velocity.js)\n\nvelocity.js是velocity模板语法的javascript实现。\n[Velocity](http://velocity.apache.org/) 是基于Java的模板引擎，广泛应用在阿里集\n体各个子公司。Velocity模板适用于大量模板使用的场景，支持复杂的逻辑运算，包含\n基本数据类型、变量赋值和函数等功能。\n\n\n##Features\n\n- 支持客户端和服务器端使用\n- 语法是富逻辑的，构成门微型的语言\n- 语法分析和模板渲染分离\n- 基本完全支持velocity语法\n- 浏览器使用支持模板之间相互引用，依据js模块加载机制，比如kissy\n- 三个Helper，友好的数据模拟解决方案\n- [Vim Syntax](https://github.com/shepherdwind/vim-velocity)\n\n##Install\n\nvia npm:\n\n```bash\n$ npm install velocity.js\n```\n\n##Broswer Support\n\n兼容ie6+，chrome等其他浏览器，[test case](http://git.shepherdwind.com/velocity.js/runner/tests.html)\n\n点击[此处](http://git.shepherdwind.com/velocity.js/try/index.html)可以体验web\n端velocity语法解析过程，注：使用ACE作为代码编辑器，仅支持高级浏览器访问。\n\n执行`cake`命令进行打包velocity.js浏览器端脚本:\n\n```bash\n$ cake --build\n```\n\n需要cli下安装coffeejs，暂时打包是为kissy所使用的，velocity.js需要的一些常用的\necma5功能，比如`foreach, some, isArray`等，在node环境下是自带的功能，而web端的兼\n容是交给已有的类库解决。需要自行提供一组跨浏览器的api，比如kissy打包：\n\n```js\n  //api map\n  var utils = {\n    forEach : S.each,\n    some    : S.some,\n    mixin   : S.mix,\n    guid    : S.guid,\n    isArray : S.isArray,\n    indexOf : S.indexOf,\n    keys    : S.keys,\n    now     : S.now\n  };\n\n```\n\nVelocity语法具有很高的容错能力，类似于html结构的解析，同时语法规则复杂，所以语法\n解释器执行性能可能比较慢，`velocity.js`把语法结构分析运算和语法执行两个过程独立出来，\n第一步，语法结构分析返回一个数组(语法树)，描述velocity语法，语法执行使用数据和语\n法树，计算模板最终结果。\n\n执行build后，得到两个文件，分别是`build/velocity/`下的`index.js`和`parse.js`，两者\n相互独立，`parse.js`语法分析过程可以放在本地完成，执行命令：\n\n把语法分析和模板拼接分开，为了方便在本地编译语法树，减少在web端js运算。本地编译\n模板的思路，源自KISSY的[xtemplate](http://docs.kissyui.com/docs/html/api/component/xtemplate/)。\n\n虽然语法解释器可以在浏览器端执行，但是，不推荐那么使用。\n\n```bash\n#使用velocity命令行工具打包\nveloctiy --build *.vm\nveloctiy -b *.vm\n```\n\n源码中`test/web/`目录的js，一部分就是线下编译后的得到的，此处可[直接访问](http://git.shepherdwind.com/velocity.js/web/index.html)。\n\n##Public API\n\n###node_module\n\n```js\nvar Velocity = require('../src/velocity');\n\n//1. 直接解析\nVelocity.render('string of velocity', context);\n\n//2. 使用Parser和Compile\nvar Parser = Velocity.Parser;\nvar Compile = Velocity.Compile;\n\nvar asts = Parser.parse('string of velocity');\n(new Compile(asts)).render(context);\n```\n####context\n\n`context`是一个对象，可以为空，执行中`$foo.bar`，访问路径是`context.foo.bar`，\n`context`的属性可以是函数，和vm中定义保持一致。\n\n###On Broswer\n\n1 . 使用线下打包方案：\n\n```js\nKISSY.use('velocity/index, web/directives', function(S, Velocity, asts){\n  var compile = new Velocity(asts);\n  S.all('body').html(compile.render());\n});\n```\n\n2 . 使用线上编译：\n\n```js\nKISSY.use('velocity/index, velocity/parse', function(S, Velocity, Parser){\n  var html = (S.all('#tpl').html());\n  var asts = Parser.parse(html);\n  var compile = new Velocity(asts);\n  console.log(compile.render());\n});\n```\n\n两者的区别在于asts的获取，第一种方式，直接取asts，第二种，需要首先执行语法分析过\n程。\n\n##Syntax\n\n具体语法请访问官网文档：[velocity user guide](http://velocity.apache.org/engine/devel/user-guide.html)。\n\n###Directives\n\nDirectives支持`set`, `foreach`, `if|else|elseif`, `macro`, `parse`, `break`。不\n支持有，`stop`, `evaluate`, `define`，感觉这些语法比较偏，用处不大，暂时没有实现。\n其中`parse`，在web端，使用kissy的模块加载器加载，需要首先线下编译打包，[例子](http://git.shepherdwind.com/velocity.js/web/index.html)。\n\n###foreach\n\nforeach在velocity中对对象的遍历，和js有区别，java中对象是一个map，需要通过方法\n`keyset`来获取map中的key，foreach循环写法等同于js的for in循环，感觉有点怪异。在\n一个foreach，有一个`$foreach`的对象可以使用，此变量作用域为当前循环范围。\n\n```\n#foreach($num as [1..5])\n  index => $foreach.index \n  count => $foreach.count\n  #if (!$foreach.hasNext) end #end\n#end\n结果：\nindex => 0\ncount => 1\n\nindex => 1\ncount => 2\n...\nindex => 4\ncount => 5\nend\n```\n\n###string\n\nvelocity中字符串求值和php类似，双引号字符串里面的变量会被替换变量对应的值，单引\n号原样返回，推荐尽量使用单引号，那样性能好一些。此外，双引号中变量替换，没有再次\n调用语法分析器，而是使用正则，只支持简单的引用替换，比如`\"$varname1 $foo.bar\"`，\n`\"$foo.bar[1] $foo.bar()\"`都不支持。如果需要完整支持字符串双引号，需要反复调用语\n法分析器，考虑到性能，基本引用基本够用了，vm本身支持强大的变量赋值，可以先赋值，\n在放入字符串，或者使用加法进行字符串拼接。\n\n在java中可能大量使用双引号方式，因为java对象无法自动转换类型，双引号做类型转换用，\n而在web端，js无此需要。\n\n###velocity\n\n```\nUsage: velocity [options] [file ...]\n\nOptions:\n\n  -h, --help         output usage information\n  -V, --version      output the version number\n  -b, --build        build .vm file to js ast module of kissy\n\nExample:\n\n  # parse vm file\n  $ velocity a.vm \n\n  # parse vm file with json data\n  $ velocity a.vm  a.json\n\n  # build asts module of kissy\n  $ velocity *.vm\n```\n\n##Helper\n\nHelper提供一些额外的功能，都在`src/helper/`目录下，使用方式参考`test/`下对应文件，\nHelper功能还在开发中，可能不太完善。\n\n- `structure` 获取vm中所有变量的结构: `$foo.bar` => `foo: {bar: 'string'}`\n- `backstep` vm逆推，根据velocity文件和解析后的结果，计算数据结构和内容\n- `jsonify` 把vm转换为json结构，去除其中的html标签，比如：\n\n```\nhello world $foo.name.\n=>\n{foo: { name: $foo.name }}\n```\n\n##License\n\n(The MIT License)\n\nCopyright (c) 2012-2013 Eward Song<eward.song@gmail.com>\n\nPermission is hereby granted, free of charge, to any person obtaining a copy of\nthis software and associated documentation files (the 'Software'), to deal in\nthe Software without restriction, including without limitation the rights to\nuse, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of\nthe Software, and to permit persons to whom the Software is furnished to do so,\nsubject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS\nFOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR\nCOPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER\nIN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN\nCONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n","_id":"velocity.js@0.2.5","dist":{"shasum":"e67487e0af4313e65f73dd0d171660676cbee397","tarball":"https://registry.npmjs.org/velocity.js/-/velocity.js-0.2.5.tgz","integrity":"sha512-y7lD0QgN3rmQFuIktmwIa+6Uhuj8fin+MhHw1AUrOzg+kDOIejjfc4IR+2LHiNvX2Pix6dSCcgEbxPler+4ukQ==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQCxv0RRCLr4NxTKuPmUrJZQ0lmzp80IWeG/6vWKdQOlewIgduCsTyQ5oYGzk/IfRZsi9VeyuvYHGzd26pj8ifG8LGg="}]},"_npmVersion":"1.1.62","_npmUser":{"name":"shepherdwind","email":"eward.song@gmail.com"},"maintainers":[{"name":"shepherdwind","email":"eward.song@gmail.com"}]},"0.2.6":{"name":"velocity.js","description":"Velocity Template Language(VTL) for JavaScript","version":"0.2.6","keywords":["velocity template"],"homepage":"http://git.shepherdwind.com/velocity.js/","repository":{"type":"git","url":"git://github.com/shepherdwind/velocity.js.git"},"engines":{"node":">=0.8.0"},"main":"src/velocity.js","bin":{"velocity":"bin/velocity"},"scripts":{"test":"make test"},"readme":"##Velocity - Template Engine [![Build Status](https://secure.travis-ci.org/shepherdwind/velocity.js.png)](https://travis-ci.org/shepherdwind/velocity.js)\n\nvelocity.js是velocity模板语法的javascript实现。\n[Velocity](http://velocity.apache.org/) 是基于Java的模板引擎，广泛应用在阿里集\n体各个子公司。Velocity模板适用于大量模板使用的场景，支持复杂的逻辑运算，包含\n基本数据类型、变量赋值和函数等功能。\n\n\n##Features\n\n- 支持客户端和服务器端使用\n- 语法是富逻辑的，构成门微型的语言\n- 语法分析和模板渲染分离\n- 基本完全支持velocity语法\n- 浏览器使用支持模板之间相互引用，依据js模块加载机制，比如kissy\n- 三个Helper，友好的数据模拟解决方案\n- [Vim Syntax](https://github.com/shepherdwind/vim-velocity)\n\n##Install\n\nvia npm:\n\n```bash\n$ npm install velocity.js\n```\n\n##Broswer Support\n\n兼容ie6+，chrome等其他浏览器，[test case](http://git.shepherdwind.com/velocity.js/runner/tests.html)\n\n点击[此处](http://git.shepherdwind.com/velocity.js/try/index.html)可以体验web\n端velocity语法解析过程，注：使用ACE作为代码编辑器，仅支持高级浏览器访问。\n\n执行`cake`命令进行打包velocity.js浏览器端脚本:\n\n```bash\n$ cake --build\n```\n\n需要cli下安装coffeejs，暂时打包是为kissy所使用的，velocity.js需要的一些常用的\necma5功能，比如`foreach, some, isArray`等，在node环境下是自带的功能，而web端的兼\n容是交给已有的类库解决。需要自行提供一组跨浏览器的api，比如kissy打包：\n\n```js\n  //api map\n  var utils = {\n    forEach : S.each,\n    some    : S.some,\n    mixin   : S.mix,\n    guid    : S.guid,\n    isArray : S.isArray,\n    indexOf : S.indexOf,\n    keys    : S.keys,\n    now     : S.now\n  };\n\n```\n\nVelocity语法具有很高的容错能力，类似于html结构的解析，同时语法规则复杂，所以语法\n解释器执行性能可能比较慢，`velocity.js`把语法结构分析运算和语法执行两个过程独立出来，\n第一步，语法结构分析返回一个数组(语法树)，描述velocity语法，语法执行使用数据和语\n法树，计算模板最终结果。\n\n执行build后，得到两个文件，分别是`build/velocity/`下的`index.js`和`parse.js`，两者\n相互独立，`parse.js`语法分析过程可以放在本地完成，执行命令：\n\n把语法分析和模板拼接分开，为了方便在本地编译语法树，减少在web端js运算。本地编译\n模板的思路，源自KISSY的[xtemplate](http://docs.kissyui.com/docs/html/api/component/xtemplate/)。\n\n虽然语法解释器可以在浏览器端执行，但是，不推荐那么使用。\n\n```bash\n#使用velocity命令行工具打包\nveloctiy --build *.vm\nveloctiy -b *.vm\n```\n\n源码中`test/web/`目录的js，一部分就是线下编译后的得到的，此处可[直接访问](http://git.shepherdwind.com/velocity.js/web/index.html)。\n\n##Public API\n\n###node_module\n\n```js\nvar Velocity = require('../src/velocity');\n\n//1. 直接解析\nVelocity.render('string of velocity', context);\n\n//2. 使用Parser和Compile\nvar Parser = Velocity.Parser;\nvar Compile = Velocity.Compile;\n\nvar asts = Parser.parse('string of velocity');\n(new Compile(asts)).render(context);\n```\n####context\n\n`context`是一个对象，可以为空，执行中`$foo.bar`，访问路径是`context.foo.bar`，\n`context`的属性可以是函数，和vm中定义保持一致。\n\n###On Broswer\n\n1 . 使用线下打包方案：\n\n```js\nKISSY.use('velocity/index, web/directives', function(S, Velocity, asts){\n  var compile = new Velocity(asts);\n  S.all('body').html(compile.render());\n});\n```\n\n2 . 使用线上编译：\n\n```js\nKISSY.use('velocity/index, velocity/parse', function(S, Velocity, Parser){\n  var html = (S.all('#tpl').html());\n  var asts = Parser.parse(html);\n  var compile = new Velocity(asts);\n  console.log(compile.render());\n});\n```\n\n两者的区别在于asts的获取，第一种方式，直接取asts，第二种，需要首先执行语法分析过\n程。\n\n##Syntax\n\n具体语法请访问官网文档：[velocity user guide](http://velocity.apache.org/engine/devel/user-guide.html)。\n\n###Directives\n\nDirectives支持`set`, `foreach`, `if|else|elseif`, `macro`, `parse`, `break`。不\n支持有，`stop`, `evaluate`, `define`，感觉这些语法比较偏，用处不大，暂时没有实现。\n其中`parse`，在web端，使用kissy的模块加载器加载，需要首先线下编译打包，[例子](http://git.shepherdwind.com/velocity.js/web/index.html)。\n\n###foreach\n\nforeach在velocity中对对象的遍历，和js有区别，java中对象是一个map，需要通过方法\n`keyset`来获取map中的key，foreach循环写法等同于js的for in循环，感觉有点怪异。在\n一个foreach，有一个`$foreach`的对象可以使用，此变量作用域为当前循环范围。\n\n```\n#foreach($num as [1..5])\n  index => $foreach.index \n  count => $foreach.count\n  #if (!$foreach.hasNext) end #end\n#end\n结果：\nindex => 0\ncount => 1\n\nindex => 1\ncount => 2\n...\nindex => 4\ncount => 5\nend\n```\n\n###string\n\nvelocity中字符串求值和php类似，双引号字符串里面的变量会被替换变量对应的值，单引\n号原样返回，推荐尽量使用单引号，那样性能好一些。此外，双引号中变量替换，没有再次\n调用语法分析器，而是使用正则，只支持简单的引用替换，比如`\"$varname1 $foo.bar\"`，\n`\"$foo.bar[1] $foo.bar()\"`都不支持。如果需要完整支持字符串双引号，需要反复调用语\n法分析器，考虑到性能，基本引用基本够用了，vm本身支持强大的变量赋值，可以先赋值，\n在放入字符串，或者使用加法进行字符串拼接。\n\n在java中可能大量使用双引号方式，因为java对象无法自动转换类型，双引号做类型转换用，\n而在web端，js无此需要。\n\n###velocity\n\n```\nUsage: velocity [options] [file ...]\n\nOptions:\n\n  -h, --help         output usage information\n  -V, --version      output the version number\n  -b, --build        build .vm file to js ast module of kissy\n\nExample:\n\n  # parse vm file\n  $ velocity a.vm \n\n  # parse vm file with json data\n  $ velocity a.vm  a.json\n\n  # build asts module of kissy\n  $ velocity *.vm\n```\n\n##Helper\n\nHelper提供一些额外的功能，都在`src/helper/`目录下，使用方式参考`test/`下对应文件，\nHelper功能还在开发中，可能不太完善。\n\n- `structure` 获取vm中所有变量的结构: `$foo.bar` => `foo: {bar: 'string'}`\n- `backstep` vm逆推，根据velocity文件和解析后的结果，计算数据结构和内容\n- `jsonify` 把vm转换为json结构，去除其中的html标签，比如：\n\n```\nhello world $foo.name.\n=>\n{foo: { name: $foo.name }}\n```\n\n##License\n\n(The MIT License)\n\nCopyright (c) 2012-2013 Eward Song<eward.song@gmail.com>\n\nPermission is hereby granted, free of charge, to any person obtaining a copy of\nthis software and associated documentation files (the 'Software'), to deal in\nthe Software without restriction, including without limitation the rights to\nuse, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of\nthe Software, and to permit persons to whom the Software is furnished to do so,\nsubject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS\nFOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR\nCOPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER\nIN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN\nCONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n","_id":"velocity.js@0.2.6","dist":{"shasum":"222b0de810ebef8e09c5c4b43f267e2e53200619","tarball":"https://registry.npmjs.org/velocity.js/-/velocity.js-0.2.6.tgz","integrity":"sha512-yxJ9unnX0mao1Atwa/jl/dSCjQSq3vFu6OiGsP9lX2cY5m83cpQOKh/wCXftfFOpRy/n+2uJS+TSJZ5V1g/OVA==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIFnAFiyCdQET2Xzx9eKUHl/G00c5HZxBPXr0YJnKdLk/AiBFKfwJJmHPX2O6oISA+jlTIUCSkSvSbMt67h1FtAhvaA=="}]},"_npmVersion":"1.1.62","_npmUser":{"name":"shepherdwind","email":"eward.song@gmail.com"},"maintainers":[{"name":"shepherdwind","email":"eward.song@gmail.com"}]},"0.2.7":{"name":"velocity.js","description":"Velocity Template Language(VTL) for JavaScript","version":"0.2.7","keywords":["velocity template"],"homepage":"http://git.shepherdwind.com/velocity.js/","repository":{"type":"git","url":"git://github.com/shepherdwind/velocity.js.git"},"engines":{"node":">=0.8.0"},"main":"src/velocity.js","bin":{"velocity":"bin/velocity"},"scripts":{"test":"make test"},"readme":"##Velocity - Template Engine [![Build Status](https://secure.travis-ci.org/shepherdwind/velocity.js.png)](https://travis-ci.org/shepherdwind/velocity.js)\n\nvelocity.js是velocity模板语法的javascript实现。\n[Velocity](http://velocity.apache.org/) 是基于Java的模板引擎，广泛应用在阿里集\n体各个子公司。Velocity模板适用于大量模板使用的场景，支持复杂的逻辑运算，包含\n基本数据类型、变量赋值和函数等功能。\n\n\n##Features\n\n- 支持客户端和服务器端使用\n- 语法是富逻辑的，构成门微型的语言\n- 语法分析和模板渲染分离\n- 基本完全支持velocity语法\n- 浏览器使用支持模板之间相互引用，依据js模块加载机制，比如kissy\n- 三个Helper，友好的数据模拟解决方案\n- [Vim Syntax](https://github.com/shepherdwind/vim-velocity)\n\n##Install\n\nvia npm:\n\n```bash\n$ npm install velocity.js\n```\n\n##Broswer Support\n\n兼容ie6+，chrome等其他浏览器，[test case](http://git.shepherdwind.com/velocity.js/runner/tests.html)\n\n点击[此处](http://git.shepherdwind.com/velocity.js/try/index.html)可以体验web\n端velocity语法解析过程，注：使用ACE作为代码编辑器，仅支持高级浏览器访问。\n\n执行`cake`命令进行打包velocity.js浏览器端脚本:\n\n```bash\n$ cake --build\n```\n\n需要cli下安装coffeejs，暂时打包是为kissy所使用的，velocity.js需要的一些常用的\necma5功能，比如`foreach, some, isArray`等，在node环境下是自带的功能，而web端的兼\n容是交给已有的类库解决。需要自行提供一组跨浏览器的api，比如kissy打包：\n\n```js\n  //api map\n  var utils = {\n    forEach : S.each,\n    some    : S.some,\n    mixin   : S.mix,\n    guid    : S.guid,\n    isArray : S.isArray,\n    indexOf : S.indexOf,\n    keys    : S.keys,\n    now     : S.now\n  };\n\n```\n\nVelocity语法具有很高的容错能力，类似于html结构的解析，同时语法规则复杂，所以语法\n解释器执行性能可能比较慢，`velocity.js`把语法结构分析运算和语法执行两个过程独立出来，\n第一步，语法结构分析返回一个数组(语法树)，描述velocity语法，语法执行使用数据和语\n法树，计算模板最终结果。\n\n执行build后，得到两个文件，分别是`build/velocity/`下的`index.js`和`parse.js`，两者\n相互独立，`parse.js`语法分析过程可以放在本地完成，执行命令：\n\n把语法分析和模板拼接分开，为了方便在本地编译语法树，减少在web端js运算。本地编译\n模板的思路，源自KISSY的[xtemplate](http://docs.kissyui.com/docs/html/api/component/xtemplate/)。\n\n虽然语法解释器可以在浏览器端执行，但是，不推荐那么使用。\n\n```bash\n#使用velocity命令行工具打包\nveloctiy --build *.vm\nveloctiy -b *.vm\n```\n\n源码中`test/web/`目录的js，一部分就是线下编译后的得到的，此处可[直接访问](http://git.shepherdwind.com/velocity.js/web/index.html)。\n\n##Public API\n\n###node_module\n\n```js\nvar Velocity = require('../src/velocity');\n\n//1. 直接解析\nVelocity.render('string of velocity', context);\n\n//2. 使用Parser和Compile\nvar Parser = Velocity.Parser;\nvar Compile = Velocity.Compile;\n\nvar asts = Parser.parse('string of velocity');\n(new Compile(asts)).render(context);\n```\n####context\n\n`context`是一个对象，可以为空，执行中`$foo.bar`，访问路径是`context.foo.bar`，\n`context`的属性可以是函数，和vm中定义保持一致。\n\n###On Broswer\n\n1 . 使用线下打包方案：\n\n```js\nKISSY.use('velocity/index, web/directives', function(S, Velocity, asts){\n  var compile = new Velocity(asts);\n  S.all('body').html(compile.render());\n});\n```\n\n2 . 使用线上编译：\n\n```js\nKISSY.use('velocity/index, velocity/parse', function(S, Velocity, Parser){\n  var html = (S.all('#tpl').html());\n  var asts = Parser.parse(html);\n  var compile = new Velocity(asts);\n  console.log(compile.render());\n});\n```\n\n两者的区别在于asts的获取，第一种方式，直接取asts，第二种，需要首先执行语法分析过\n程。\n\n##Syntax\n\n具体语法请访问官网文档：[velocity user guide](http://velocity.apache.org/engine/devel/user-guide.html)。\n\n###Directives\n\nDirectives支持`set`, `foreach`, `if|else|elseif`, `macro`, `parse`, `break`。不\n支持有，`stop`, `evaluate`, `define`，感觉这些语法比较偏，用处不大，暂时没有实现。\n其中`parse`，在web端，使用kissy的模块加载器加载，需要首先线下编译打包，[例子](http://git.shepherdwind.com/velocity.js/web/index.html)。\n\n###macro\n\n宏分为系统的宏，比如`parse, include`，和用户自定义宏，通过`#macro`在vm中定义，此\n外可以使用自定义的js函数替代在vm中定义。对于系统宏和自定义宏，不做区分，对于\n`#parse`和`#include`的调用，可以使用自定义函数来执行。具体见[issue #3](https://github.com/shepherdwind/velocity.js/issues/3)。\n\n###foreach\n\nforeach在velocity中对对象的遍历，和js有区别，java中对象是一个map，需要通过方法\n`keyset`来获取map中的key，foreach循环写法等同于js的for in循环，感觉有点怪异。在\n一个foreach，有一个`$foreach`的对象可以使用，此变量作用域为当前循环范围。\n\n```\n#foreach($num as [1..5])\n  index => $foreach.index \n  count => $foreach.count\n  #if (!$foreach.hasNext) end #end\n#end\n结果：\nindex => 0\ncount => 1\n\nindex => 1\ncount => 2\n...\nindex => 4\ncount => 5\nend\n```\n\n###string\n\nvelocity中字符串求值和php类似，双引号字符串里面的变量会被替换变量对应的值，单引\n号原样返回，推荐尽量使用单引号，那样性能好一些。此外，双引号中变量替换，没有再次\n调用语法分析器，而是使用正则，只支持简单的引用替换，比如`\"$varname1 $foo.bar\"`，\n`\"$foo.bar[1] $foo.bar()\"`都不支持。如果需要完整支持字符串双引号，需要反复调用语\n法分析器，考虑到性能，基本引用基本够用了，vm本身支持强大的变量赋值，可以先赋值，\n在放入字符串，或者使用加法进行字符串拼接。\n\n在java中可能大量使用双引号方式，因为java对象无法自动转换类型，双引号做类型转换用，\n而在web端，js无此需要。\n\n###velocity\n\n```\nUsage: velocity [options] [file ...]\n\nOptions:\n\n  -h, --help         output usage information\n  -V, --version      output the version number\n  -b, --build        build .vm file to js ast module of kissy\n\nExample:\n\n  # parse vm file\n  $ velocity a.vm \n\n  # parse vm file with json data\n  $ velocity a.vm  a.json\n\n  # build asts module of kissy\n  $ velocity *.vm\n```\n\n##Helper\n\nHelper提供一些额外的功能，都在`src/helper/`目录下，使用方式参考`test/`下对应文件，\nHelper功能还在开发中，可能不太完善。\n\n- `structure` 获取vm中所有变量的结构: `$foo.bar` => `foo: {bar: 'string'}`\n- `backstep` vm逆推，根据velocity文件和解析后的结果，计算数据结构和内容\n- `jsonify` 把vm转换为json结构，去除其中的html标签，比如：\n\n```\nhello world $foo.name.\n=>\n{foo: { name: $foo.name }}\n```\n\n##License\n\n(The MIT License)\n\nCopyright (c) 2012-2013 Eward Song<eward.song@gmail.com>\n\nPermission is hereby granted, free of charge, to any person obtaining a copy of\nthis software and associated documentation files (the 'Software'), to deal in\nthe Software without restriction, including without limitation the rights to\nuse, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of\nthe Software, and to permit persons to whom the Software is furnished to do so,\nsubject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS\nFOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR\nCOPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER\nIN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN\nCONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n","_id":"velocity.js@0.2.7","dist":{"shasum":"c2b7f44f62f708c8ba379b3a3dec4bc93b9f38c9","tarball":"https://registry.npmjs.org/velocity.js/-/velocity.js-0.2.7.tgz","integrity":"sha512-yuu3iO+IZV/YCD0vB5dvR1Nh0Xf22ntiCCZlXVhdWxJqZDeMmK4cK488MA/bZ81f7jslsvdxnYx8nJkfU8gmxQ==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCID/lrFdx5iQeKpHMQNnmWquS43pQYwE8Ac8iCddi3EmAAiATxrNfx6tYVQY/ICIsnMIfabx+VLziR9dnSA0jJ5KAhQ=="}]},"_npmVersion":"1.1.62","_npmUser":{"name":"shepherdwind","email":"eward.song@gmail.com"},"maintainers":[{"name":"shepherdwind","email":"eward.song@gmail.com"}]},"0.3.0":{"name":"velocity.js","description":"Velocity Template Language(VTL) for JavaScript","version":"0.3.0","keywords":["velocity template"],"homepage":"http://git.shepherdwind.com/velocity.js/","repository":{"type":"git","url":"git://github.com/shepherdwind/velocity.js.git"},"engines":{"node":">=0.8.0"},"main":"src/velocity.js","bin":{"velocity":"bin/velocity"},"devDependencies":{"mocha":">=1.7.2","jison":">=0.3","coffee-script":">=1.4.0"},"scripts":{"test":"make test"},"readme":"##Velocity - Template Engine [![Build Status](https://secure.travis-ci.org/shepherdwind/velocity.js.png)](https://travis-ci.org/shepherdwind/velocity.js)\n\nvelocity.js是velocity模板语法的javascript实现。\n[Velocity](http://velocity.apache.org/) 是基于Java的模板引擎，广泛应用在阿里集\n体各个子公司。Velocity模板适用于大量模板使用的场景，支持复杂的逻辑运算，包含\n基本数据类型、变量赋值和函数等功能。\n\n\n##Features\n\n- 支持客户端和服务器端使用\n- 语法是富逻辑的，构成门微型的语言\n- 语法分析和模板渲染分离\n- 基本完全支持velocity语法\n- 浏览器使用支持模板之间相互引用，依据js模块加载机制，比如kissy\n- 三个Helper，友好的数据模拟解决方案\n- [Vim Syntax](https://github.com/shepherdwind/vim-velocity)\n\n##Install\n\nvia npm:\n\n```bash\n$ npm install velocity.js\n```\n\n##Broswer Support\n\n兼容ie6+，chrome等其他浏览器，[test case](http://git.shepherdwind.com/velocity.js/runner/tests.html)\n\n点击[此处](http://git.shepherdwind.com/velocity.js/try/index.html)可以体验web\n端velocity语法解析过程，注：使用ACE作为代码编辑器，仅支持高级浏览器访问。\n\n执行`cake`命令进行打包velocity.js浏览器端脚本:\n\n```bash\n$ cake --build\n```\n\n需要cli下安装coffeejs，暂时打包是为kissy所使用的，velocity.js需要的一些常用的\necma5功能，比如`foreach, some, isArray`等，在node环境下是自带的功能，而web端的兼\n容是交给已有的类库解决。需要自行提供一组跨浏览器的api，比如kissy打包：\n\n```js\n  //api map\n  var utils = {\n    forEach : S.each,\n    some    : S.some,\n    mixin   : S.mix,\n    guid    : S.guid,\n    isArray : S.isArray,\n    indexOf : S.indexOf,\n    keys    : S.keys,\n    now     : S.now\n  };\n\n```\n\nVelocity语法具有很高的容错能力，类似于html结构的解析，同时语法规则复杂，所以语法\n解释器执行性能可能比较慢，`velocity.js`把语法结构分析运算和语法执行两个过程独立出来，\n第一步，语法结构分析返回一个数组(语法树)，描述velocity语法，语法执行使用数据和语\n法树，计算模板最终结果。\n\n执行build后，得到两个文件，分别是`build/velocity/`下的`index.js`和`parse.js`，两者\n相互独立，`parse.js`语法分析过程可以放在本地完成，执行命令：\n\n把语法分析和模板拼接分开，为了方便在本地编译语法树，减少在web端js运算。本地编译\n模板的思路，源自KISSY的[xtemplate](http://docs.kissyui.com/docs/html/api/component/xtemplate/)。\n\n虽然语法解释器可以在浏览器端执行，但是，不推荐那么使用。\n\n```bash\n#使用velocity命令行工具打包\nveloctiy --build *.vm\nveloctiy -b *.vm\n```\n\n源码中`test/web/`目录的js，一部分就是线下编译后的得到的，此处可[直接访问](http://git.shepherdwind.com/velocity.js/web/index.html)。\n\n##Public API\n\n###node_module\n\n```js\nvar Velocity = require('../src/velocity');\n\n//1. 直接解析\nVelocity.render('string of velocity', context);\n\n//2. 使用Parser和Compile\nvar Parser = Velocity.Parser;\nvar Compile = Velocity.Compile;\n\nvar asts = Parser.parse('string of velocity');\n(new Compile(asts)).render(context);\n```\n####context\n\n`context`是一个对象，可以为空，执行中`$foo.bar`，访问路径是`context.foo.bar`，\n`context`的属性可以是函数，和vm中定义保持一致。\n\n###On Broswer\n\n1 . 使用线下打包方案：\n\n```js\nKISSY.use('velocity/index, web/directives', function(S, Velocity, asts){\n  var compile = new Velocity(asts);\n  S.all('body').html(compile.render());\n});\n```\n\n2 . 使用线上编译：\n\n```js\nKISSY.use('velocity/index, velocity/parse', function(S, Velocity, Parser){\n  var html = (S.all('#tpl').html());\n  var asts = Parser.parse(html);\n  var compile = new Velocity(asts);\n  console.log(compile.render());\n});\n```\n\n两者的区别在于asts的获取，第一种方式，直接取asts，第二种，需要首先执行语法分析过\n程。\n\n##Syntax\n\n具体语法请访问官网文档：[velocity user guide](http://velocity.apache.org/engine/devel/user-guide.html)。\n\n###Directives\n\nDirectives支持`set`, `foreach`, `if|else|elseif`, `macro`, `parse`, `break`。不\n支持有，`stop`, `evaluate`, `define`，感觉这些语法比较偏，用处不大，暂时没有实现。\n其中`parse`，在web端，使用kissy的模块加载器加载，需要首先线下编译打包，[例子](http://git.shepherdwind.com/velocity.js/web/index.html)。\n\n###macro\n\n宏分为系统的宏，比如`parse, include`，和用户自定义宏，通过`#macro`在vm中定义，此\n外可以使用自定义的js函数替代在vm中定义。对于系统宏和自定义宏，不做区分，对于\n`#parse`和`#include`的调用，可以使用自定义函数来执行。具体见[issue #3](https://github.com/shepherdwind/velocity.js/issues/3)。\n\n###foreach\n\nforeach在velocity中对对象的遍历，和js有区别，java中对象是一个map，需要通过方法\n`keyset`来获取map中的key，foreach循环写法等同于js的for in循环，感觉有点怪异。在\n一个foreach，有一个`$foreach`的对象可以使用，此变量作用域为当前循环范围。\n\n```\n#foreach($num as [1..5])\n  index => $foreach.index \n  count => $foreach.count\n  #if (!$foreach.hasNext) end #end\n#end\n结果：\nindex => 0\ncount => 1\n\nindex => 1\ncount => 2\n...\nindex => 4\ncount => 5\nend\n```\n\n###string\n\nvelocity中字符串求值和php类似，双引号字符串里面的变量会被替换变量对应的值，单引\n号原样返回，推荐尽量使用单引号，那样性能好一些。此外，双引号中变量替换，没有再次\n调用语法分析器，而是使用正则，只支持简单的引用替换，比如`\"$varname1 $foo.bar\"`，\n`\"$foo.bar[1] $foo.bar()\"`都不支持。如果需要完整支持字符串双引号，需要反复调用语\n法分析器，考虑到性能，基本引用基本够用了，vm本身支持强大的变量赋值，可以先赋值，\n在放入字符串，或者使用加法进行字符串拼接。\n\n在java中可能大量使用双引号方式，因为java对象无法自动转换类型，双引号做类型转换用，\n而在web端，js无此需要。\n\n###velocity\n\n```\nUsage: velocity [options] [file ...]\n\nOptions:\n\n  -h, --help         output usage information\n  -V, --version      output the version number\n  -b, --build        build .vm file to js ast module of kissy\n\nExample:\n\n  # parse vm file\n  $ velocity a.vm \n\n  # parse vm file with json data\n  $ velocity a.vm  a.json\n\n  # build asts module of kissy\n  $ velocity *.vm\n```\n\n##Helper\n\nHelper提供一些额外的功能，都在`src/helper/`目录下，使用方式参考`test/`下对应文件，\nHelper功能还在开发中，可能不太完善。\n\n- `structure` 获取vm中所有变量的结构: `$foo.bar` => `foo: {bar: 'string'}`\n- `backstep` vm逆推，根据velocity文件和解析后的结果，计算数据结构和内容\n- `jsonify` 把vm转换为json结构，去除其中的html标签，比如：\n\n```\nhello world $foo.name.\n=>\n{foo: { name: $foo.name }}\n```\n\n##License\n\n(The MIT License)\n\nCopyright (c) 2012-2013 Eward Song<eward.song@gmail.com>\n\nPermission is hereby granted, free of charge, to any person obtaining a copy of\nthis software and associated documentation files (the 'Software'), to deal in\nthe Software without restriction, including without limitation the rights to\nuse, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of\nthe Software, and to permit persons to whom the Software is furnished to do so,\nsubject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS\nFOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR\nCOPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER\nIN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN\nCONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n","_id":"velocity.js@0.3.0","dist":{"shasum":"2118f7d2687e7b53b8f644fd7ee173543482c4e9","tarball":"https://registry.npmjs.org/velocity.js/-/velocity.js-0.3.0.tgz","integrity":"sha512-FviBqIxVGAVpGYd4h86qA+ebvNHzzVPW6kub7ImhHalEcErmhq0LaMoUPXQcOOcYbItm83h/YM++nIqhReKz5w==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQDNl/euVeOMjZZfrBzrB2035jkSCuIrgDBEsAeYm12LhwIhAMXOWX/OyJWtleB9OLR/5BwUAj+n74PaoVyUNKtW9ciR"}]},"_npmVersion":"1.1.62","_npmUser":{"name":"shepherdwind","email":"eward.song@gmail.com"},"maintainers":[{"name":"shepherdwind","email":"eward.song@gmail.com"}]},"0.3.1":{"name":"velocity.js","description":"Velocity Template Language(VTL) for JavaScript","version":"0.3.1","keywords":["velocity template"],"homepage":"http://git.shepherdwind.com/velocity.js/","repository":{"type":"git","url":"git://github.com/shepherdwind/velocity.js.git"},"engines":{"node":">=0.8.0"},"main":"src/velocity.js","bin":{"velocity":"bin/velocity"},"devDependencies":{"mocha":">=1.7.2","jison":">=0.3","coffee-script":">=1.4.0"},"scripts":{"test":"make test"},"readme":"##Velocity - Template Engine [![Build Status](https://secure.travis-ci.org/shepherdwind/velocity.js.png)](https://travis-ci.org/shepherdwind/velocity.js)\n\nvelocity.js是velocity模板语法的javascript实现。\n[Velocity](http://velocity.apache.org/) 是基于Java的模板引擎，广泛应用在阿里集\n体各个子公司。Velocity模板适用于大量模板使用的场景，支持复杂的逻辑运算，包含\n基本数据类型、变量赋值和函数等功能。\n\n\n##Features\n\n- 支持客户端和服务器端使用\n- 语法是富逻辑的，构成门微型的语言\n- 语法分析和模板渲染分离\n- 基本完全支持velocity语法\n- 浏览器使用支持模板之间相互引用，依据js模块加载机制，比如kissy\n- 三个Helper，友好的数据模拟解决方案\n- [Vim Syntax](https://github.com/shepherdwind/vim-velocity)\n\n##Install\n\nvia npm:\n\n```bash\n$ npm install velocity.js\n```\n\n##Broswer Support\n\n兼容ie6+，chrome等其他浏览器，[test case](http://shepherdwind.com/velocity/runner/tests.html)\n\n点击[此处](http://shepherdwind.com/velocity/try/index.html)可以体验web\n端velocity语法解析过程，注：使用ACE作为代码编辑器，仅支持高级浏览器访问。\n\n执行`cake`命令进行打包velocity.js浏览器端脚本:\n\n```bash\n$ cake --build\n```\n\n需要cli下安装coffeejs，暂时打包是为kissy所使用的，velocity.js需要的一些常用的\necma5功能，比如`foreach, some, isArray`等，在node环境下是自带的功能，而web端的兼\n容是交给已有的类库解决。需要自行提供一组跨浏览器的api，比如kissy打包：\n\n```js\n  //api map\n  var utils = {\n    forEach : S.each,\n    some    : S.some,\n    mixin   : S.mix,\n    guid    : S.guid,\n    isArray : S.isArray,\n    indexOf : S.indexOf,\n    keys    : S.keys,\n    now     : S.now\n  };\n\n```\n\nVelocity语法具有很高的容错能力，类似于html结构的解析，同时语法规则复杂，所以语法\n解释器执行性能可能比较慢，`velocity.js`把语法结构分析运算和语法执行两个过程独立出来，\n第一步，语法结构分析返回一个数组(语法树)，描述velocity语法，语法执行使用数据和语\n法树，计算模板最终结果。\n\n执行build后，得到两个文件，分别是`build/velocity/`下的`index.js`和`parse.js`，两者\n相互独立，`parse.js`语法分析过程可以放在本地完成，执行命令：\n\n把语法分析和模板拼接分开，为了方便在本地编译语法树，减少在web端js运算。本地编译\n模板的思路，源自KISSY的[xtemplate](http://docs.kissyui.com/docs/html/api/component/xtemplate/)。\n\n虽然语法解释器可以在浏览器端执行，但是，不推荐那么使用。\n\n```bash\n#使用velocity命令行工具打包\nveloctiy --build *.vm\nveloctiy -b *.vm\n```\n\n源码中`test/web/`目录的js，一部分就是线下编译后的得到的，此处可[直接访问](http://shepherdwind.com/velocity/web/index.html)。\n\n##Public API\n\n###node_module\n\n```js\nvar Velocity = require('../src/velocity');\n\n//1. 直接解析\nVelocity.render('string of velocity', context);\n\n//2. 使用Parser和Compile\nvar Parser = Velocity.Parser;\nvar Compile = Velocity.Compile;\n\nvar asts = Parser.parse('string of velocity');\n(new Compile(asts)).render(context);\n```\n####context\n\n`context`是一个对象，可以为空，执行中`$foo.bar`，访问路径是`context.foo.bar`，\n`context`的属性可以是函数，和vm中定义保持一致。\n\n###On Broswer\n\n1 . 使用线下打包方案：\n\n```js\nKISSY.use('velocity/index, web/directives', function(S, Velocity, asts){\n  var compile = new Velocity(asts);\n  S.all('body').html(compile.render());\n});\n```\n\n2 . 使用线上编译：\n\n```js\nKISSY.use('velocity/index, velocity/parse', function(S, Velocity, Parser){\n  var html = (S.all('#tpl').html());\n  var asts = Parser.parse(html);\n  var compile = new Velocity(asts);\n  console.log(compile.render());\n});\n```\n\n两者的区别在于asts的获取，第一种方式，直接取asts，第二种，需要首先执行语法分析过\n程。\n\n##Syntax\n\n具体语法请访问官网文档：[velocity user guide](http://velocity.apache.org/engine/devel/user-guide.html)。\n\n###Directives\n\nDirectives支持`set`, `foreach`, `if|else|elseif`, `macro`, `parse`, `break`。不\n支持有，`stop`, `evaluate`, `define`，感觉这些语法比较偏，用处不大，暂时没有实现。\n其中`parse`，在web端，使用kissy的模块加载器加载，需要首先线下编译打包，[例子](http://shepherdwind.com/velocity/web/index.html)。\n\n###macro\n\n宏分为系统的宏，比如`parse, include`，和用户自定义宏，通过`#macro`在vm中定义，此\n外可以使用自定义的js函数替代在vm中定义。对于系统宏和自定义宏，不做区分，对于\n`#parse`和`#include`的调用，可以使用自定义函数来执行。具体见[issue #3](https://github.com/shepherdwind/velocity.js/issues/3)。\n\n###foreach\n\nforeach在velocity中对对象的遍历，和js有区别，java中对象是一个map，需要通过方法\n`keyset`来获取map中的key，foreach循环写法等同于js的for in循环，感觉有点怪异。在\n一个foreach，有一个`$foreach`的对象可以使用，此变量作用域为当前循环范围。\n\n```\n#foreach($num as [1..5])\n  index => $foreach.index \n  count => $foreach.count\n  #if (!$foreach.hasNext) end #end\n#end\n结果：\nindex => 0\ncount => 1\n\nindex => 1\ncount => 2\n...\nindex => 4\ncount => 5\nend\n```\n\n###string\n\nvelocity中字符串求值和php类似，双引号字符串里面的变量会被替换变量对应的值，单引\n号原样返回，推荐尽量使用单引号，那样性能好一些。此外，双引号中变量替换，没有再次\n调用语法分析器，而是使用正则，只支持简单的引用替换，比如`\"$varname1 $foo.bar\"`，\n`\"$foo.bar[1] $foo.bar()\"`都不支持。如果需要完整支持字符串双引号，需要反复调用语\n法分析器，考虑到性能，基本引用基本够用了，vm本身支持强大的变量赋值，可以先赋值，\n在放入字符串，或者使用加法进行字符串拼接。\n\n在java中可能大量使用双引号方式，因为java对象无法自动转换类型，双引号做类型转换用，\n而在web端，js无此需要。\n\n###velocity\n\n```\nUsage: velocity [options] [file ...]\n\nOptions:\n\n  -h, --help         output usage information\n  -V, --version      output the version number\n  -b, --build        build .vm file to js ast module of kissy\n\nExample:\n\n  # parse vm file\n  $ velocity a.vm \n\n  # parse vm file with json data\n  $ velocity a.vm  a.json\n\n  # build asts module of kissy\n  $ velocity *.vm\n```\n\n##Helper\n\nHelper提供一些额外的功能，都在`src/helper/`目录下，使用方式参考`test/`下对应文件，\nHelper功能还在开发中，可能不太完善。\n\n- `structure` 获取vm中所有变量的结构: `$foo.bar` => `foo: {bar: 'string'}`\n- `backstep` vm逆推，根据velocity文件和解析后的结果，计算数据结构和内容\n- `jsonify` 把vm转换为json结构，去除其中的html标签，比如：\n\n```\nhello world $foo.name.\n=>\n{foo: { name: $foo.name }}\n```\n\n##License\n\n(The MIT License)\n\nCopyright (c) 2012-2013 Eward Song<eward.song@gmail.com>\n\nPermission is hereby granted, free of charge, to any person obtaining a copy of\nthis software and associated documentation files (the 'Software'), to deal in\nthe Software without restriction, including without limitation the rights to\nuse, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of\nthe Software, and to permit persons to whom the Software is furnished to do so,\nsubject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS\nFOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR\nCOPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER\nIN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN\nCONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n","_id":"velocity.js@0.3.1","dist":{"shasum":"26ff26a0887410b04bcd28d82bb6711c53681b65","tarball":"https://registry.npmjs.org/velocity.js/-/velocity.js-0.3.1.tgz","integrity":"sha512-wC3lmLyVM1AejOPioghvWxCfLUtxusaknxJLMpudDusyljgu5VwZbZ7kZgoQhG9Vm0M3/q8/NBvGm3gt2uZ64A==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQCfil+h7UUz3Ak9JsObw3XT/qz57suzUCg0kj3A99aYxwIgN8lnX/dt/v5E2quRo/Qoc2gn90w42idPAv4g2BOKkhQ="}]},"_npmVersion":"1.1.62","_npmUser":{"name":"shepherdwind","email":"eward.song@gmail.com"},"maintainers":[{"name":"shepherdwind","email":"eward.song@gmail.com"}]},"0.3.2":{"name":"velocity.js","description":"Velocity Template Language(VTL) for JavaScript","version":"0.3.2","keywords":["velocity template"],"homepage":"http://git.shepherdwind.com/velocity.js/","repository":{"type":"git","url":"git://github.com/shepherdwind/velocity.js.git"},"engines":{"node":">=0.8.0"},"main":"src/velocity.js","bin":{"velocity":"bin/velocity"},"devDependencies":{"mocha":">=1.7.2","jison":">=0.3","coffee-script":">=1.4.0"},"scripts":{"test":"make test"},"readme":"##Velocity - Template Engine [![Build Status](https://secure.travis-ci.org/shepherdwind/velocity.js.png)](https://travis-ci.org/shepherdwind/velocity.js)\n\n*注意*\n\nvelocityjs在npm中包名从原来的`velocity.js`改为`velocityjs`，感觉`require(\"velocity.js\")`\n比较不好看，所以改名，从`0.3.0`之后的版本都在`velocityjs`下更新。\n\n查看最新版本\n\n```bash\n$ npm info velocityjs version\n```\n\nvelocity.js是velocity模板语法的javascript实现。\n[Velocity](http://velocity.apache.org/) 是基于Java的模板引擎，广泛应用在阿里集\n体各个子公司。Velocity模板适用于大量模板使用的场景，支持复杂的逻辑运算，包含\n基本数据类型、变量赋值和函数等功能。\n\n\n##Features\n\n- 支持客户端和服务器端使用\n- 语法是富逻辑的，构成门微型的语言\n- 语法分析和模板渲染分离\n- 基本完全支持velocity语法\n- 浏览器使用支持模板之间相互引用，依据js模块加载机制，比如kissy\n- 三个Helper，友好的数据模拟解决方案\n- [Vim Syntax](https://github.com/shepherdwind/vim-velocity)\n\n##Install\n\nvia npm:\n\n```bash\n$ npm install velocityjs\n```\n\n##Broswer Support\n\n兼容ie6+，chrome等其他浏览器，[test case](http://shepherdwind.com/velocity/runner/tests.html)\n\n点击[此处](http://shepherdwind.com/velocity/try/index.html)可以体验web\n端velocity语法解析过程，注：使用ACE作为代码编辑器，仅支持高级浏览器访问。\n\n执行`cake`命令进行打包velocity.js浏览器端脚本:\n\n```bash\n$ make parse\n```\n\n需要cli下安装coffeejs，暂时打包是为kissy所使用的，velocity.js需要的一些常用的\necma5功能，比如`foreach, some, isArray`等，在node环境下是自带的功能，而web端的兼\n容是交给已有的类库解决。需要自行提供一组跨浏览器的api，比如kissy打包：\n\n```js\n  //api map\n  var utils = {\n    forEach : S.each,\n    some    : S.some,\n    mixin   : S.mix,\n    guid    : S.guid,\n    isArray : S.isArray,\n    indexOf : S.indexOf,\n    keys    : S.keys,\n    now     : S.now\n  };\n\n```\n\nVelocity语法具有很高的容错能力，类似于html结构的解析，同时语法规则复杂，所以语法\n解释器执行性能可能比较慢，`velocity.js`把语法结构分析运算和语法执行两个过程独立出来，\n第一步，语法结构分析返回一个数组(语法树)，描述velocity语法，语法执行使用数据和语\n法树，计算模板最终结果。\n\n执行build后，得到两个文件，分别是`build/velocity/`下的`index.js`和`parse.js`，两者\n相互独立，`parse.js`语法分析过程可以放在本地完成，执行命令：\n\n把语法分析和模板拼接分开，为了方便在本地编译语法树，减少在web端js运算。本地编译\n模板的思路，源自KISSY的[xtemplate](http://docs.kissyui.com/docs/html/api/component/xtemplate/)。\n\n虽然语法解释器可以在浏览器端执行，但是，不推荐那么使用。\n\n```bash\n#使用velocity命令行工具打包\nveloctiy --build *.vm\nveloctiy -b *.vm\n```\n\n源码中`test/web/`目录的js，一部分就是线下编译后的得到的，此处可[直接访问](http://shepherdwind.com/velocity/web/index.html)。\n\n##Public API\n\n###node_module\n\n```js\nvar Velocity = require('../src/velocity');\n\n//1. 直接解析\nVelocity.render('string of velocity', context);\n\n//2. 使用Parser和Compile\nvar Parser = Velocity.Parser;\nvar Compile = Velocity.Compile;\n\nvar asts = Parser.parse('string of velocity');\n(new Compile(asts)).render(context);\n```\n####context\n\n`context`是一个对象，可以为空，执行中`$foo.bar`，访问路径是`context.foo.bar`，\n`context`的属性可以是函数，和vm中定义保持一致。\n\n###On Broswer\n\n1 . 使用线下打包方案：\n\n```js\nKISSY.use('velocity/index, web/directives', function(S, Velocity, asts){\n  var compile = new Velocity(asts);\n  S.all('body').html(compile.render());\n});\n```\n\n2 . 使用线上编译：\n\n```js\nKISSY.use('velocity/index, velocity/parse', function(S, Velocity, Parser){\n  var html = (S.all('#tpl').html());\n  var asts = Parser.parse(html);\n  var compile = new Velocity(asts);\n  console.log(compile.render());\n});\n```\n\n两者的区别在于asts的获取，第一种方式，直接取asts，第二种，需要首先执行语法分析过\n程。\n\n##Syntax\n\n具体语法请访问官网文档：[velocity user guide](http://velocity.apache.org/engine/devel/user-guide.html)。\n\n###Directives\n\nDirectives支持`set`, `foreach`, `if|else|elseif`, `macro`, `parse`, `break`。不\n支持有，`stop`, `evaluate`, `define`，感觉这些语法比较偏，用处不大，暂时没有实现。\n其中`parse`，在web端，使用kissy的模块加载器加载，需要首先线下编译打包，[例子](http://shepherdwind.com/velocity/web/index.html)。\n\n###macro\n\n宏分为系统的宏，比如`parse, include`，和用户自定义宏，通过`#macro`在vm中定义，此\n外可以使用自定义的js函数替代在vm中定义。对于系统宏和自定义宏，不做区分，对于\n`#parse`和`#include`的调用，可以使用自定义函数来执行。具体见[issue #3](https://github.com/shepherdwind/velocity.js/issues/3)。\n\n###foreach\n\nforeach在velocity中对对象的遍历，和js有区别，java中对象是一个map，需要通过方法\n`keyset`来获取map中的key，foreach循环写法等同于js的for in循环，感觉有点怪异。在\n一个foreach，有一个`$foreach`的对象可以使用，此变量作用域为当前循环范围。\n\n```\n#foreach($num in [1..5])\n  index => $foreach.index \n  count => $foreach.count\n  #if (!$foreach.hasNext) end #end\n#end\n结果：\nindex => 0\ncount => 1\n\nindex => 1\ncount => 2\n...\nindex => 4\ncount => 5\nend\n```\n\n###string\n\nvelocity中字符串求值和php类似，双引号字符串里面的变量会被替换变量对应的值，单引\n号原样返回，推荐尽量使用单引号，那样性能好一些。此外，双引号中变量替换，没有再次\n调用语法分析器，而是使用正则，只支持简单的引用替换，比如`\"$varname1 $foo.bar\"`，\n`\"$foo.bar[1] $foo.bar()\"`都不支持。如果需要完整支持字符串双引号，需要反复调用语\n法分析器，考虑到性能，基本引用基本够用了，vm本身支持强大的变量赋值，可以先赋值，\n在放入字符串，或者使用加法进行字符串拼接。\n\n在java中可能大量使用双引号方式，因为java对象无法自动转换类型，双引号做类型转换用，\n而在web端，js无此需要。\n\n###velocity\n\n```\nUsage: velocity [options] [file ...]\n\nOptions:\n\n  -h, --help         output usage information\n  -V, --version      output the version number\n  -b, --build        build .vm file to js ast module of kissy\n\nExample:\n\n  # parse vm file\n  $ velocity a.vm \n\n  # parse vm file with json data\n  $ velocity a.vm  a.json\n\n  # build asts module of kissy\n  $ velocity *.vm\n```\n\n##Helper\n\nHelper提供一些额外的功能，都在`src/helper/`目录下，使用方式参考`test/`下对应文件，\nHelper功能还在开发中，可能不太完善。\n\n- `structure` 获取vm中所有变量的结构: `$foo.bar` => `foo: {bar: 'string'}`\n- `backstep` vm逆推，根据velocity文件和解析后的结果，计算数据结构和内容\n- `jsonify` 把vm转换为json结构，去除其中的html标签，比如：\n\n```\nhello world $foo.name.\n=>\n{foo: { name: $foo.name }}\n```\n\n##License\n\n(The MIT License)\n\nCopyright (c) 2012-2013 Eward Song<eward.song@gmail.com>\n\nPermission is hereby granted, free of charge, to any person obtaining a copy of\nthis software and associated documentation files (the 'Software'), to deal in\nthe Software without restriction, including without limitation the rights to\nuse, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of\nthe Software, and to permit persons to whom the Software is furnished to do so,\nsubject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS\nFOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR\nCOPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER\nIN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN\nCONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n","_id":"velocity.js@0.3.2","dist":{"shasum":"6bdfd6d59bacda8eefadce26fb129c2ea5598078","tarball":"https://registry.npmjs.org/velocity.js/-/velocity.js-0.3.2.tgz","integrity":"sha512-eBR7T2Wp4w/gbjzhZjQsKxUgoUyc7MKq99eq2dr0nC353qLmeaqDFCrviEhGqtWzHnOLfMF0cuq6neND+xyYAg==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQCA4o/fdUrRjER2cO9xdTHukYJFR9C05ZTQGLszlvc53QIgHagLAAiJsEqmt/IE8QXD6jYoTC5q7U4+s7cKJ59jt7k="}]},"_npmVersion":"1.1.62","_npmUser":{"name":"shepherdwind","email":"eward.song@gmail.com"},"maintainers":[{"name":"shepherdwind","email":"eward.song@gmail.com"}]},"0.3.4":{"name":"velocity.js","description":"Velocity Template Language(VTL) for JavaScript","version":"0.3.4","keywords":["velocity template"],"homepage":"http://git.shepherdwind.com/velocity.js/","repository":{"type":"git","url":"git://github.com/shepherdwind/velocity.js.git"},"engines":{"node":">=0.8.0"},"main":"src/velocity.js","bin":{"velocity":"bin/velocity"},"devDependencies":{"mocha":">=1.7.2","jison":">=0.3","coffee-script":">=1.4.0"},"scripts":{"test":"make test"},"readme":"##Velocity - Template Engine [![Build Status](https://secure.travis-ci.org/shepherdwind/velocity.js.png)](https://travis-ci.org/shepherdwind/velocity.js)\n\n*注意*\n\nvelocityjs在npm中包名从原来的`velocity.js`改为`velocityjs`，感觉`require(\"velocity.js\")`\n比较不好看，所以改名，从`0.3.0`之后的版本都在`velocityjs`下更新。\n\n查看最新版本\n\n```bash\n$ npm info velocityjs version\n```\n\nvelocity.js是velocity模板语法的javascript实现。\n[Velocity](http://velocity.apache.org/) 是基于Java的模板引擎，广泛应用在阿里集\n体各个子公司。Velocity模板适用于大量模板使用的场景，支持复杂的逻辑运算，包含\n基本数据类型、变量赋值和函数等功能。\n\n\n##Features\n\n- 支持客户端和服务器端使用\n- 语法是富逻辑的，构成门微型的语言\n- 语法分析和模板渲染分离\n- 基本完全支持velocity语法\n- 浏览器使用支持模板之间相互引用，依据js模块加载机制，比如kissy\n- 三个Helper，友好的数据模拟解决方案\n- [Vim Syntax](https://github.com/shepherdwind/vim-velocity)\n\n##Install\n\nvia npm:\n\n```bash\n$ npm install velocityjs\n```\n\n##Broswer Support\n\n兼容ie6+，chrome等其他浏览器，[test case](http://shepherdwind.com/velocity/runner/tests.html)\n\n点击[此处](http://shepherdwind.com/velocity/try/index.html)可以体验web\n端velocity语法解析过程，注：使用ACE作为代码编辑器，仅支持高级浏览器访问。\n\n执行`cake`命令进行打包velocity.js浏览器端脚本:\n\n```bash\n$ make parse\n```\n\n需要cli下安装coffeejs，暂时打包是为kissy所使用的，velocity.js需要的一些常用的\necma5功能，比如`foreach, some, isArray`等，在node环境下是自带的功能，而web端的兼\n容是交给已有的类库解决。需要自行提供一组跨浏览器的api，比如kissy打包：\n\n```js\n  //api map\n  var utils = {\n    forEach : S.each,\n    some    : S.some,\n    mixin   : S.mix,\n    guid    : S.guid,\n    isArray : S.isArray,\n    indexOf : S.indexOf,\n    keys    : S.keys,\n    now     : S.now\n  };\n\n```\n\nVelocity语法具有很高的容错能力，类似于html结构的解析，同时语法规则复杂，所以语法\n解释器执行性能可能比较慢，`velocity.js`把语法结构分析运算和语法执行两个过程独立出来，\n第一步，语法结构分析返回一个数组(语法树)，描述velocity语法，语法执行使用数据和语\n法树，计算模板最终结果。\n\n执行build后，得到两个文件，分别是`build/velocity/`下的`index.js`和`parse.js`，两者\n相互独立，`parse.js`语法分析过程可以放在本地完成，执行命令：\n\n把语法分析和模板拼接分开，为了方便在本地编译语法树，减少在web端js运算。本地编译\n模板的思路，源自KISSY的[xtemplate](http://docs.kissyui.com/docs/html/api/component/xtemplate/)。\n\n虽然语法解释器可以在浏览器端执行，但是，不推荐那么使用。\n\n```bash\n#使用velocity命令行工具打包\nveloctiy --build *.vm\nveloctiy -b *.vm\n```\n\n源码中`test/web/`目录的js，一部分就是线下编译后的得到的，此处可[直接访问](http://shepherdwind.com/velocity/web/index.html)。\n\n##Public API\n\n###node_module\n\n```js\nvar Velocity = require('../src/velocity');\n\n//1. 直接解析\nVelocity.render('string of velocity', context);\n\n//2. 使用Parser和Compile\nvar Parser = Velocity.Parser;\nvar Compile = Velocity.Compile;\n\nvar asts = Parser.parse('string of velocity');\n(new Compile(asts)).render(context);\n```\n####context\n\n`context`是一个对象，可以为空，执行中`$foo.bar`，访问路径是`context.foo.bar`，\n`context`的属性可以是函数，和vm中定义保持一致。\n\n###On Broswer\n\n1 . 使用线下打包方案：\n\n```js\nKISSY.use('velocity/index, web/directives', function(S, Velocity, asts){\n  var compile = new Velocity(asts);\n  S.all('body').html(compile.render());\n});\n```\n\n2 . 使用线上编译：\n\n```js\nKISSY.use('velocity/index, velocity/parse', function(S, Velocity, Parser){\n  var html = (S.all('#tpl').html());\n  var asts = Parser.parse(html);\n  var compile = new Velocity(asts);\n  console.log(compile.render());\n});\n```\n\n两者的区别在于asts的获取，第一种方式，直接取asts，第二种，需要首先执行语法分析过\n程。\n\n##Syntax\n\n具体语法请访问官网文档：[velocity user guide](http://velocity.apache.org/engine/devel/user-guide.html)。\n\n###Directives\n\nDirectives支持`set`, `foreach`, `if|else|elseif`, `macro`, `parse`, `break`。不\n支持有，`stop`, `evaluate`, `define`，感觉这些语法比较偏，用处不大，暂时没有实现。\n其中`parse`，在web端，使用kissy的模块加载器加载，需要首先线下编译打包，[例子](http://shepherdwind.com/velocity/web/index.html)。\n\n###macro\n\n宏分为系统的宏，比如`parse, include`，和用户自定义宏，通过`#macro`在vm中定义，此\n外可以使用自定义的js函数替代在vm中定义。对于系统宏和自定义宏，不做区分，对于\n`#parse`和`#include`的调用，可以使用自定义函数来执行。具体见[issue #3](https://github.com/shepherdwind/velocity.js/issues/3)。\n\n###foreach\n\nforeach在velocity中对对象的遍历，和js有区别，java中对象是一个map，需要通过方法\n`keyset`来获取map中的key，foreach循环写法等同于js的for in循环，感觉有点怪异。在\n一个foreach，有一个`$foreach`的对象可以使用，此变量作用域为当前循环范围。\n\n```\n#foreach($num in [1..5])\n  index => $foreach.index \n  count => $foreach.count\n  #if (!$foreach.hasNext) end #end\n#end\n结果：\nindex => 0\ncount => 1\n\nindex => 1\ncount => 2\n...\nindex => 4\ncount => 5\nend\n```\n\n###string\n\nvelocity中字符串求值和php类似，双引号字符串里面的变量会被替换变量对应的值，单引\n号原样返回，推荐尽量使用单引号，那样性能好一些。此外，双引号中变量替换，没有再次\n调用语法分析器，而是使用正则，只支持简单的引用替换，比如`\"$varname1 $foo.bar\"`，\n`\"$foo.bar[1] $foo.bar()\"`都不支持。如果需要完整支持字符串双引号，需要反复调用语\n法分析器，考虑到性能，基本引用基本够用了，vm本身支持强大的变量赋值，可以先赋值，\n在放入字符串，或者使用加法进行字符串拼接。\n\n在java中可能大量使用双引号方式，因为java对象无法自动转换类型，双引号做类型转换用，\n而在web端，js无此需要。\n\n###velocity\n\n```\nUsage: velocity [options] [file ...]\n\nOptions:\n\n  -h, --help         output usage information\n  -V, --version      output the version number\n  -b, --build        build .vm file to js ast module of kissy\n\nExample:\n\n  # parse vm file\n  $ velocity a.vm \n\n  # parse vm file with json data\n  $ velocity a.vm  a.json\n\n  # build asts module of kissy\n  $ velocity *.vm\n```\n\n##Helper\n\nHelper提供一些额外的功能，主要用于解决vm数据模拟问题。\n\n- `structure` 获取vm中所有变量的结构: `$foo.bar` => `foo: {bar: 'string'}`\n- `backstep` vm逆推，根据velocity文件和解析后的结果，计算数据结构和内容\n- `jsonify` 把vm转换为json结构，去除其中的html标签，比如：\n\njsonify文档[issue #11](https://github.com/shepherdwind/velocity.js/issues/11)\n\n```\nhello world $foo.name.\n=>\n{foo: { name: $foo.name }}\n```\n\n##License\n\n(The MIT License)\n\nCopyright (c) 2012-2013 Eward Song<eward.song@gmail.com>\n\nPermission is hereby granted, free of charge, to any person obtaining a copy of\nthis software and associated documentation files (the 'Software'), to deal in\nthe Software without restriction, including without limitation the rights to\nuse, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of\nthe Software, and to permit persons to whom the Software is furnished to do so,\nsubject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS\nFOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR\nCOPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER\nIN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN\nCONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n","_id":"velocity.js@0.3.4","dist":{"shasum":"d988611f59ccac0a612157ebc51dbbf3c2df3959","tarball":"https://registry.npmjs.org/velocity.js/-/velocity.js-0.3.4.tgz","integrity":"sha512-bWdFWHr70PCvcsH5ioGza+0yM3t88oOeHMaGGsVWTCHt/ysPvyOGo3fZt0ynRBXROxcDEHnLRIXfD0IPDAVNzA==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIBFD48tLV1MVRun9+KlmI/3YnjsdycpYNjyhdfmKfK6DAiEAi+PPCXkIXoBh0rsHVkOKbXxmBvzOQFtVHn77tyE8/1Y="}]},"_npmVersion":"1.1.62","_npmUser":{"name":"shepherdwind","email":"eward.song@gmail.com"},"maintainers":[{"name":"shepherdwind","email":"eward.song@gmail.com"}]}},"readme":"Velocity Template Language(VTL) for JavaScript\n---------------------------------------------\n\nJavaScript版本VTL，Velocity是基于Java的模板引擎，veloctiy.js是JS版本的实现，实现\n依据[velocity user guide](http://velocity.apache.org/engine/devel/user-guide.html)。\n","maintainers":[{"name":"shepherdwind","email":"eward.song@gmail.com"}],"time":{"modified":"2022-06-28T09:57:23.072Z","created":"2012-10-07T05:57:10.394Z","0.0.1":"2012-10-07T05:58:26.433Z","0.1.1":"2012-11-23T00:16:04.370Z","0.1.2":"2012-11-23T17:55:47.962Z","0.1.3":"2012-12-07T03:57:00.018Z","0.1.4":"2012-12-07T10:47:24.908Z","0.2.0":"2012-12-08T04:40:08.047Z","0.2.1":"2012-12-10T03:09:58.835Z","0.2.2":"2012-12-10T05:00:24.437Z","0.2.3":"2012-12-11T03:55:33.978Z","0.2.4":"2012-12-11T12:16:09.640Z","0.2.5":"2012-12-20T03:41:18.541Z","0.2.6":"2012-12-21T07:12:51.012Z","0.2.7":"2013-01-05T08:04:44.342Z","0.3.0":"2013-01-15T03:29:18.867Z","0.3.1":"2013-01-24T06:54:07.412Z","0.3.2":"2013-01-25T16:03:01.778Z","0.3.4":"2013-02-17T09:10:22.243Z"},"repository":{"type":"git","url":"git://github.com/shepherdwind/velocity.js.git"}}