(init : T.() -> Unit) : T
where class object T : Factory{
val tag = T.create()
tag.init()
children.add(tag)
return tag
}
}
abstract class TagWithText(name : String) : Tag(name) {
fun String.plus() {
children.add(TextElement(this))
}
}
class HTML() : TagWithText("html") {
class object : Factory {
override fun create() = HTML()
}
fun head(init : Head.() -> Unit) = initTag(init)
fun body(init : Body.() -> Unit) = initTag(init)
}
class Head() : TagWithText("head") {
class object : Factory {
override fun create() = Head()
}
fun title(init : Title.() -> Unit) = initTag(init)
}
class Title() : TagWithText("title")
abstract class BodyTag(name : String) : TagWithText(name) {
}
class Body() : BodyTag("body") {
class object : Factory {
override fun create() = Body()
}
fun b(init : B.() -> Unit) = initTag(init)
fun p(init : P.() -> Unit) = initTag(init)
fun h1(init : H1.() -> Unit) = initTag