diff options
author | Robert Jaros <rjaros@finn.pl> | 2019-10-17 21:58:34 +0200 |
---|---|---|
committer | Robert Jaros <rjaros@finn.pl> | 2019-10-17 21:58:34 +0200 |
commit | 736b80835f67c9c34657074ebcfbe0752bef1c18 (patch) | |
tree | 82d1e18a9ec07692dfe5dd31f470b842a9950a89 /src/main/kotlin/pl/treksoft/kvision/form/check | |
parent | 53b325d52208bfd44ba6a524ce3dda5379aed699 (diff) | |
download | kvision-736b80835f67c9c34657074ebcfbe0752bef1c18.tar.gz kvision-736b80835f67c9c34657074ebcfbe0752bef1c18.tar.bz2 kvision-736b80835f67c9c34657074ebcfbe0752bef1c18.zip |
Move DSL builder functions out of the companion objects (#93)
Diffstat (limited to 'src/main/kotlin/pl/treksoft/kvision/form/check')
6 files changed, 82 insertions, 88 deletions
diff --git a/src/main/kotlin/pl/treksoft/kvision/form/check/CheckBox.kt b/src/main/kotlin/pl/treksoft/kvision/form/check/CheckBox.kt index cb962850..ac25b30d 100644 --- a/src/main/kotlin/pl/treksoft/kvision/form/check/CheckBox.kt +++ b/src/main/kotlin/pl/treksoft/kvision/form/check/CheckBox.kt @@ -191,19 +191,19 @@ open class CheckBox( companion object { internal var counter = 0 - - /** - * DSL builder extension function. - * - * It takes the same parameters as the constructor of the built component. - */ - fun Container.checkBox( - value: Boolean = false, name: String? = null, label: String? = null, - rich: Boolean = false, init: (CheckBox.() -> Unit)? = null - ): CheckBox { - val checkBox = CheckBox(value, name, label, rich).apply { init?.invoke(this) } - this.add(checkBox) - return checkBox - } } } + +/** + * DSL builder extension function. + * + * It takes the same parameters as the constructor of the built component. + */ +fun Container.checkBox( + value: Boolean = false, name: String? = null, label: String? = null, + rich: Boolean = false, init: (CheckBox.() -> Unit)? = null +): CheckBox { + val checkBox = CheckBox(value, name, label, rich).apply { init?.invoke(this) } + this.add(checkBox) + return checkBox +} diff --git a/src/main/kotlin/pl/treksoft/kvision/form/check/CheckBoxInput.kt b/src/main/kotlin/pl/treksoft/kvision/form/check/CheckBoxInput.kt index ea58268d..ea8bf7db 100644 --- a/src/main/kotlin/pl/treksoft/kvision/form/check/CheckBoxInput.kt +++ b/src/main/kotlin/pl/treksoft/kvision/form/check/CheckBoxInput.kt @@ -33,21 +33,18 @@ import pl.treksoft.kvision.core.Container open class CheckBoxInput( value: Boolean = false, classes: Set<String> = setOf() -) : CheckInput(CheckInputType.CHECKBOX, value, classes) { +) : CheckInput(CheckInputType.CHECKBOX, value, classes) - companion object { - /** - * DSL builder extension function. - * - * It takes the same parameters as the constructor of the built component. - */ - fun Container.checkBoxInput( - value: Boolean = false, - classes: Set<String> = setOf(), init: (CheckInput.() -> Unit)? = null - ): CheckBoxInput { - val checkBoxInput = CheckBoxInput(value, classes).apply { init?.invoke(this) } - this.add(checkBoxInput) - return checkBoxInput - } - } +/** + * DSL builder extension function. + * + * It takes the same parameters as the constructor of the built component. + */ +fun Container.checkBoxInput( + value: Boolean = false, + classes: Set<String> = setOf(), init: (CheckInput.() -> Unit)? = null +): CheckBoxInput { + val checkBoxInput = CheckBoxInput(value, classes).apply { init?.invoke(this) } + this.add(checkBoxInput) + return checkBoxInput } diff --git a/src/main/kotlin/pl/treksoft/kvision/form/check/Radio.kt b/src/main/kotlin/pl/treksoft/kvision/form/check/Radio.kt index e9551196..bb73da60 100644 --- a/src/main/kotlin/pl/treksoft/kvision/form/check/Radio.kt +++ b/src/main/kotlin/pl/treksoft/kvision/form/check/Radio.kt @@ -206,19 +206,19 @@ open class Radio( companion object { internal var counter = 0 - - /** - * DSL builder extension function. - * - * It takes the same parameters as the constructor of the built component. - */ - fun Container.radio( - value: Boolean = false, extraValue: String? = null, name: String? = null, label: String? = null, - rich: Boolean = false, init: (Radio.() -> Unit)? = null - ): Radio { - val radio = Radio(value, extraValue, name, label, rich).apply { init?.invoke(this) } - this.add(radio) - return radio - } } } + +/** + * DSL builder extension function. + * + * It takes the same parameters as the constructor of the built component. + */ +fun Container.radio( + value: Boolean = false, extraValue: String? = null, name: String? = null, label: String? = null, + rich: Boolean = false, init: (Radio.() -> Unit)? = null +): Radio { + val radio = Radio(value, extraValue, name, label, rich).apply { init?.invoke(this) } + this.add(radio) + return radio +} diff --git a/src/main/kotlin/pl/treksoft/kvision/form/check/RadioGroup.kt b/src/main/kotlin/pl/treksoft/kvision/form/check/RadioGroup.kt index 14b426a3..bee57db4 100644 --- a/src/main/kotlin/pl/treksoft/kvision/form/check/RadioGroup.kt +++ b/src/main/kotlin/pl/treksoft/kvision/form/check/RadioGroup.kt @@ -227,19 +227,19 @@ open class RadioGroup( companion object { internal var counter = 0 - - /** - * DSL builder extension function. - * - * It takes the same parameters as the constructor of the built component. - */ - fun Container.radioGroup( - options: List<StringPair>? = null, value: String? = null, name: String? = null, inline: Boolean = false, - label: String? = null, rich: Boolean = false, init: (RadioGroup.() -> Unit)? = null - ): RadioGroup { - val radioGroup = RadioGroup(options, value, name, inline, label, rich).apply { init?.invoke(this) } - this.add(radioGroup) - return radioGroup - } } } + +/** + * DSL builder extension function. + * + * It takes the same parameters as the constructor of the built component. + */ +fun Container.radioGroup( + options: List<StringPair>? = null, value: String? = null, name: String? = null, inline: Boolean = false, + label: String? = null, rich: Boolean = false, init: (RadioGroup.() -> Unit)? = null +): RadioGroup { + val radioGroup = RadioGroup(options, value, name, inline, label, rich).apply { init?.invoke(this) } + this.add(radioGroup) + return radioGroup +} diff --git a/src/main/kotlin/pl/treksoft/kvision/form/check/RadioGroupInput.kt b/src/main/kotlin/pl/treksoft/kvision/form/check/RadioGroupInput.kt index d4301709..5a47c3ce 100644 --- a/src/main/kotlin/pl/treksoft/kvision/form/check/RadioGroupInput.kt +++ b/src/main/kotlin/pl/treksoft/kvision/form/check/RadioGroupInput.kt @@ -174,19 +174,19 @@ open class RadioGroupInput( companion object { internal var counter = 0 - - /** - * DSL builder extension function. - * - * It takes the same parameters as the constructor of the built component. - */ - fun Container.radioGroupInput( - options: List<StringPair>? = null, value: String? = null, name: String? = null, inline: Boolean = false, - init: (RadioGroupInput.() -> Unit)? = null - ): RadioGroupInput { - val radioGroupInput = RadioGroupInput(options, value, name, inline).apply { init?.invoke(this) } - this.add(radioGroupInput) - return radioGroupInput - } } } + +/** + * DSL builder extension function. + * + * It takes the same parameters as the constructor of the built component. + */ +fun Container.radioGroupInput( + options: List<StringPair>? = null, value: String? = null, name: String? = null, inline: Boolean = false, + init: (RadioGroupInput.() -> Unit)? = null +): RadioGroupInput { + val radioGroupInput = RadioGroupInput(options, value, name, inline).apply { init?.invoke(this) } + this.add(radioGroupInput) + return radioGroupInput +} diff --git a/src/main/kotlin/pl/treksoft/kvision/form/check/RadioInput.kt b/src/main/kotlin/pl/treksoft/kvision/form/check/RadioInput.kt index 9c6a1670..72bb4cd0 100644 --- a/src/main/kotlin/pl/treksoft/kvision/form/check/RadioInput.kt +++ b/src/main/kotlin/pl/treksoft/kvision/form/check/RadioInput.kt @@ -33,21 +33,18 @@ import pl.treksoft.kvision.core.Container open class RadioInput( value: Boolean = false, classes: Set<String> = setOf() -) : CheckInput(CheckInputType.RADIO, value, classes) { +) : CheckInput(CheckInputType.RADIO, value, classes) - companion object { - /** - * DSL builder extension function. - * - * It takes the same parameters as the constructor of the built component. - */ - fun Container.radioInput( - value: Boolean = false, - classes: Set<String> = setOf(), init: (CheckInput.() -> Unit)? = null - ): RadioInput { - val checkBoxInput = RadioInput(value, classes).apply { init?.invoke(this) } - this.add(checkBoxInput) - return checkBoxInput - } - } +/** + * DSL builder extension function. + * + * It takes the same parameters as the constructor of the built component. + */ +fun Container.radioInput( + value: Boolean = false, + classes: Set<String> = setOf(), init: (CheckInput.() -> Unit)? = null +): RadioInput { + val checkBoxInput = RadioInput(value, classes).apply { init?.invoke(this) } + this.add(checkBoxInput) + return checkBoxInput } |