私の目標は、次のコード ブロックでジェネリック関数に渡されるオブジェクトの定義の反復部分を DRY することです。
renderTpl(response, "person.html", new Transformer {
$(".person :first-child").contents = name
$(".person :last-child").contents = age
})
パーツを DRY して、代わりにnew Transformer
2 番目の引数リストでブロックを渡すことができるようにしたいと思います。renderTpl
renderTpl(response, "person.html") {
$(".person :first-child").contents = name
$(".person :last-child").contents = age
}
マクロに頼らずにこれを達成することは可能ですか? これまでの試みを投稿しますが、正直なところ、今は何も思いつきませんでした。
背景:私は Scalate のすばらしいScuerynet.liftweb.util.Html5
をサーブレットで使用し、Liftと組み合わせてorg.ccil.cowan.tagsoup
、HTML5 の解析とレンダリングを行っています。現在renderTpl
および実装はここloadTpl
で見ることができます。