- java.lang.Object
-
- com.samskivert.mustache.Mustache
-
public class Mustache extends java.lang.Object
Provides Mustache templating services.Basic usage:
String source = "Hello {{arg}}!"; Template tmpl = Mustache.compiler().compile(source); Map<String, Object> context = new HashMap<String, Object>(); context.put("arg", "world"); tmpl.execute(context); // returns "Hello world!"
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected static class
Mustache.AbstractPartialSegment
An abstract segment that is a template include.protected static class
Mustache.AbstractSectionSegment
A helper class for section-like segments.protected static class
Mustache.Accumulator
protected static interface
Mustache.BlockReplaceable
protected static class
Mustache.BlockSegment
A parent partial parameter using $ as the sigil.static interface
Mustache.Collector
Handles interpreting objects as collections.static class
Mustache.Compiler
Compiles templates into executable form.static interface
Mustache.CustomContext
Provides a means to implement custom logic for variable lookup.protected static class
Mustache.Delims
static interface
Mustache.Escaper
Handles escaping characters in substituted text.protected static class
Mustache.FauxSegment
static interface
Mustache.Formatter
Handles converting objects to strings when rendering templates.protected static class
Mustache.IncludedTemplateSegment
A segment that loads and executes a sub-template by spec called a partial.protected static class
Mustache.InvertedSegment
A segment that represents an inverted section.static interface
Mustache.InvertibleLambda
Handles lambdas that are also invoked for inverse sections..static interface
Mustache.Lambda
Handles lambdas.protected static class
Mustache.NamedSegment
A helper class for named segments.protected static class
Mustache.ParentTemplateSegment
A segment that loads and executes a parent template by spec called inheritance.protected static class
Mustache.Parser
protected static class
Mustache.SectionSegment
A segment that represents a section.protected static interface
Mustache.StandaloneSection
protected static class
Mustache.StringSegment
A simple segment that reproduces a string.static interface
Mustache.TemplateLoader
Handles loading partial templates.static interface
Mustache.VariableFetcher
Reads variables from context objects.protected static class
Mustache.VariableSegment
A segment that substitutes the contents of a variable.static interface
Mustache.Visitor
Used to visit the tags in a template without executing it.
-
Field Summary
Fields Modifier and Type Field Description protected static Mustache.Formatter
DEFAULT_FORMATTER
protected static Mustache.TemplateLoader
FAILING_LOADER
protected static int
MATCHING_END
protected static int
MATCHING_START
protected static char
NO_CHAR
Used when we have only a single character delimiter.protected static int
TAG
protected static int
TEXT
-
Constructor Summary
Constructors Modifier Constructor Description private
Mustache()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description protected static boolean
allowsWhitespace(char typeChar)
protected static Template
compile(java.io.Reader source, Mustache.Compiler compiler)
Compiles the supplied template into a repeatedly executable intermediate form.static Mustache.Compiler
compiler()
Returns a compiler that escapes HTML by default and does not use standards mode.(package private) static Template.Segment[]
indentSegs(Template.Segment[] _segs, java.lang.String indent, boolean _first, boolean _last)
Indents segments by indent.(package private) static Template.Segment[]
replaceBlockSegs(Template.Segment[] _segs, java.util.Map<java.lang.String,Mustache.BlockSegment> blocks)
protected static void
restoreStartTag(java.lang.StringBuilder text, Mustache.Delims starts)
protected static Template.Segment[]
trim(Template.Segment[] segs, boolean top)
-
-
-
Field Detail
-
TEXT
protected static final int TEXT
- See Also:
- Constant Field Values
-
MATCHING_START
protected static final int MATCHING_START
- See Also:
- Constant Field Values
-
MATCHING_END
protected static final int MATCHING_END
- See Also:
- Constant Field Values
-
TAG
protected static final int TAG
- See Also:
- Constant Field Values
-
NO_CHAR
protected static final char NO_CHAR
Used when we have only a single character delimiter.- See Also:
- Constant Field Values
-
FAILING_LOADER
protected static final Mustache.TemplateLoader FAILING_LOADER
-
DEFAULT_FORMATTER
protected static final Mustache.Formatter DEFAULT_FORMATTER
-
-
Method Detail
-
compiler
public static Mustache.Compiler compiler()
Returns a compiler that escapes HTML by default and does not use standards mode.
-
compile
protected static Template compile(java.io.Reader source, Mustache.Compiler compiler)
Compiles the supplied template into a repeatedly executable intermediate form.
-
trim
protected static Template.Segment[] trim(Template.Segment[] segs, boolean top)
-
indentSegs
static Template.Segment[] indentSegs(Template.Segment[] _segs, java.lang.String indent, boolean _first, boolean _last)
Indents segments by indent.- Parameters:
_segs
- segments to be cloned if indentation is neededindent
- the space to use for indent._first
- whether to append an indent on the first segment_last
- whether to append an indent on the last segment last empty newline (no character after \n).- Returns:
- cloned segments if changed
-
replaceBlockSegs
static Template.Segment[] replaceBlockSegs(Template.Segment[] _segs, java.util.Map<java.lang.String,Mustache.BlockSegment> blocks)
-
restoreStartTag
protected static void restoreStartTag(java.lang.StringBuilder text, Mustache.Delims starts)
-
allowsWhitespace
protected static boolean allowsWhitespace(char typeChar)
-
-