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/upload/Upload.kt | 40 ++++----- .../pl/treksoft/kvision/form/upload/UploadInput.kt | 97 +++++++++++----------- 2 files changed, 67 insertions(+), 70 deletions(-) (limited to 'kvision-modules/kvision-bootstrap-upload/src/main/kotlin') diff --git a/kvision-modules/kvision-bootstrap-upload/src/main/kotlin/pl/treksoft/kvision/form/upload/Upload.kt b/kvision-modules/kvision-bootstrap-upload/src/main/kotlin/pl/treksoft/kvision/form/upload/Upload.kt index bd931127..67c660ea 100644 --- a/kvision-modules/kvision-bootstrap-upload/src/main/kotlin/pl/treksoft/kvision/form/upload/Upload.kt +++ b/kvision-modules/kvision-bootstrap-upload/src/main/kotlin/pl/treksoft/kvision/form/upload/Upload.kt @@ -308,26 +308,26 @@ open class Upload( companion object { internal var counter = 0 + } +} - /** - * DSL builder extension function. - * - * It takes the same parameters as the constructor of the built component. - */ - fun Container.upload( - uploadUrl: String? = null, - multiple: Boolean = false, - label: String? = null, - rich: Boolean = false, - init: (Upload.() -> Unit)? = null - ): Upload { - val upload = Upload(uploadUrl, multiple, label, rich).apply { - init?.invoke( - this - ) - } - this.add(upload) - return upload - } +/** + * DSL builder extension function. + * + * It takes the same parameters as the constructor of the built component. + */ +fun Container.upload( + uploadUrl: String? = null, + multiple: Boolean = false, + label: String? = null, + rich: Boolean = false, + init: (Upload.() -> Unit)? = null +): Upload { + val upload = Upload(uploadUrl, multiple, label, rich).apply { + init?.invoke( + this + ) } + this.add(upload) + return upload } diff --git a/kvision-modules/kvision-bootstrap-upload/src/main/kotlin/pl/treksoft/kvision/form/upload/UploadInput.kt b/kvision-modules/kvision-bootstrap-upload/src/main/kotlin/pl/treksoft/kvision/form/upload/UploadInput.kt index faae5274..da05b04c 100644 --- a/kvision-modules/kvision-bootstrap-upload/src/main/kotlin/pl/treksoft/kvision/form/upload/UploadInput.kt +++ b/kvision-modules/kvision-bootstrap-upload/src/main/kotlin/pl/treksoft/kvision/form/upload/UploadInput.kt @@ -320,58 +320,55 @@ open class UploadInput(uploadUrl: String? = null, multiple: Boolean = false, cla this.language = language } } +} - companion object { - - /** - * DSL builder extension function. - * - * It takes the same parameters as the constructor of the built component. - */ - fun Container.uploadInput( - uploadUrl: String? = null, - multiple: Boolean = false, - classes: Set = setOf(), - init: (UploadInput.() -> Unit)? = null - ): UploadInput { - val uploadInput = UploadInput(uploadUrl, multiple, classes).apply { - init?.invoke( - this - ) - } - this.add(uploadInput) - return uploadInput - } +/** + * DSL builder extension function. + * + * It takes the same parameters as the constructor of the built component. + */ +fun Container.uploadInput( + uploadUrl: String? = null, + multiple: Boolean = false, + classes: Set = setOf(), + init: (UploadInput.() -> Unit)? = null +): UploadInput { + val uploadInput = UploadInput(uploadUrl, multiple, classes).apply { + init?.invoke( + this + ) + } + this.add(uploadInput) + return uploadInput +} - /** - * Returns file with the content read. - * @param key key identifier of the control - * @param kFile object identifying the file - * @return KFile object - */ - suspend fun Form.getContent( - key: KProperty1?>, - kFile: KFile - ): KFile { - val control = getControl(key) as Upload - val content = control.getNativeFile(kFile)?.getContent() - return kFile.copy(content = content) - } +/** + * Returns file with the content read. + * @param key key identifier of the control + * @param kFile object identifying the file + * @return KFile object + */ +suspend fun Form.getContent( + key: KProperty1?>, + kFile: KFile +): KFile { + val control = getControl(key) as Upload + val content = control.getNativeFile(kFile)?.getContent() + return kFile.copy(content = content) +} - /** - * Returns file with the content read. - * @param key key identifier of the control - * @param kFile object identifying the file - * @return KFile object - */ - suspend fun FormPanel.getContent( - key: KProperty1?>, - kFile: KFile - ): KFile { - val control = getControl(key) as Upload - val content = control.getNativeFile(kFile)?.getContent() - return kFile.copy(content = content) - } - } +/** + * Returns file with the content read. + * @param key key identifier of the control + * @param kFile object identifying the file + * @return KFile object + */ +suspend fun FormPanel.getContent( + key: KProperty1?>, + kFile: KFile +): KFile { + val control = getControl(key) as Upload + val content = control.getNativeFile(kFile)?.getContent() + return kFile.copy(content = content) } -- cgit