Skip to content

Instantly share code, notes, and snippets.

@ianhomer
Created January 4, 2012 17:16
Show Gist options
  • Save ianhomer/1561045 to your computer and use it in GitHub Desktop.
Save ianhomer/1561045 to your computer and use it in GitHub Desktop.
Simple String Templating with Defaults
import groovy.text.SimpleTemplateEngine
class Message() {
String body
String populateBodyWith(binding) {
new SimpleTemplateEngine().createTemplate(body).make(binding.withDefault { '${' + it + '}' })
}
}
@ianhomer
Copy link
Author

ianhomer commented Jan 4, 2012

Populate variables in a message strings with defaulting so that unrecognised variables are not templated

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment