After looking at what would be the least disruptive thing to do, I
decided to try something simple first. As of change dad987b you can
now return a Function<String, String> for a {{#variable}} and this is
what will happen:
1. The enclosed text is evaluated and captured
2. Your function is called passing in the resulting text string
3. The return value of the function replaces the contents of the
{{#function}}.
There is a simple test called testSimpleLambda that shows the trivial
case of transforming one result into another:
{{#translate}}Hello{{/translate}}
{{#translate}}{{#translate}}Hello{{/translate}}{{/translate}}
becomes:
Hola
Hello
When translate lambda is defined as:
Function<String, String> translate = new Function<String,
String>() {
@Override
public String apply(String input) {
if (input.equals("Hello")) {
return "Hola";
} if (input.equals("Hola")) {
return "Hello";
}
return null;
}
};
This does introduce a new dependency on Guava. That might be overkill
for this case. Maybe I should just have my own Function interface? Too
bad I can't "extend interface if class is on the classpath". It is
possible to return other types from the Function as null is converted
to empty string and the results of the Function are evaluated with
String.valueOf() if it makes more sense to return another type.
Sam