From 736b80835f67c9c34657074ebcfbe0752bef1c18 Mon Sep 17 00:00:00 2001 From: Robert Jaros Date: Thu, 17 Oct 2019 21:58:34 +0200 Subject: Move DSL builder functions out of the companion objects (#93) --- .../pl/treksoft/kvision/form/select/Select.kt | 30 +++--- .../pl/treksoft/kvision/form/select/SelectInput.kt | 31 +++--- .../treksoft/kvision/form/select/SelectOptGroup.kt | 58 ++++++----- .../treksoft/kvision/form/select/SelectOption.kt | 111 ++++++++++----------- 4 files changed, 111 insertions(+), 119 deletions(-) (limited to 'kvision-modules/kvision-bootstrap-select/src/main') diff --git a/kvision-modules/kvision-bootstrap-select/src/main/kotlin/pl/treksoft/kvision/form/select/Select.kt b/kvision-modules/kvision-bootstrap-select/src/main/kotlin/pl/treksoft/kvision/form/select/Select.kt index 4b2505d2..ea98e369 100644 --- a/kvision-modules/kvision-bootstrap-select/src/main/kotlin/pl/treksoft/kvision/form/select/Select.kt +++ b/kvision-modules/kvision-bootstrap-select/src/main/kotlin/pl/treksoft/kvision/form/select/Select.kt @@ -266,20 +266,20 @@ open class Select( companion object { internal var counter = 0 - - /** - * DSL builder extension function. - * - * It takes the same parameters as the constructor of the built component. - */ - fun Container.select( - options: List? = null, value: String? = null, name: String? = null, - multiple: Boolean = false, ajaxOptions: AjaxOptions? = null, label: String? = null, - rich: Boolean = false, init: (Select.() -> Unit)? = null - ): Select { - val select = Select(options, value, name, multiple, ajaxOptions, label, rich).apply { init?.invoke(this) } - this.add(select) - return select - } } } + +/** + * DSL builder extension function. + * + * It takes the same parameters as the constructor of the built component. + */ +fun Container.select( + options: List? = null, value: String? = null, name: String? = null, + multiple: Boolean = false, ajaxOptions: AjaxOptions? = null, label: String? = null, + rich: Boolean = false, init: (Select.() -> Unit)? = null +): Select { + val select = Select(options, value, name, multiple, ajaxOptions, label, rich).apply { init?.invoke(this) } + this.add(select) + return select +} diff --git a/kvision-modules/kvision-bootstrap-select/src/main/kotlin/pl/treksoft/kvision/form/select/SelectInput.kt b/kvision-modules/kvision-bootstrap-select/src/main/kotlin/pl/treksoft/kvision/form/select/SelectInput.kt index 84eccaf7..b515ea3e 100644 --- a/kvision-modules/kvision-bootstrap-select/src/main/kotlin/pl/treksoft/kvision/form/select/SelectInput.kt +++ b/kvision-modules/kvision-bootstrap-select/src/main/kotlin/pl/treksoft/kvision/form/select/SelectInput.kt @@ -354,22 +354,19 @@ open class SelectInput( override fun blur() { getElementJQuery()?.blur() } +} - companion object { - - /** - * DSL builder extension function. - * - * It takes the same parameters as the constructor of the built component. - */ - fun Container.selectInput( - options: List? = null, value: String? = null, - multiple: Boolean = false, ajaxOptions: AjaxOptions? = null, - classes: Set = setOf(), init: (SelectInput.() -> Unit)? = null - ): SelectInput { - val selectInput = SelectInput(options, value, multiple, ajaxOptions, classes).apply { init?.invoke(this) } - this.add(selectInput) - return selectInput - } - } +/** + * DSL builder extension function. + * + * It takes the same parameters as the constructor of the built component. + */ +fun Container.selectInput( + options: List? = null, value: String? = null, + multiple: Boolean = false, ajaxOptions: AjaxOptions? = null, + classes: Set = setOf(), init: (SelectInput.() -> Unit)? = null +): SelectInput { + val selectInput = SelectInput(options, value, multiple, ajaxOptions, classes).apply { init?.invoke(this) } + this.add(selectInput) + return selectInput } diff --git a/kvision-modules/kvision-bootstrap-select/src/main/kotlin/pl/treksoft/kvision/form/select/SelectOptGroup.kt b/kvision-modules/kvision-bootstrap-select/src/main/kotlin/pl/treksoft/kvision/form/select/SelectOptGroup.kt index 3f07a9bf..7893f891 100644 --- a/kvision-modules/kvision-bootstrap-select/src/main/kotlin/pl/treksoft/kvision/form/select/SelectOptGroup.kt +++ b/kvision-modules/kvision-bootstrap-select/src/main/kotlin/pl/treksoft/kvision/form/select/SelectOptGroup.kt @@ -88,36 +88,34 @@ open class SelectOptGroup( } return sn } +} - companion object { - /** - * DSL builder extension function. - * - * It takes the same parameters as the constructor of the built component. - */ - fun Select.selectOptGroup( - label: String, options: List? = null, maxOptions: Int? = null, - disabled: Boolean = false, classes: Set = setOf(), init: (SelectOptGroup.() -> Unit)? = null - ): SelectOptGroup { - val selectOptGroup = - SelectOptGroup(label, options, maxOptions, disabled, classes).apply { init?.invoke(this) } - this.add(selectOptGroup) - return selectOptGroup - } +/** + * DSL builder extension function. + * + * It takes the same parameters as the constructor of the built component. + */ +fun Select.selectOptGroup( + label: String, options: List? = null, maxOptions: Int? = null, + disabled: Boolean = false, classes: Set = setOf(), init: (SelectOptGroup.() -> Unit)? = null +): SelectOptGroup { + val selectOptGroup = + SelectOptGroup(label, options, maxOptions, disabled, classes).apply { init?.invoke(this) } + this.add(selectOptGroup) + return selectOptGroup +} - /** - * DSL builder extension function. - * - * It takes the same parameters as the constructor of the built component. - */ - fun SelectInput.selectOptGroup( - label: String, options: List? = null, maxOptions: Int? = null, - disabled: Boolean = false, classes: Set = setOf(), init: (SelectOptGroup.() -> Unit)? = null - ): SelectOptGroup { - val selectOptGroup = - SelectOptGroup(label, options, maxOptions, disabled, classes).apply { init?.invoke(this) } - this.add(selectOptGroup) - return selectOptGroup - } - } +/** + * DSL builder extension function. + * + * It takes the same parameters as the constructor of the built component. + */ +fun SelectInput.selectOptGroup( + label: String, options: List? = null, maxOptions: Int? = null, + disabled: Boolean = false, classes: Set = setOf(), init: (SelectOptGroup.() -> Unit)? = null +): SelectOptGroup { + val selectOptGroup = + SelectOptGroup(label, options, maxOptions, disabled, classes).apply { init?.invoke(this) } + this.add(selectOptGroup) + return selectOptGroup } diff --git a/kvision-modules/kvision-bootstrap-select/src/main/kotlin/pl/treksoft/kvision/form/select/SelectOption.kt b/kvision-modules/kvision-bootstrap-select/src/main/kotlin/pl/treksoft/kvision/form/select/SelectOption.kt index 91c269a8..a9c7eda5 100644 --- a/kvision-modules/kvision-bootstrap-select/src/main/kotlin/pl/treksoft/kvision/form/select/SelectOption.kt +++ b/kvision-modules/kvision-bootstrap-select/src/main/kotlin/pl/treksoft/kvision/form/select/SelectOption.kt @@ -104,67 +104,64 @@ open class SelectOption( } return sn } +} - companion object { - /** - * DSL builder extension function. - * - * It takes the same parameters as the constructor of the built component. - */ - fun Select.selectOption( - value: String? = null, label: String? = null, subtext: String? = null, icon: String? = null, - divider: Boolean = false, disabled: Boolean = false, selected: Boolean = false, - classes: Set = setOf(), init: (SelectOption.() -> Unit)? = null - ): SelectOption { - val selectOption = - SelectOption(value, label, subtext, icon, divider, disabled, selected, classes).apply { - init?.invoke( - this - ) - } - this.add(selectOption) - return selectOption +/** + * DSL builder extension function. + * + * It takes the same parameters as the constructor of the built component. + */ +fun Select.selectOption( + value: String? = null, label: String? = null, subtext: String? = null, icon: String? = null, + divider: Boolean = false, disabled: Boolean = false, selected: Boolean = false, + classes: Set = setOf(), init: (SelectOption.() -> Unit)? = null +): SelectOption { + val selectOption = + SelectOption(value, label, subtext, icon, divider, disabled, selected, classes).apply { + init?.invoke( + this + ) } + this.add(selectOption) + return selectOption +} - /** - * DSL builder extension function. - * - * It takes the same parameters as the constructor of the built component. - */ - fun SelectInput.selectOption( - value: String? = null, label: String? = null, subtext: String? = null, icon: String? = null, - divider: Boolean = false, disabled: Boolean = false, selected: Boolean = false, - classes: Set = setOf(), init: (SelectOption.() -> Unit)? = null - ): SelectOption { - val selectOption = - SelectOption(value, label, subtext, icon, divider, disabled, selected, classes).apply { - init?.invoke( - this - ) - } - this.add(selectOption) - return selectOption +/** + * DSL builder extension function. + * + * It takes the same parameters as the constructor of the built component. + */ +fun SelectInput.selectOption( + value: String? = null, label: String? = null, subtext: String? = null, icon: String? = null, + divider: Boolean = false, disabled: Boolean = false, selected: Boolean = false, + classes: Set = setOf(), init: (SelectOption.() -> Unit)? = null +): SelectOption { + val selectOption = + SelectOption(value, label, subtext, icon, divider, disabled, selected, classes).apply { + init?.invoke( + this + ) } + this.add(selectOption) + return selectOption +} - /** - * DSL builder extension function. - * - * It takes the same parameters as the constructor of the built component. - */ - fun SelectOptGroup.selectOption( - value: String? = null, label: String? = null, subtext: String? = null, icon: String? = null, - divider: Boolean = false, disabled: Boolean = false, selected: Boolean = false, - classes: Set = setOf(), init: (SelectOption.() -> Unit)? = null - ): SelectOption { - val selectOption = - SelectOption(value, label, subtext, icon, divider, disabled, selected, classes).apply { - init?.invoke( - this - ) - } - this.add(selectOption) - return selectOption +/** + * DSL builder extension function. + * + * It takes the same parameters as the constructor of the built component. + */ +fun SelectOptGroup.selectOption( + value: String? = null, label: String? = null, subtext: String? = null, icon: String? = null, + divider: Boolean = false, disabled: Boolean = false, selected: Boolean = false, + classes: Set = setOf(), init: (SelectOption.() -> Unit)? = null +): SelectOption { + val selectOption = + SelectOption(value, label, subtext, icon, divider, disabled, selected, classes).apply { + init?.invoke( + this + ) } - - } + this.add(selectOption) + return selectOption } -- cgit