From bafcdb6fc3f1d4ec4f1a0f4fcce776ba10d8136c Mon Sep 17 00:00:00 2001 From: Robert Jaros Date: Mon, 12 Feb 2018 10:50:42 +0100 Subject: Type safe DSL builders --- src/main/kotlin/pl/treksoft/kvision/html/Link.kt | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'src/main/kotlin/pl/treksoft/kvision/html/Link.kt') diff --git a/src/main/kotlin/pl/treksoft/kvision/html/Link.kt b/src/main/kotlin/pl/treksoft/kvision/html/Link.kt index ad8897d5..7572d444 100644 --- a/src/main/kotlin/pl/treksoft/kvision/html/Link.kt +++ b/src/main/kotlin/pl/treksoft/kvision/html/Link.kt @@ -22,6 +22,7 @@ package pl.treksoft.kvision.html import com.github.snabbdom.VNode +import pl.treksoft.kvision.core.Container import pl.treksoft.kvision.core.ResString import pl.treksoft.kvision.core.StringPair import pl.treksoft.kvision.panel.SimplePanel @@ -81,4 +82,18 @@ open class Link( override fun getSnAttrs(): List { return super.getSnAttrs() + ("href" to url) } + + companion object { + /** + * 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 = setOf(), init: (Link.() -> Unit)? = null + ) { + this.add(Link(label, url, icon, image, classes).apply { init?.invoke(this) }) + } + } } -- cgit