public class AlternativesHelper extends BasicHelper
Object.toString() value or if no such object
exists renders the output of
MissingValueHandler.handle(org.trimou.engine.MustacheTagInfo)
If no AlternativesHelper.Selector instance is declared the default behavior is: take the
first parameter matching the condition (by default not null or not empty for
an instance of String).
In some situations a more appropriate name could be used - the user is free
to register this helper with any name - see also
MustacheEngineBuilder.registerHelper(String, Helper).
It's useful to specify default values:
Username: {{alt username "Joe"}}
The number of parameters is not limited:
Call me {{alt user.name user.nick "Joe"}}!
A custom AlternativesHelper.Selector might be used to change the default behavior. See
for example AlternativesHelper.MinSelector and HelpersBuilder.addMin():
{{min item1.price item2.price}}
HelpersBuilder.addAlt()| Modifier and Type | Class and Description |
|---|---|
static class |
AlternativesHelper.ConditionSelector
Selects the first parameter matching the condition (by default not null
or not empty for an instance of
String). |
static class |
AlternativesHelper.MaxSelector
Attempts to select the maximal value from the parameters.
|
static class |
AlternativesHelper.MinSelector
Attempts to select the minimal value from the parameters.
|
static interface |
AlternativesHelper.Selector
Selects one object from the set of alternatives.
|
HELPER_TAG_TYPESconfiguration| Constructor and Description |
|---|
AlternativesHelper()
Constructs the default version of the helper using
AlternativesHelper.ConditionSelector with the default condition. |
AlternativesHelper(AlternativesHelper.Selector selector) |
| Modifier and Type | Method and Description |
|---|---|
void |
execute(Options options)
Execute the helper.
|
void |
validate(HelperDefinition definition)
Helper should validate the tag definition (e.g. number of parameters)
during compilation and fail fast if necessary.
|
allowedTagTypes, getRequiredHashKeys, getSupportedHashKeys, numberOfRequiredHashEntries, numberOfRequiredParametersappend, convertAndAppend, convertValue, init, isSection, isUnescapeVariable, isVariablecheckNotInitialized, initclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitgetConfigurationKeys, initpublic AlternativesHelper()
AlternativesHelper.ConditionSelector with the default condition.public AlternativesHelper(AlternativesHelper.Selector selector)
selector - public void execute(Options options)
Helperpublic void validate(HelperDefinition definition)
HelperMustacheException with code
MustacheProblem.COMPILE_HELPER_VALIDATION_FAILURE should be
thrown in case of validation failure occurs.validate in interface Helpervalidate in class BasicHelperCopyright © 2017. All rights reserved.