`
badqiu
  • 浏览: 670387 次
  • 性别: Icon_minigender_1
  • 来自: 珠海
社区版块
存档分类
最新评论

扩展freemarker,velocity,实现模板的管道操作

阅读更多

操作系统中有一个很重要的功能,就是可以使用管道,即将前一个应用程序的输出流作为下一个应用程序的输入流. 现扩展的freemarker,velocity实现同样的功能。

一.功能介绍

 1.将前一个模板的输出,变成一个变量,后一个模板可以通过变量引用前一个模板的输出

 2.整个管道下的模板都在同一个context中,即模板间可以相互引用变量

 

二.管道定义表达式

 first.ftl | second.flt | three.flt

 

三.模板管道(Pipeline)示意图

管道示意图

 

四.API示例使用

Configuration conf = new Configuration();
//... other settings for Configuration
Pipeline pipeline = new FreemarkerPipeline(conf);
pipeline.pipeline("first.flt | second.flt | three.flt", map , writer);

五.管道与继承结合

将管道操作与我之前扩展的模板继承相结合,即可打造一个完美的页面布局框架.

管道+继承示意图如下:

管道+继承示意图

 

六.源代码

 请查看: http://rapid-framework.googlecode.com/svn/trunk/rapid-framework/src/rapid_framework_common/cn/org/rapid_framework/pipeline/

 

结论:

使用pipeline及继承相结合,目的是替换现有的布局工具:sitemesh,tiles,与sitemesh相比,现有的继承指令会比sitemesh的性能要高,继承的关系比tiles更加易于理解,打造一个适用于rapid-framework的全新页面布局系统.

 

以上相关内容属于rapid-framework下一版本的更新内容,请关注.

 

 

4
0
分享到:
评论
2 楼 azheng270 2011-04-09  
装饰器布局
<#macro workBenchHead title="" charset="utf-8" lang="zh-CN">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
        <#if title??><titlt>title</title></title></#if>
<#nested />
</head>
</#macro>
<#macro workBenchBody title>
<body>
<div>
<#nested />
</div>
</body>
</html>
</#macro>

被装饰页面
<#import "/decorators/MainDec.ftl" as dec />
<@dec.workBenchHead title="用户管理">
<script type="text/javascript" src="${app_context}/res/script/app/security/userManager.js"></script>
</@dec.workBenchHead>
<@dec.workBenchBody title="授权管理 - 用户管理">
body中的内容
</@dec.workBenchBody>

装饰后的页面代码
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<script type="text/javascript" src="${app_context}/res/script/app/security/userManager.js"></script>
</head>
<body>
<div>
body中的内容
</div>
</body>
</html>
我是通过2个宏来实现的, 对我来说, 任何页面就是装饰head和body,参数什么的可以修改装饰器模板的宏定义, head和body的输出,其实就是<#nested />的内容
1 楼 wutao8818 2010-04-23  
类似 django 的 模板模式,我也觉得这个模式很好,只是能力有限,没有做到。

Great Work . Thx! 

相关推荐

Global site tag (gtag.js) - Google Analytics