Groovy web console

subscribe to the feed Subscribe
to this
site
templateengine test (via #groovywebconsole)
tweet this snippet Tweet
this
script

templateengine test

Published 1 week ago by nmrao with tags te
Actions  ➤ Edit in console Back to console Show/hide line numbers View recent scripts
def text = '$test $test2 this is my test'
def binding = [test:'HELLO', test2:'WORLD']
def engine = new groovy.text.SimpleTemplateEngine() 
def template = engine.createTemplate(text).make(binding)
def result = 'HELLO WORLD this is my test'
assert result == template.toString()

/*
def test="HELLO"
def test2="WORLD"
def queryText = "\$\$test\$\$ \$\$test2\$\$ this is my test"

def list = queryText.findAll(/\$\$(.*?)\$\$/)
println list

def map = [:]
list.each{
    it = it.replace("\$\$", "")
    map.putAt(it, eval(it))
}

queryText = queryText.replaceAll(/\$\$(.*?)\$\$/) { k -> map[k[1]] ?: k[0] }

System.out.println(map)
System.out.println(queryText)
*/