Skip to content

Instantly share code, notes, and snippets.

@mostlylikeable
Created September 4, 2014 20:07
Show Gist options
  • Select an option

  • Save mostlylikeable/be2aefc9ce6f577767cb to your computer and use it in GitHub Desktop.

Select an option

Save mostlylikeable/be2aefc9ce6f577767cb to your computer and use it in GitHub Desktop.
Render gsp template from file, delegating to script
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