操作系統中有一個很重要的功能,就是可以使用管道,即將前一個應用程序的輸出流作為下一個應用程序的輸入流. 現擴展的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下一版本的更新內容,請關注.