Created
January 4, 2012 17:16
-
-
Save ianhomer/1561045 to your computer and use it in GitHub Desktop.
Simple String Templating with Defaults
This file contains 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 groovy.text.SimpleTemplateEngine | |
class Message() { | |
String body | |
String populateBodyWith(binding) { | |
new SimpleTemplateEngine().createTemplate(body).make(binding.withDefault { '${' + it + '}' }) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Populate variables in a message strings with defaulting so that unrecognised variables are not templated