Skip to content

Instantly share code, notes, and snippets.

@krsmes
Last active December 28, 2015 01:09
Show Gist options
  • Save krsmes/7418190 to your computer and use it in GitHub Desktop.
Save krsmes/7418190 to your computer and use it in GitHub Desktop.
Simple grails controller action to evaluate groovy script for debugging
def eval = {
def binding = new Binding(app:grailsApplication,request:request,session:session,controller:this)
def result
try { result = params.script ? new GroovyShell(binding).evaluate(params.script) : '(no script)' }
catch (e) { result = e.message }
result = result instanceof Map ? result.collect{"$it.key: $it.value"}.join('\n') :
result instanceof Iterable ? result.join('\n') : result
render """${g.form(action:'eval',method:'POST') {
"${g.textArea(name:'script',value:params.script,cols:80,rows:10)}${g.submitButton(name:'Submit')}"}}
<hr/><pre>${result}</pre>"""
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment