My goal is to DRY up the repetitive parts of the definition of objects passed to a generic function in the following block of code:
renderTpl(response, "person.html", new Transformer {
$(".person :first-child").contents = name
$(".person :last-child").contents = age
})
I would like to DRY out the new Transformer
part and be able to pass the block in the 2nd argument list of renderTpl
instead:
renderTpl(response, "person.html") {
$(".person :first-child").contents = name
$(".person :last-child").contents = age
}
is it possible to achieve this without resorting to macros? I would post my attempts so far but to be honest I couldn't come up with anything right now.
Background: I'm using Scalate's awesome Scuery with servlets, combined with Lift's net.liftweb.util.Html5
and org.ccil.cowan.tagsoup
for HTML5 parsing and rendering; the current renderTpl
and loadTpl
implementation can be seen here.