kotlinx.html implements a very elegant DSL that allows describing the code to build a DOM.tree or subtree.
e.g. from readme page…
val myDiv = document.create.div("panel") {
p {
+"Here is "
a("http://kotlinlang.org") { +"official Kotlin site" }
}
// sequence of tags can be added here
}
The questions is, how can the ‘sequence of tags’ be provided not by a set of declarations, but by a function that provides the set of declarations so in place of …
val myDiv = document.create.div("panel") {
p {
+"Here is "
a("http://kotlinlang.org") { +"official Kotlin site" }
}
// sequence
ul {
li{ +"list item 1"}
li{ +"list item n"}
}
}
but instead something like…
fun doUl(){
return document.create.ul{
li{ +"item 1"}
li{ +"item n"}
}
}
//........
val myDiv = document.create.div("panel") {
p {
+"Here is "
a("http://kotlinlang.org") { +"official Kotlin site" }
}
// sequence here
doUl()
}
I would assume some ‘wrapper’ function is going to be needed for ‘doUI()’. But I cannot yet see how to do something like this and any suggestions appreciated.