Created
September 4, 2014 20:07
-
-
Save mostlylikeable/be2aefc9ce6f577767cb to your computer and use it in GitHub Desktop.
Render gsp template from file, delegating to script
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import org.springframework.core.io.ByteArrayResource | |
| def s = new File('/Users/ben/Documents/foo/index.gsp').withReader { reader -> | |
| return reader.text | |
| } | |
| def resource = new ByteArrayResource(s.bytes) | |
| def renderer = ctx.groovyPagesTemplateEngine | |
| def template = renderer.createTemplate(resource, false) | |
| def output = new StringWriter() | |
| template.make([s: this]).writeTo(output) // s is accessible in template: s.buildActionUrl('bar') | |
| private String buildActionUrl(name) { | |
| return "http://foo.com/$name" | |
| } | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment