[Groovy] Class TagLibAdapter
- groovy.text.markup.TagLibAdapter
Adapts Grails taglibs for use in the template engine. An adapter may be created like this:
def model = [:] def tpl = template.make(model) model.g = new TagLibAdapter(tpl) model.g.registerTagLib(SimpleTagLib)where SimpleTagLib is:
class SimpleTagLib { def emoticon = { attrs, body -> out << body() << (attrs.happy == 'true' ? " :-)" : " :-(") } }Then it can be used inside a template like this:
g.emoticon(happy:'true') { 'Hi John' }Performance-wise, it would be better to reimplement the taglib, but this makes it easier to reuse existing code.
Constructor Summary
Constructor and description |
---|
TagLibAdapter
(BaseTemplate tpl) |
Methods Summary
Type Params | Return Type | Name and description |
---|---|---|
Object |
methodMissing(String name, def args) | |
void |
registerTagLib(Class tagLibClass) | |
void |
registerTagLib(Object tagLib) |
Inherited Methods Summary
Methods inherited from class | Name |
---|---|
class Object | wait, wait, wait, equals, toString, hashCode, getClass, notify, notifyAll |
Constructor Detail
TagLibAdapter(BaseTemplate tpl)
Method Detail
Object methodMissing(String name, def args)
void registerTagLib(Class tagLibClass)
void registerTagLib(Object tagLib)
© 2003-2020 The Apache Software Foundation
Licensed under the Apache license.
https://docs.groovy-lang.org/2.5.14/html/gapi/groovy/text/markup/TagLibAdapter.html