All templates compiled through groovy. extend this abstract class,
which provides a number of utility methods to generate markup. An instance of this class can be obtained
after calling groovy. or groovy.)} on
a template generated by groovy..
It is advised to use a distinct template instance for each thread (or more simply, each rendered document) for thread safety and avoiding mixing models.
For the application needs, it is possible to provide more helper methods by extending this class and
configuring the base template class using the groovy.
method.
| Modifier and Type | Class and Description |
|---|---|
| private static class |
| Modifier and Type | Field and Description |
|---|---|
| private final Map | |
| private final TemplateConfiguration | |
| private boolean | |
| private static final Map | |
| private final MarkupTemplateEngine | |
| private final Map | |
| private final Map | |
| private Writer |
| Access | Constructor and Description |
|---|---|
| public | BaseTemplate(final MarkupTemplateEngine templateEngine, final Map<K, V> model, final Map<String, String> modelTypes, final TemplateConfiguration configuration)
|
| Modifier and Type | Method and Description |
|---|---|
| public BaseTemplate | Returns: this template instance.the object to be rendered inside an XML comment block. cs)Renders the supplied object using its |
| public Closure | |
| private Writer | |
| private String | |
| private Map | |
| public Object | |
| public Map | |
| public Writer | |
| public void | includeEscaped(String
the path to the other file templatePath)Includes contents of another file, not as a template but as escaped text. |
| public void | includeGroovy(String
the path to the included resource. templatePath)Includes another template inside this template. |
| public void | includeUnescaped(String
the path to the other file templatePath)Includes contents of another file, not as a template but as unescaped text. |
| public Object | |
| public Object | Returns: this template instancemodel to be passed to the template model, String the name of the template to be used as a layout templateName, boolean a boolean indicating if we should inherit the parent model inheritModel)Imports a template and renders it using the specified model, allowing fine grained composition of templates and layouting. |
| public Object | Returns: this template instancethe name of the tag tagName, Object tag generation arguments args)This is the main method responsible for writing a tag and its attributes. |
| public void | |
| public BaseTemplate | |
| public abstract Object | |
| public String | |
| public String | |
| public Object | Returns: an escaped string, or the object itselfan object to be escaped for XML contents)Escapes the string representation of the supplied object if it derives from |
| private void | |
| private void | |
| private void | |
| private void | |
| private void | |
| public Writer | Returns: a writer instancethe Writer to which this Writable should output its data. out)Implements groovy. Main method used to render a template. |
| public BaseTemplate | |
| public BaseTemplate | Returns: this template instancethe object to be rendered obj)Renders the object provided as parameter using its |
| public BaseTemplate | Returns: this template instancethe object to be rendered unescaped obj)Renders the object provided as parameter using its |
| cachedFragments | back to summary |
|---|---|
| private final Map<String, Template> cachedFragments | |
| configuration | back to summary |
|---|---|
| private final TemplateConfiguration configuration | |
| doWriteIndent | back to summary |
|---|---|
| private boolean doWriteIndent | |
| EMPTY_MODEL | back to summary |
|---|---|
| private static final Map<K, V> EMPTY_MODEL | |
| engine | back to summary |
|---|---|
| private final MarkupTemplateEngine engine | |
| model | back to summary |
|---|---|
| private final Map<K, V> model | |
| modelTypes | back to summary |
|---|---|
| private final Map<String, String> modelTypes | |
| out | back to summary |
|---|---|
| private Writer out | |
| BaseTemplate | back to summary |
|---|---|
| public BaseTemplate(final MarkupTemplateEngine templateEngine, final Map<K, V> model, final Map<String, String> modelTypes, final TemplateConfiguration configuration) | |
| comment | back to summary |
|---|---|
| public BaseTemplate comment(Object cs) throws IOException Renders the supplied object using its
| |
| contents | back to summary |
|---|---|
| public Closure Wraps a closure so that it can be used as a prototype for inclusion in layouts. This is useful when you want to use a closure in a model, but that you don't want to render the result of the closure but instead call it as if it was a specification of a template fragment. | |
| createWriter | back to summary |
|---|---|
| private Writer createWriter(final Writer out) | |
| escapeQuotes | back to summary |
|---|---|
| private String escapeQuotes(String str) | |
| forkModel | back to summary |
|---|---|
private Map
| |
| fragment | back to summary |
|---|---|
| public Object fragment(Map<K, V> model, String templateText) throws IOException, ClassNotFoundException Renders an embedded template as a fragment. Fragments are cached in a template, meaning that
if you use the same fragment in a template, it will only be compiled once, but once per template
instance. This is less performant than using | |
| getModel | back to summary |
|---|---|
| public Map | |
| getOut | back to summary |
|---|---|
| public Writer getOut() Convenience method to return the current writer instance.
| |
| includeEscaped | back to summary |
|---|---|
| public void includeEscaped(String templatePath) throws IOException Includes contents of another file, not as a template but as escaped text.
| |
| includeGroovy | back to summary |
|---|---|
| public void includeGroovy(String templatePath) throws IOException, ClassNotFoundException Includes another template inside this template.
| |
| includeUnescaped | back to summary |
|---|---|
| public void includeUnescaped(String templatePath) throws IOException Includes contents of another file, not as a template but as unescaped text.
| |
| layout | back to summary |
|---|---|
| public Object layout(Map<K, V> model, String templateName) throws IOException, ClassNotFoundException Imports a template and renders it using the specified model, allowing fine grained composition
of templates and layouting. This works similarily to a template include but allows a distinct
model to be used. This version doesn't inherit the model from the parent. If you need model
inheritance, see | |
| layout | back to summary |
|---|---|
| public Object layout(Map<K, V> model, String templateName, boolean inheritModel) throws IOException, ClassNotFoundException Imports a template and renders it using the specified model, allowing fine grained composition of templates and layouting. This works similarily to a template include but allows a distinct model to be used. If the layout inherits from the parent model, a new model is created, with the values from the parent model, eventually overridden with those provided specifically for this layout. | |
| methodMissing | back to summary |
|---|---|
| public Object methodMissing(String tagName, Object args) throws IOException This is the main method responsible for writing a tag and its attributes. The arguments may be:
or a combination of (attributes,string), (attributes,closure) | |
| newLine | back to summary |
|---|---|
| public void newLine() throws IOException Adds a new line to the output. The new line string can be configured by
| |
| pi | back to summary |
|---|---|
| public BaseTemplate pi(Map<?, ?> attrs) throws IOException Renders processing instructions. The supplied map contains all elements to be rendered as processing instructions. The key is the name of the element, the value is either a map of attributes, or an object to be rendered directly. For example:
pi("xml-stylesheet":[href:"mystyle.css", type:"text/css"])
will be rendered as:
<?xml-stylesheet href='mystyle.css' type='text/css'?>
| |
| run | back to summary |
|---|---|
| public abstract Object run() | |
| stringOf | back to summary |
|---|---|
| public String stringOf(Closure<V> cl) throws IOException | |
| toString | back to summary |
|---|---|
| public String toString() Overrides java. Doc from java. Returns a string representation of the object.
Satisfying this method's contract implies a non-
| |
| tryEscape | back to summary |
|---|---|
| public Object tryEscape(Object contents) Escapes the string representation of the supplied object if it derives from | |
| writeAttribute | back to summary |
|---|---|
| private void writeAttribute(String attName, String value) throws IOException | |
| writeAttributes | back to summary |
|---|---|
| private void writeAttributes(final Map<?, ?> attributes) throws IOException | |
| writeBody | back to summary |
|---|---|
| private void writeBody(final Object body) throws IOException | |
| writeIndent | back to summary |
|---|---|
| private void writeIndent() throws IOException | |
| writeQt | back to summary |
|---|---|
| private void writeQt() throws IOException | |
| writeTo | back to summary |
|---|---|
| public Writer writeTo(final Writer out) throws IOException Implements groovy. Main method used to render a template.
| |
| xmlDeclaration | back to summary |
|---|---|
| public BaseTemplate xmlDeclaration() throws IOException Renders an XML declaration header. If the declaration encoding is set in the
| |
| yield | back to summary |
|---|---|
| public BaseTemplate yield(Object obj) throws IOException Renders the object provided as parameter using its
| |
| yieldUnescaped | back to summary |
|---|---|
| public BaseTemplate yieldUnescaped(Object obj) throws IOException Renders the object provided as parameter using its
| |
| Modifier and Type | Field and Description |
|---|---|
| private final Object[] | |
| private Map | |
| private Object |
| Modifier and Type | Method and Description |
|---|---|
| public Map | |
| public Object | |
| public BaseTemplate. |
| array | back to summary |
|---|---|
| private final Object[] array | |
| attributes | back to summary |
|---|---|
| private Map<K, V> attributes | |
| body | back to summary |
|---|---|
| private Object body | |
| TagData | back to summary |
|---|---|
| public TagData(final Object args) | |
| getAttributes | back to summary |
|---|---|
| public Map | |
| getBody | back to summary |
|---|---|
| public Object getBody() | |
| invoke | back to summary |
|---|---|
| public BaseTemplate. | |