CommonTemplate导出模板所需变量结构

在velocity的邮件列表中收到下面的邮件:
[quote="Simon Gubler's EMail"]
Hi all

I have written a small tool that scanns velocity-files and extracts all called variables. It's a command-line tool, you can execute it like this:

java -jar TemplateAnalyzer.jar folder1 folder2 In folder1 are your velocity files to analyze, in folder2 the tool will generate velocity-files with the same name as in folder1 but only with the accessed variables as content.

I made it an sourceforge project so you can view the code. You can find the project here: http://sourceforge.net/projects/vmanalyzer. I don't know if anything like this already exists, I didn't find anything under sourceforge.

There are some things I would like to add in the future, like for example recursively scanning the velocity-files, but for now I hope it can be of use to you.

Simon Gubler
[/quote]

这个想法非常不错, 通过分析模板, 得知该模板需要哪些变量和属性.
CommonTemplate([url]http://www.commontemplate.org[/url])应该更容易做到, 只需通过访问者遍历所有指令表达式, 就可以识别出来
.
这样,可以输出propertites和xml两种格式的结构,如:
propertites格式输出:
user.name=
user.email=
xml格式输出:
<data>
<user>
<name></name>
<email></email>
</user>
</data>
这种结构将会有很多作用, 直接想到的就是:
在输出的结构内填上数据就能够进行模板独立测试.

独立测试功能一直列在计划中, 将和上面提到的功能一起实现.
将写一个简单ctlviewer.exe, 修改注册表文件关联, 当双击*.ctl时用此exe打开.
ctlviewer将读取测试数据执行模板, 将输出结果用IE打开.

测试数据可以单独放一个文件, 但读取可能不方便.
最好直接放在模板内, 用特殊的指令包含. 如:

$propdata
$!
user.name=testname
user.email=testemail
!$
$end

或者:
[code="xml"]
$xmldata
$!
<data>
<user>
<name>testname</name>
<email>testemail</email>
</user>
</data>
!$
$end
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值