Socket
Socket
Sign inDemoInstall

velocityjs

Package Overview
Dependencies
0
Maintainers
1
Versions
76
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.4.6 to 0.4.7

dist/archive.zip

5

package.json
{
"name": "velocityjs",
"description": "Velocity Template Language(VTL) for JavaScript",
"version": "0.4.6",
"version": "0.4.7",
"keywords": [

@@ -29,4 +29,5 @@ "velocity template"

"spm": {
"main": "index.js"
"main": "index.js",
"buildArgs": "--skip fs,path"
}
}

96

README.md

@@ -6,8 +6,5 @@ Velocity - Template Engine

velocity.js是velocity模板语法的javascript实现。
[Velocity](http://velocity.apache.org/) 是基于Java的模板引擎,广泛应用在阿里集
体各个子公司。Velocity模板适用于大量模板使用的场景,支持复杂的逻辑运算,包含
基本数据类型、变量赋值和函数等功能。
[![NPM](https://nodei.co/npm/velocityjs.png?downloads=true&stars=true)](https://nodei.co/npm/velocityjs/)
在此,推荐一下沉鱼写的[velocity](https://github.com/fool2fish/velocity)。也是一个velocity模板的语法解释器,比我的写得好,错误处理很给力。
velocity.js是[velocity](http://velocity.apache.org/)模板语法的javascript实现。

@@ -17,7 +14,4 @@ ##Features

- 支持客户端和服务器端使用
- 语法是富逻辑的,构成门微型的语言
- 语法分析和模板渲染分离
- 基本完全支持velocity语法
- 浏览器使用支持模板之间相互引用,依据js模块加载机制,比如kissy
- 三个Helper,友好的数据模拟解决方案
- 基本完全支持velocity[语法](http://velocity.apache.org/engine/devel/user-guide.html)
- [Vim Syntax](https://github.com/shepherdwind/vim-velocity)

@@ -33,20 +27,26 @@

##Broswer Support
##Broswer
兼容ie6+,chrome等其他浏览器,[test case](http://git.shepherdwind.com/velocity.js/runner/tests.html)
兼容支持es5的浏览器,可以通过测试来验证[test case](http://git.shepherdwind.com/velocity.js/runner/tests.html)。
点击[此处](http://git.shepherdwind.com/velocity.js/try/index.html)可以体验web
端velocity语法解析过程,注:使用ACE作为代码编辑器,仅支持高级浏览器访问。
对于低端浏览器需要实现以下方法
虽然语法解释器可以在浏览器端执行,但是,不推荐那么用,后续不再打包浏览器版本。
1. Array.prototype的map, forEach, some, filter, every, indexOf
2. Date.now
3. Object.keys
##Examples
在tests目录下有大量的例子,node和浏览器下使用是一致的,另外,examples目录下有一个
最简单的例子。
##Public API
###node_module
文件组织通过CommonJS方式,对于浏览器,通过spm可以打包为cmd模块。
```js
var Velocity = require('../src/velocity');
var Velocity = require('velocityjs');
//1. 直接解析
Velocity.render('string of velocity', context);
Velocity.render('string of velocity', context, macros);

@@ -58,4 +58,5 @@ //2. 使用Parser和Compile

var asts = Parser.parse('string of velocity');
(new Compile(asts)).render(context);
(new Compile(asts)).render(context, macros);
```
####context

@@ -85,38 +86,2 @@

###string
velocity中字符串求值和php类似,双引号字符串里面的变量会被替换变量对应的值,单引
号原样返回,推荐尽量使用单引号,那样性能好一些。此外,双引号中变量替换,没有再次
调用语法分析器,而是使用正则,只支持简单的引用替换,比如`"$varname1 $foo.bar"`,
`"$foo.bar[1] $foo.bar()"`都不支持。如果需要完整支持字符串双引号,需要反复调用语
法分析器,考虑到性能,基本引用基本够用了,vm本身支持强大的变量赋值,可以先赋值,
在放入字符串,或者使用加法进行字符串拼接。
在java中可能大量使用双引号方式,因为java对象无法自动转换类型,双引号做类型转换用,
而在web端,js无此需要。
###velocity
```
Usage: velocity [options] [file ...]
Options:
-h, --help output usage information
-V, --version output the version number
-b, --build build .vm file to js ast module of kissy
Example:
# parse vm file
$ velocity a.vm
# parse vm file with json data
$ velocity a.vm a.json
# build asts module of kissy
$ velocity *.vm
```
##Questions

@@ -130,23 +95,8 @@

## 其他
推荐一下沉鱼写的[velocity](https://github.com/fool2fish/velocity)。
##License
(The MIT License)
Copyright (c) 2012-2013 Eward Song<eward.song at gmail.com>
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the 'Software'), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

@@ -54,3 +54,3 @@ module.exports = function(Velocity, utils){

return str ;
return str.replace(/\s+\n+/g, '\n');
},

@@ -57,0 +57,0 @@

@@ -254,2 +254,7 @@ var Velocity = require('../src/velocity')

it('#if not work', function(){
var vm = '#if($!css_pureui)hello world#end'
assert.equal('', render(vm))
})
it('#elseif & #else', function(){

@@ -566,9 +571,36 @@ var vm = '#if($foo < 5)Go North#elseif($foo == 8)Go East#{else}Go South#end'

assert.equal(render(vm).trim(), "6")
});
})
it('#30', function() {
var vm = '$foo.setName'
assert.equal(render(vm, { foo: { setName: "foo" }}).trim(), "foo")
});
});
})
})
describe('multiline', function(){
it('multiline: #set multiline', function(){
var vm = "$bar.foo()\n#set($foo=$bar)\n..."
assert.equal("$bar.foo()\n...", render(vm))
})
it('multiline: #if multiline', function(){
var vm = "$bar.foo()\n#if(1>0)\n...#end"
assert.equal("$bar.foo()\n...", render(vm))
})
it('multiline: #set #set', function(){
var vm = "$bar.foo()\n...\n#set($foo=$bar)\n#set($foo=$bar)"
assert.equal("$bar.foo()\n...\n", render(vm))
})
it('multiline: #if multiline #set', function(){
var vm = "$bar.foo()\n#if(1>0)\n#set($foo=$bar)\n...#end"
assert.equal("$bar.foo()\n...", render(vm))
})
it('multiline: #if multiline #set #end', function(){
var vm = "$bar.foo()\n#if(1>0)...\n#set($foo=$bar)\n#end"
assert.equal("$bar.foo()\n...\n", render(vm))
})
})
})
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc