CommonTemplate导出模板所需变量结构

在velocity的邮件列表中收到下面的邮件:
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


这个想法非常不错, 通过分析模板, 得知该模板需要哪些变量和属性.
CommonTemplate( http://www.commontemplate.org)应该更容易做到, 只需通过访问者遍历所有指令表达式, 就可以识别出来
.
这样,可以输出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

或者:
$xmldata
$!
<data>
    <user>
        <name>testname</name>
        <email>testemail</email>
    </user>
</data>
!$
$end
  

你可能感兴趣的:(数据结构,xml,velocity,IE,commontemplate)