Skip to content

Instantly share code, notes, and snippets.

@fumokmm
Created December 20, 2010 15:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fumokmm/748526 to your computer and use it in GitHub Desktop.
Save fumokmm/748526 to your computer and use it in GitHub Desktop.
// Stringを拡張してバインド変数のマップを渡してパースできるようにする
String.metaClass.parse = { Map binding = [:] ->
new groovy.text.SimpleTemplateEngine()
.createTemplate(new StringReader(delegate))
.make(binding).toString()
}
// エルシャダイ風にテスト
def result = '''
${user1}「${serif1}」
<%= user2 %>「<%= serif2 %>」
'''.parse(
user1: 'ルシフェル', serif1: 'そんな装備で大丈夫か?',
user2: 'イーノック', serif2: '大丈夫だ、問題ない'
)
assert '''
ルシフェル「そんな装備で大丈夫か?」
イーノック「大丈夫だ、問題ない」
''' == result
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment