Details
-
Bug
-
Status: Closed
-
Major
-
Resolution: Won't Fix
-
1.7.6
-
None
-
None
Description
I'm trying to use the SimpleTemplateEngine in combination with some static imports to capitalize some words, like this:
import static org.apache.commons.lang.WordUtils.capitalize import groovy.text.SimpleTemplateEngine def text = 'Dear "${capitalize(\'erik\')} $lastname",\nSo nice to meet you in <% print city %>.\nSee you in ${month},\n${signed}' def binding = ["firstname":"Sam", "lastname":"Pullara", "city":"San Francisco", "month":"December", "signed":"Groovy-Dev"] def engine = new SimpleTemplateEngine() template = engine.createTemplate(text).make(binding) def result = 'Dear "Sam Pullara",\nSo nice to meet you in San Francisco.\nSee you in December,\nGroovy-Dev' assert result == template.toString()
This doesn't work, because it cannot find the capitalize method:
groovy.lang.MissingMethodException: No signature of method: SimpleTemplateScript14.capitalize() is applicable for argument types: (java.lang.String) values: [erik] at SimpleTemplateScript14.run(SimpleTemplateScript14.groovy:2) at groovy.text.SimpleTemplateEngine$SimpleTemplate$1.writeTo(SimpleTemplateEngine.java:164) at groovy.text.SimpleTemplateEngine$SimpleTemplate$1.toString(SimpleTemplateEngine.java:176) at ConsoleScript15.run(ConsoleScript15:14)
Whenever I use the fully qualified name, it works, but importing brings me no luck, even though it's nicely advertised on the documentation page: http://groovy.codehaus.org/Groovy+Templates
For what it's worth, I've tried it with the Groovy which comes with Grails 1.3.2.
Kind regards,
Erik Pragt