Last active
December 19, 2015 21:39
-
-
Save erokhins/6021366 to your computer and use it in GitHub Desktop.
Kara new
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 = "" | |
} | |
} | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Did you mean
fun Tag<TR>.td(f: Tag<TD>.() -> Unit) {}
instead of
fun Tag<TagAttributes>.td(f: Tag<TD>.() -> Unit) {}