@Retention(value=RUNTIME) @Target(value={METHOD,TYPE}) public @interface Transformer
Transformer could be used to annotate on a public static methods that works on a given object with or without parameters. For example,
@Transformer public static String format(Number number, String formatStr) When feature.transformer.enabled is set to true (by default it is true), template author can use Transformer to further process an expression value:
@args Date dueDate\n…@dueDate.format(“dd/MM/yyyy”) The @dueDate.format(“dd/MM/yyyy”) in the above example will be transformed into S.format(dueDate, “dd/MM/yyyy”) in the generated java source
Note, the above sample code demonstrates a transformer named format, which is built into Rythm engine. However when you want to define your own transformer, you need to use this Transformer annotation to mark on your methods or classes. When the annotation is marked on a class, then all public static methods with return value and at least one parameter will be treated as transformer
You can register them to RythmEngine by RythmEngine.registerTransformer(Class[]) method
true Transformers mechanism is also found in other template engine solutions, but with different names. Freemarker call it built-ins, Velocity called it velocity tools. But none of them are as easy to use as Rythm Transformers
| Modifier and Type | Optional Element and Description |
|---|---|
boolean |
lastParam
Indicate whether the expression been transformed should be passed to the transformer function as first or last param
|
boolean |
requireTemplate
Require passing
template instance as implicit argument (the first parameter) |
String |
value
The namespace of the transformer.
|
String |
waivePattern
Once specified the pattern will be used to match the token to see if transformer extension should be waived or not.
|
public abstract String value
The namespace of the transformer. When namespace is presented, the template author needs to use the namespace to qualify the transformer in the template source. For example, @x.app_myTransformer()
Default value: "app"
public abstract String waivePattern
Once specified the pattern will be used to match the token to see if transformer extension should be waived or not. For example, @x.escape() should be treated as escape transformer while @s().escape(x) shouldn’t because s\(\) is a waive pattern
public abstract boolean requireTemplate
Require passing template instance as implicit argument (the first parameter)
Copyright © 2017–2021 OSGL (Open Source General Library). All rights reserved.