diff options
author | Robert Jaros <rjaros@finn.pl> | 2018-02-12 12:00:15 +0100 |
---|---|---|
committer | Robert Jaros <rjaros@finn.pl> | 2018-02-12 12:00:15 +0100 |
commit | eea44b35add0d036119888f41e4ed38e75190934 (patch) | |
tree | 01ff2b73042ab08941df082d74241dc5e229a37d /src/main/kotlin/pl/treksoft/kvision/html | |
parent | 4191287261b46b95908469c2ec3fa9d886681861 (diff) | |
download | kvision-eea44b35add0d036119888f41e4ed38e75190934.tar.gz kvision-eea44b35add0d036119888f41e4ed38e75190934.tar.bz2 kvision-eea44b35add0d036119888f41e4ed38e75190934.zip |
DSL builders returning built components.
Diffstat (limited to 'src/main/kotlin/pl/treksoft/kvision/html')
6 files changed, 30 insertions, 18 deletions
diff --git a/src/main/kotlin/pl/treksoft/kvision/html/Button.kt b/src/main/kotlin/pl/treksoft/kvision/html/Button.kt index b4c6ed7c..79155395 100644 --- a/src/main/kotlin/pl/treksoft/kvision/html/Button.kt +++ b/src/main/kotlin/pl/treksoft/kvision/html/Button.kt @@ -162,15 +162,17 @@ open class Button( companion object { /** - * DSL builder extension function + * DSL builder extension function. * * It takes the same parameters as the constructor of the built component. */ fun Container.button( text: String, icon: String? = null, style: BUTTONSTYLE = BUTTONSTYLE.DEFAULT, disabled: Boolean = false, classes: Set<String> = setOf(), init: (Button.() -> Unit)? = null - ) { - this.add(Button(text, icon, style, disabled, classes).apply { init?.invoke(this) }) + ): Button { + val button = Button(text, icon, style, disabled, classes).apply { init?.invoke(this) } + this.add(button) + return button } } } diff --git a/src/main/kotlin/pl/treksoft/kvision/html/Image.kt b/src/main/kotlin/pl/treksoft/kvision/html/Image.kt index c2af9bac..bd469afe 100644 --- a/src/main/kotlin/pl/treksoft/kvision/html/Image.kt +++ b/src/main/kotlin/pl/treksoft/kvision/html/Image.kt @@ -122,15 +122,17 @@ open class Image( companion object { /** - * DSL builder extension function + * DSL builder extension function. * * It takes the same parameters as the constructor of the built component. */ fun Container.image( src: ResString, alt: String? = null, responsive: Boolean = false, shape: IMAGESHAPE? = null, centered: Boolean = false, classes: Set<String> = setOf(), init: (Image.() -> Unit)? = null - ) { - this.add(Image(src, alt, responsive, shape, centered, classes).apply { init?.invoke(this) }) + ): Image { + val image = Image(src, alt, responsive, shape, centered, classes).apply { init?.invoke(this) } + this.add(image) + return image } } } diff --git a/src/main/kotlin/pl/treksoft/kvision/html/Label.kt b/src/main/kotlin/pl/treksoft/kvision/html/Label.kt index cd120cba..e56362ef 100644 --- a/src/main/kotlin/pl/treksoft/kvision/html/Label.kt +++ b/src/main/kotlin/pl/treksoft/kvision/html/Label.kt @@ -33,14 +33,16 @@ import pl.treksoft.kvision.core.Container open class Label(text: String, rich: Boolean = false) : Tag(TAG.SPAN, text, rich) { companion object { /** - * DSL builder extension function + * DSL builder extension function. * * It takes the same parameters as the constructor of the built component. */ fun Container.label( text: String, rich: Boolean = false, init: (Label.() -> Unit)? = null - ) { - this.add(Label(text, rich).apply { init?.invoke(this) }) + ): Label { + val label = Label(text, rich).apply { init?.invoke(this) } + this.add(label) + return label } } } diff --git a/src/main/kotlin/pl/treksoft/kvision/html/Link.kt b/src/main/kotlin/pl/treksoft/kvision/html/Link.kt index 7572d444..e075d685 100644 --- a/src/main/kotlin/pl/treksoft/kvision/html/Link.kt +++ b/src/main/kotlin/pl/treksoft/kvision/html/Link.kt @@ -85,15 +85,17 @@ open class Link( companion object { /** - * DSL builder extension function + * DSL builder extension function. * * It takes the same parameters as the constructor of the built component. */ fun Container.link( label: String, url: String, icon: String? = null, image: ResString? = null, classes: Set<String> = setOf(), init: (Link.() -> Unit)? = null - ) { - this.add(Link(label, url, icon, image, classes).apply { init?.invoke(this) }) + ): Link { + val link = Link(label, url, icon, image, classes).apply { init?.invoke(this) } + this.add(link) + return link } } } diff --git a/src/main/kotlin/pl/treksoft/kvision/html/List.kt b/src/main/kotlin/pl/treksoft/kvision/html/List.kt index 29f5d18e..2dadd546 100644 --- a/src/main/kotlin/pl/treksoft/kvision/html/List.kt +++ b/src/main/kotlin/pl/treksoft/kvision/html/List.kt @@ -146,15 +146,17 @@ open class ListTag( companion object { /** - * DSL builder extension function + * DSL builder extension function. * * It takes the same parameters as the constructor of the built component. */ fun Container.listTag( type: LISTTYPE, elements: List<String>? = null, rich: Boolean = false, classes: Set<String> = setOf(), init: (ListTag.() -> Unit)? = null - ) { - this.add(ListTag(type, elements, rich, classes, init)) + ): ListTag { + val listTag = ListTag(type, elements, rich, classes, init) + this.add(listTag) + return listTag } } } diff --git a/src/main/kotlin/pl/treksoft/kvision/html/Tag.kt b/src/main/kotlin/pl/treksoft/kvision/html/Tag.kt index ebcc0020..62a647bc 100644 --- a/src/main/kotlin/pl/treksoft/kvision/html/Tag.kt +++ b/src/main/kotlin/pl/treksoft/kvision/html/Tag.kt @@ -155,15 +155,17 @@ open class Tag( companion object { /** - * DSL builder extension function + * DSL builder extension function. * * It takes the same parameters as the constructor of the built component. */ fun Container.tag( type: TAG, text: String? = null, rich: Boolean = false, align: ALIGN? = null, classes: Set<String> = setOf(), init: (Tag.() -> Unit)? = null - ) { - this.add(Tag(type, text, rich, align, classes, init)) + ): Tag { + val tag = Tag(type, text, rich, align, classes, init) + this.add(tag) + return tag } } } |