Page History
'eval' Method
eval(String script)
This method will evaluate a Groovy code from a string and return the result.
Code Block | ||
---|---|---|
| ||
$groovy.eval("println 'Hello World!'") |
eval(String script, String bindingName, Object bindingObject)
This method will evaluate a Groovy code with a single binding object and specified binding name. The code will be evaluated from a string. The binding name will be used as the name for this object.
Code Block | ||
---|---|---|
| ||
#foreach ($c in $Class)
$groovy.eval("println classname", "classname", $c.name)
#end |
eval(String script, Map bindingMap)
This method will evaluate a Groovy code with a set of binding arguments (a name and an object). The code will be evaluated from a string. The binding map consists of key-value pairs for the binding name and the binding object.
Code Block | ||
---|---|---|
| ||
#set ($dict = $map.createHashMap())
#set ($void = $dict.put("first", "foo"))
#set ($void = $dict.put("last", "bar"))
$groovy.eval("println first + last", $dict) |
Or
Code Block | ||
---|---|---|
| ||
$groovy.eval("println first + ' ' + last", {"first":"foo", "last":"bar"}) |
Tip |
---|
The second code contains curly brackets; '{' and '}' characters, which are not allowed to be used in any RTF template. For the RTF template, use the first code instead. |
'execute' method
execute(String filename)
This method will execute a Groovy file. The 'filename' parameter refers to a name of the Groovy file or an absolute path to the Groovy file.
Code Block | ||
---|---|---|
| ||
$groovy.execute("filename.groovy") |
execute(String filename, String bindingName, Object bindingObject)
This method will execute a Groovy file with a single binding object and specified binding name. The 'filename' parameter is a file path to the Groovy file. The binding name will be used as the name for this object.
File filename.groovy
Code Block | ||
---|---|---|
| ||
"Class name is $c.name" |
The template code
Code Block | ||
---|---|---|
| ||
#foreach ($c in $Class)
$groovy.execute("filename.groovy", 'c', $c)
#end |
execute(String filename, Map bindingMap)
This method will execute a Groovy file with a set of binding arguments (a name and an object). The 'filename' parameter is a file path to the Groovy file. The binding map consists of key-value pairs for the binding name and the binding object.
File filename.groovy
Code Block | ||
---|---|---|
| ||
first + " " + last |
The template code
Code Block | ||
---|---|---|
| ||
#set ($dict = $map.createHashMap())
#set ($void = $dict.put("first", "foo"))
#set ($void = $dict.put("last", "bar"))
$groovy.execute("filename.groovy", $dict) |
Tip |
---|
|