1

私の目標は、次のコード ブロックでジェネリック関数に渡されるオブジェクトの定義の反復部分を DRY することです。

renderTpl(response, "person.html", new Transformer {
  $(".person :first-child").contents = name
  $(".person :last-child").contents = age
})

パーツを DRY して、代わりにnew Transformer2 番目の引数リストでブロックを渡すことができるようにしたいと思います。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で見ることができます。

4

0 に答える 0