Skip to content

Instantly share code, notes, and snippets.

@erokhins
Last active December 19, 2015 21:39
Show Gist options
  • Save erokhins/6021366 to your computer and use it in GitHub Desktop.
Save erokhins/6021366 to your computer and use it in GitHub Desktop.
Kara new
open class TagAttributes
var TagAttributes.id = ""
class Tag<out T: TagAttributes>(val containingTag: Tag<TagAttributes>?, val t: T) {
val attr: T = t
fun attr(f: T.() -> Unit) {
}
}
class A: TagAttributes()
var A.href = ""
class INPUT: TagAttributes()
var INPUT.value = ""
class TABLE: TagAttributes()
class TR: TagAttributes()
class TD: TagAttributes()
fun Tag<TagAttributes>.a(f: Tag<A>.() -> Unit) {}
fun Tag<TagAttributes>.input(f: Tag<INPUT>.() -> Unit) {}
fun Tag<TagAttributes>.table(f: Tag<TABLE>.() -> Unit) {}
fun Tag<TagAttributes>.tr(f: Tag<TR>.() -> Unit) {}
fun Tag<TagAttributes>.td(f: Tag<TD>.() -> Unit) {}
fun main(args: Array<String>) {
Tag<A>(null, A()).table {
tr {
td {
attr {
id = ""
}
input {
attr.value = ""
attr {
value = ""
}
a {
attr {
href = ""
id = ""
}
}
}
}
}
}
}
@shafirov
Copy link

Did you mean
fun Tag<TR>.td(f: Tag<TD>.() -> Unit) {}
instead of
fun Tag<TagAttributes>.td(f: Tag<TD>.() -> Unit) {}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment