public class DecoratorHelper<T> extends BasicSectionHelper
MustacheEngine engine = MustacheEngineBuilder.newBuilder()
.registerHelper("decorateStr",
decorate(String.class).compute("reverse", s -> new StringBuilder(s).reverse().toString()).build())
.build();
engine.compileMustache("{{#decorateStr}}{{reverse}}{{/decorateStr}}").render("Foo");
By default, the helper throws IllegalStateException if the runtime
class of the context object is not assignable to the delegate type. A custom
predicate can be used but beware of generics pitfalls and
ClassCastExceptions.
Note that ReflectionResolver and MapResolver must be
registered in order to make it work.
| Modifier and Type | Class and Description |
|---|---|
static class |
DecoratorHelper.Builder<T> |
SECTION_TYPESHELPER_TAG_TYPESconfiguration| Modifier and Type | Method and Description |
|---|---|
static <T> DecoratorHelper.Builder<T> |
decorate(Class<T> delegateType)
Returns a decorator helper builder for the specified delegate type.
|
static <T> DecoratorHelper.Builder<T> |
decorate(Predicate<Object> test)
Returns a decorator helper builder with the specified predicate used to test
a context object.
|
void |
execute(Options options)
Execute the helper.
|
protected int |
numberOfRequiredParameters() |
allowedTagTypesgetRequiredHashKeys, getSupportedHashKeys, numberOfRequiredHashEntries, validateappend, convertAndAppend, convertValue, init, isSection, isUnescapeVariable, isVariablecheckNotInitialized, initclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitgetConfigurationKeys, initpublic static <T> DecoratorHelper.Builder<T> decorate(Class<T> delegateType)
delegateType - public static <T> DecoratorHelper.Builder<T> decorate(Predicate<Object> test)
delegateType - public void execute(Options options)
Helperprotected int numberOfRequiredParameters()
numberOfRequiredParameters in class BasicHelperCopyright © 2020. All rights reserved.