@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
@x.app_myTransformer()
Default value: "app"
public abstract String waivePattern
public abstract boolean requireTemplate
template
instance as
implicit argument (the first parameter)public abstract boolean lastParam
Copyright © 2015. All Rights Reserved.