簡化 velocity ?模板引擎:min-velocity
min-velocity 是一個專為代碼生成而定制的簡化 velocity 模板引擎。
目標:
以 velocity 1.7 為基礎, 裁剪出適合用作代碼生成的模板引擎
裁剪:
-
沒有event機制
-
沒有macro
-
沒有stop
-
沒有evaluate
-
沒有define
-
沒有break
改動:
-
requires jdk1.5+
-
默認情況下,不打印任何日志
-
默認采用classpath模板加載器而非文件系統模板加載器
-
default I/O encoding changed to UTF-8(from iso-8859-1)
-
對于#set指令,默認允許設置null值
-
默認打開resource cache
-
去掉了parser pool
-
#parse和#include標簽支持相對路徑
-
新增$ParseUtil.recParsing("xxx.vm").addParam("key", val)模板調用形式;相當于帶調用棧的#parse標簽,能用在當你需要每層遞歸的context都相互隔離的遞歸#parse的時候;也能支持相對路徑
-
可放置min-velocity.properties文件(可選)在classpath根路徑下,用于覆蓋velocity的各種默認屬性
-
min-velocity.properties可使用default.static.util.mappings屬性配置默認的靜態工具類,這 些工具類將被默認放入模板context中,可配置多個,如:default.static.util.mappings = ClassUtils:org.apache.commons.lang.ClassUtils
-
設置'stream.reference.rendering'開關(true/false),默認關閉; 開啟后,遇到reference是stream或reader的時候, 將讀取stream或reader中的內容做渲染而非簡單地toString渲染; 其中讀取stream或reader的buffer可通過'stream.reference.rendering.buffer.size'配置大小 (默認為1024個字符); 亦可通過'stream.reference.rendering.limit'選項設置能夠從流中讀取的最大字符數限制(默認為100000)
-
支持String模板渲染,即直接將模板內容以String形式傳入api進行渲染而不是只能選擇傳入一個模板路徑
-
新增index.out.of.bounds.exception.suppress選項,當設置為true時,模板中對數組或list進行的取值或設置操作將忽略index out of bounds異常