fool2fish / velocity Goto Github PK
View Code? Open in Web Editor NEWA node velocity template engine. Node 版 velocity 模板引擎。
A node velocity template engine. Node 版 velocity 模板引擎。
ATT
我想通过gulp的watch方法,发现vm或者context有改变时,重新渲染vm,实现自动化;
但是context是require进来的,改变后也没法获取到。
是否可以改变下这块的逻辑?
As captioned
听说有java版的,where?~
页面怎么使用?引用哪个js文件 ?能否给个完整的demo?
input:
$a
$b
$b.c[0]
$b.c[$d].e
$f.h($a).i
^ return of method won't go further
output:
{
a: '',
b: {
c:[{e: ''}]
},
f: {
h: function(){}
}
}
input:
$a.length()
$b.size()
$c.keySet()
$c.d
output:
{
a: '',
b: [],
c: {d: ''}
}
input:
#set($a = 1)
#set($b = $c.d)
$b.e
ouput:
module.exports = {
c: {
d: {
e: ''
}
}
}
input:
#foreach($employee in $employeeList)
$foreach.index: $employee.name - $employee.email
#end
ouput:
{
employeeList: [
{
name: '',
email: ''
}
]
}
input:
## file a.vm
#parse('path/to/b.vm')
## file b.vm
$a
output:
{
a: ''
}
input:
#define($userInfo)
$user.name
$user.email
#end
$userInfo
output:
{
user: {
name: '',
email: ''
}
}
input:
#macro(hello $user)
Welcome, $user.name !
#end
#hello($employee)
output:
module.exports = {
employee: {
name: ''
}
}
#set($f = {$g: $h})
$f[$g].i // any property of $f won't be handled
#set($j = [$k])
$j[0].l // any property of $j won't be handled
<button ng-click="$ctrl.method(item)">Click</button>
在method后边的括号位置报错
我没用明白,只能解析vm输出到console吗?
不能在浏览器里预览没什么用啊
好像没有提到怎么使用layout,不知道支不支持呢?
when I was testing the #foreach, I found that #foreach not support object as input parameter, but according the velocity user guid -- Foreach Loop,"The contents of the $allProducts variable is a Vector, a Hashtable or an Array".
if #foreach not support the object as input parameter, we can not simulate data like "map" in context.js, eg.
#foreach( $key in $allProducts.keySet() )
<li>Key: $key -> Value: $allProducts.get($key)</li>
#end
is this a bug?
#set($list = [0 .. 10])
#foreach($item in $list)
$argInForeach
#end
$argInForeach should be recognized
when macro defined in template file,the macro call will give error of “Call undefined macro” except the first call, but it's ok when the macro is defined in global macro file!
code:
#macro(Mtest,$a)
<tr>
<td>$!a</td>
</tr>
#end
#Mtest('hello')
#Mtest('world')
but when the macro is defined in global macro file, it is ok.
is this a bug?
context提供json的支持
I stumbled across this because someone on my team seems to have (accidentally) installed the 'vm' package which is here: https://www.npmjs.com/package/vm
It redirects to this github repo but it appears to be basically dead, and the bin file is simply console.log('Place holder').
Should it be taken down from npm?
应该是 $ cd examples 然后才是 $ cd hello
js 中 a 变量为null
在模板中使用
$!a
正确的方式是输出空,但是实际输出了 null
undefined的处理没问题
Length of params not must be equal with the length of arguments.
below is library.vm:
#macro(render $subchannel)
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<style tyle="text/css">
## 页面css
$!q_css
</style>
</head>
<body>
## 页面html
$!q_body
## 页面js
$!q_js
</body>
</html>
#end
{code}
below is index.vm:
#define( $q_css )
body{background:green;}
#end
#define( $q_body )
hello word!
#end
#define( $q_js )
<script>
var nimei = "nimei";
</script>
#end
#render('hotel')
在java里,render index.vm能输出$q_js,$q_css,$q_body,这样也是比较合理的
在engine-ref.js里
Reference: function(node) {
// call define
if (common.isId(node)) {
var name = node.object.name
if (name in this.template.__define) {
var def = this.template.__define[name]
var result = this[def.type](def)
if (result.stats !== STATS.SUCCESS) {
// at where the #define is called
result.stack.push(common.getRealLoc([this.template, node.pos]))
}
return result
}
}
是不是做成 return this.template._define[xxx] <- this.template.__parent.__define这样逐层查找比较合理,且和java更加吻合
eg. $_ref
this is legal in some editions and not in others.
比如
template/vm
├── inc.vm
└── index.vm
在index.vm中
#parse("./inc.vm")
提示
#parse("inc.vm")
^^^^^^^^
Error: Param of #parse not exists or is not subpath of root.
at /Users/leeluolee/code/wdp/test/template/vm/index.vm (16:7)
必须传入root参数?
Error: Lexical error on line 8. Unrecognized text.
...avStatus[0] == "m1" and $navStatus[1] ==
在判断真假时使用and报错
#set($isInsuDisable = $!{appointmentVO.oldMan}&&$!{$productXTypeChild.productXTypeCode}=='INSU')
Error: Lexical error on line 19. Unrecognized text.
...ointmentVO.oldMan}&&$!{$productXTypeChil
-----------------------^
lex改不来……这工具不熟悉……
require('util').inspect
won't output the proper string of function when writes a object to a file.
Are you about to write a gulp-velocity plugin for it ? that will do benefit for more coding guys.
Besides I noticed that someone in your company also write a node module named "velocityjs", what's the difference?
Context
{
method: {
// defined by hand
foo: function() { return true },
// definition reduced from template
bar: function() { return this.__barReturn },
__barReturn: true
}
}
Intermediate code
{
method: {
__stats: CERTAIN,
__value: {
foo: {
__stats: CERTAIN_FUNC,
__value: function() {return true}
},
bar: {
__stats: CERTAIN_FUNC,
__return: {
__stats: CERTAIN,
__value: true
},
argc: 0
}
}
}
}
Input
$method.foo($arg).bar().prop
Intermediate code
{
method: {
__stats: CERTAIN,
__value: {
foo: {
__stats: CERTAIN_FUNC,
__argc: 1,
__return: {
__stats: CERTAIN,
__value: {
bar: {
__stats: CERTAIN_FUNC,
__argc: 0,
__return: {
prop: {
__stats: UNCERTAIN
}
}
}
}
}
}
}
}
}
Output
{
method: {
foo: function(a) { return this.__fooReturn },
__fooReturn: {
bar: function() { return this.__barReturn },
__barReturn: {
prop: ''
}
}
}
}
$a
#set($a =3)
$a
$a
输出:
113
期待:
133
when use '' escape, according the the velocity user guid -- Advanced Issues: Escaping and ! render result should be:
the code:
================test begin======
#set($foo="abc")
#set($id=1)
#set($bar="${foo}${id}")
#set($dar_1="${goo}${id}")
#set($dar_2="$!{goo}${id}")
##goo is undefined
output goo: $goo
output bar:$bar
output dar_1:$dar_1
output dar_2:$dar_2
================test end======
the $dar_1 render result is not "$goo1", instead it is strange string of this template file begin contents "======1".
is this a bug?
.
问题描述:
有两个模版文件 a.vm 和 b.vm, 前者定义了一个 macro ,后者通过 parse 指令解析前者并调用其定义的 macro
在 java 版中这样做是可以的,node 版会报 macro 未定义的错误
I'm the first one to write in english, hooray!
I noticed that even if the line is pure logic, it still outputs an empty line, is there a way to avoid it?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.