java.lang.Object
com.samskivert.mustache.Mustache.Compiler
- Enclosing class:
Mustache
Compiles templates into executable form. See
Mustache.-
Field Summary
FieldsModifier and TypeFieldDescriptionfinal Mustache.CollectorThe collector used by templates compiled with this compiler.final com.samskivert.mustache.Mustache.DelimsThe delimiters used by default in templates compiled with this compiler.final booleanIf this value is true, empty string will be treated as a false value, as in JavaScript mustache implementation.final Mustache.EscaperHandles escaping characters in substituted text.final Mustache.FormatterHandles converting objects to strings when rendering a template.final Mustache.TemplateLoaderThe template loader in use during this compilation.final booleanIf this value is true, missing variables will be treated like variables that return null.final StringA value to use when a variable resolves to null.final booleanWhether or not standards mode is enabled.final booleanWhether or not to throw an exception when a section resolves to a missing value.final booleanIf this value is true, zero will be treated as a false value, as in JavaScript mustache implementation. -
Method Summary
Modifier and TypeMethodDescriptionCompiles the supplied template into a repeatedly executable intermediate form.Compiles the supplied template into a repeatedly executable intermediate form.computeNullValue(String name) Returns the value to use in the template for the null-valued propertyname.defaultValue(String defaultValue) Returns a compiler that will use the given value for any variable that is missing, or otherwise resolves to null.emptyStringIsFalse(boolean emptyStringIsFalse) Returns a compiler that will treat empty string as a false value if parameter is true.escapeHTML(boolean escapeHTML) Returns a compiler that either does or does not escape HTML by default.booleanReturns true if the supplied value is "falsey".loadTemplate(String name) Loads and compiles the templatenameusing this compiler's configured template loader.Returns a compiler that will use the given value for any variable that resolves to null, but will still raise an exception for variables for which an accessor cannot be found.standardsMode(boolean standardsMode) Returns a compiler that either does or does not use standards mode.strictSections(boolean strictSections) Returns a compiler that throws an exception when a section references a missing value (true) or treats a missing value asfalse(false, the default).withCollector(Mustache.Collector collector) Returns a compiler configured to use the supplied collector.withDelims(String delims) Returns a compiler configured to use the supplied delims as default delimiters.withEscaper(Mustache.Escaper escaper) Configures theMustache.Escaperused to escape substituted text.withFormatter(Mustache.Formatter formatter) Configures theMustache.Formatterused to turn objects into strings.withLoader(Mustache.TemplateLoader loader) Returns a compiler configured to use the supplied template loader to handle partials.zeroIsFalse(boolean zeroIsFalse) Returns a compiler that will treat zero as a false value if parameter is true.
-
Field Details
-
standardsMode
public final boolean standardsModeWhether or not standards mode is enabled. -
strictSections
public final boolean strictSectionsWhether or not to throw an exception when a section resolves to a missing value. If false, the section is simply omitted (or included in the case of inverse sections). If true, aMustacheExceptionis thrown. -
nullValue
A value to use when a variable resolves to null. If this value is null (which is the default null value), an exception will be thrown. IfmissingIsNullis also true, this value will be used when a variable cannot be resolved.If the nullValue contains a substring
{{name}}, then this substring will be replaced by name of the variable. For example, if nullValue is?{{name}}?and the missing variable isfoo, then string?foo?will be used. -
missingIsNull
public final boolean missingIsNull -
emptyStringIsFalse
public final boolean emptyStringIsFalseIf this value is true, empty string will be treated as a false value, as in JavaScript mustache implementation. Default is false. -
zeroIsFalse
public final boolean zeroIsFalseIf this value is true, zero will be treated as a false value, as in JavaScript mustache implementation. Default is false. -
formatter
Handles converting objects to strings when rendering a template. The default formatter usesString.valueOf(java.lang.Object). -
escaper
Handles escaping characters in substituted text. -
loader
The template loader in use during this compilation. -
collector
The collector used by templates compiled with this compiler. -
delims
public final com.samskivert.mustache.Mustache.Delims delimsThe delimiters used by default in templates compiled with this compiler.
-
-
Method Details
-
compile
Compiles the supplied template into a repeatedly executable intermediate form. -
compile
Compiles the supplied template into a repeatedly executable intermediate form. -
escapeHTML
Returns a compiler that either does or does not escape HTML by default. Note: this overrides any escaper set viawithEscaper(com.samskivert.mustache.Mustache.Escaper). -
standardsMode
Returns a compiler that either does or does not use standards mode. Standards mode disables the non-standard JMustache extensions like looking up missing names in a parent context. -
strictSections
Returns a compiler that throws an exception when a section references a missing value (true) or treats a missing value asfalse(false, the default). -
defaultValue
Returns a compiler that will use the given value for any variable that is missing, or otherwise resolves to null. This is likenullValueexcept that it returns the supplied default for missing keys and existing keys that return null values. -
nullValue
Returns a compiler that will use the given value for any variable that resolves to null, but will still raise an exception for variables for which an accessor cannot be found. This is likedefaultValue(java.lang.String)except that it differentiates between missing accessors, and accessors that exist but return null.- In the case of a Java object being used as a context, if no field or method can be found for a variable, an exception will be raised.
- In the case of a
Mapbeing used as a context, if the map does not contain a mapping for a variable, an exception will be raised. If the map contains a mapping which maps tonull, thennullValueis used.
-
emptyStringIsFalse
Returns a compiler that will treat empty string as a false value if parameter is true. -
zeroIsFalse
Returns a compiler that will treat zero as a false value if parameter is true. -
withFormatter
Configures theMustache.Formatterused to turn objects into strings. -
withEscaper
Configures theMustache.Escaperused to escape substituted text. -
withLoader
Returns a compiler configured to use the supplied template loader to handle partials. -
withCollector
Returns a compiler configured to use the supplied collector. -
withDelims
Returns a compiler configured to use the supplied delims as default delimiters.- Parameters:
delims- a string of the formAB CDorA Dwhere A and B are opening delims and C and D are closing delims.
-
computeNullValue
Returns the value to use in the template for the null-valued propertyname. SeenullValuefor more details. -
isFalsey
Returns true if the supplied value is "falsey". IfemptyStringIsFalseis true, then empty strings are considered falsey. IfzeroIsFalseis true, then zero values are considered falsey. -
loadTemplate
Loads and compiles the templatenameusing this compiler's configured template loader. Note that this does no caching: the caller should cache the loaded template if they expect to use it multiple times.- Returns:
- the compiled template.
- Throws:
MustacheException- if the template could not be loaded (due to I/O exception) or compiled (due to syntax error, etc.).
-