Class ModelBuilder
- java.lang.Object
-
- groovy.lang.GroovyObjectSupport
-
- groovy.util.BuilderSupport
-
- nz.net.ultraq.thymeleaf.layoutdialect.models.ModelBuilder
-
- All Implemented Interfaces:
groovy.lang.GroovyObject
public class ModelBuilder extends groovy.util.BuilderSupport
Create Thymeleaf 3.0 models using a simplified syntax.- Author:
- zhanhb, Emanuel Rabina
-
-
Constructor Summary
Constructors Constructor Description ModelBuilder(ITemplateContext context)
Constructor, create a new model builder.ModelBuilder(IModelFactory modelFactory, ElementDefinitions elementDefinitions, TemplateMode templateMode)
Constructor, create a new model builder.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
add(IModel model)
Appends an existing model to the model being built.IModel
build(groovy.lang.Closure<? extends IModel> definition)
Captures the top `build` call so that it doesn't end up as a node in the final model.protected Object
createNode(Object name)
Create a model for the given HTML element.protected Object
createNode(Object name, Object value)
Create a model for the given HTML element and inner text content.protected Object
createNode(Object name, Map attributes)
Create a model for the given HTML element and attributes.protected IModel
createNode(Object name, Map attributes, Object value)
Create a model for the given HTML element, attributes, and inner text content.protected void
nodeCompleted(Object parent, Object child)
Link a parent and child node.protected void
setParent(Object parent, Object child)
Does nothing.-
Methods inherited from class groovy.util.BuilderSupport
doInvokeMethod, getCurrent, getName, invokeMethod, invokeMethod, postNodeCompletion, setClosureDelegate, setCurrent
-
-
-
-
Constructor Detail
-
ModelBuilder
public ModelBuilder(ITemplateContext context)
Constructor, create a new model builder.- Parameters:
context
-
-
ModelBuilder
public ModelBuilder(IModelFactory modelFactory, ElementDefinitions elementDefinitions, TemplateMode templateMode)
Constructor, create a new model builder.- Parameters:
modelFactory
-elementDefinitions
-templateMode
-
-
-
Method Detail
-
add
public void add(IModel model)
Appends an existing model to the model being built.- Parameters:
model
-
-
build
public IModel build(groovy.lang.Closure<? extends IModel> definition)
Captures the top `build` call so that it doesn't end up as a node in the final model.- Parameters:
definition
-- Returns:
- The model built using the closure definition.
-
createNode
protected Object createNode(Object name)
Create a model for the given HTML element.- Specified by:
createNode
in classgroovy.util.BuilderSupport
- Parameters:
name
- HTML element name.- Returns:
- New model with the given name.
-
createNode
protected Object createNode(Object name, Object value)
Create a model for the given HTML element and inner text content.- Specified by:
createNode
in classgroovy.util.BuilderSupport
- Parameters:
name
- HTML element name.value
- Text content.- Returns:
- New model with the given name and content.
-
createNode
protected Object createNode(Object name, Map attributes)
Create a model for the given HTML element and attributes.- Specified by:
createNode
in classgroovy.util.BuilderSupport
- Parameters:
name
- HTML element name.attributes
- Element attributes.- Returns:
- New model with the given name and attributes.
-
createNode
protected IModel createNode(Object name, Map attributes, Object value)
Create a model for the given HTML element, attributes, and inner text content.- Specified by:
createNode
in classgroovy.util.BuilderSupport
- Parameters:
name
- HTML element name.attributes
- Element attributes.value
- Text content.- Returns:
- New model with the given name, attributes, and content.
-
nodeCompleted
protected void nodeCompleted(Object parent, Object child)
Link a parent and child node. A child node is appended to a parent by being the last sub-model before the parent close tag.- Overrides:
nodeCompleted
in classgroovy.util.BuilderSupport
- Parameters:
parent
-child
-
-
setParent
protected void setParent(Object parent, Object child)
Does nothing. Because models only copy events when added to one another, we can't just add child events at this point - we need to wait until that child has had it's children added, and so on. So the parent/child link is made in thenodeCompleted(java.lang.Object, java.lang.Object)
method instead.- Specified by:
setParent
in classgroovy.util.BuilderSupport
- Parameters:
parent
-child
-
-
-