* dynamic property
access
* a builder for
templates
Groovy Integration
Templates
Templates are dynamized in Groovy. That means names, declared in the template can be accessed as properties:
def t = getTemplate()
t.title = title
def region = t.region
region.name = "The thing"
region.name2 = "you know"
region.render()
As it's still necessary to render regions once all values are assigned, it can still be attractive to use the normal form for setting the values:
def t = getTemplate().set("title, tile)
t.region.set("name", "The thing").set("name2", "you know").render()
getAt is also supported: t["region-name"].render()
TemplateBuilder
The TemplateBuilder takes this one step further:
def t = new TemplateBuilder(getTemplate())
t.title = title
t.region {
name = "The thing"
name2 = "you know"
}
// or
t.region(name: "The thing", name2: "you know")
As the closures make clear, when all values are set, calling render is not necessary. (Not even possible, as the TemplateBuilder use a different interface.)
In order to include another template it's not necessary to wrap it into a TemplateBuilder:
def t = new TemplateBuilder(getTemplate())
t.targetName(getOtherTemplate().region) {
name = "The thing"
name2 = "you know"
}
So the TemplateBuilder does provide a number of nice features it's still kind of limited. If you have any ideas here, I'm happy to review push requests on GitLab