Last active
December 28, 2015 01:09
-
-
Save krsmes/7418190 to your computer and use it in GitHub Desktop.
Simple grails controller action to evaluate groovy script for debugging
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
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