aboutsummaryrefslogtreecommitdiff
path: root/src/main/kotlin/pl/treksoft/kvision/table
diff options
context:
space:
mode:
authorRobert Jaros <rjaros@finn.pl>2019-10-17 21:58:34 +0200
committerRobert Jaros <rjaros@finn.pl>2019-10-17 21:58:34 +0200
commit736b80835f67c9c34657074ebcfbe0752bef1c18 (patch)
tree82d1e18a9ec07692dfe5dd31f470b842a9950a89 /src/main/kotlin/pl/treksoft/kvision/table
parent53b325d52208bfd44ba6a524ce3dda5379aed699 (diff)
downloadkvision-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/table')
-rw-r--r--src/main/kotlin/pl/treksoft/kvision/table/Cell.kt63
-rw-r--r--src/main/kotlin/pl/treksoft/kvision/table/HeaderCell.kt35
-rw-r--r--src/main/kotlin/pl/treksoft/kvision/table/Row.kt28
-rw-r--r--src/main/kotlin/pl/treksoft/kvision/table/Table.kt32
4 files changed, 73 insertions, 85 deletions
diff --git a/src/main/kotlin/pl/treksoft/kvision/table/Cell.kt b/src/main/kotlin/pl/treksoft/kvision/table/Cell.kt
index 44646897..4cf72f77 100644
--- a/src/main/kotlin/pl/treksoft/kvision/table/Cell.kt
+++ b/src/main/kotlin/pl/treksoft/kvision/table/Cell.kt
@@ -47,39 +47,36 @@ open class Cell(
@Suppress("LeakingThis")
init?.invoke(this)
}
+}
- companion object {
- /**
- * DSL builder extension function.
- *
- * It takes the same parameters as the constructor of the built component.
- */
- fun Row.cell(
- content: String? = null,
- rich: Boolean = false,
- align: Align? = null,
- classes: Set<String> = setOf(), init: (Cell.() -> Unit)? = null
- ): Cell {
- val cell = Cell(content, rich, align, classes, init)
- this.add(cell)
- return cell
- }
-
- /**
- * DSL builder extension function.
- *
- * It takes the same parameters as the constructor of the built component.
- */
- fun Row.thcell(
- content: String? = null,
- rich: Boolean = false,
- align: Align? = null,
- classes: Set<String> = setOf(), init: (HeaderCell.() -> Unit)? = null
- ): HeaderCell {
- val headerCell = HeaderCell(content, rich, align, Scope.ROW, classes, init)
- this.add(headerCell)
- return headerCell
- }
- }
+/**
+ * DSL builder extension function.
+ *
+ * It takes the same parameters as the constructor of the built component.
+ */
+fun Row.cell(
+ content: String? = null,
+ rich: Boolean = false,
+ align: Align? = null,
+ classes: Set<String> = setOf(), init: (Cell.() -> Unit)? = null
+): Cell {
+ val cell = Cell(content, rich, align, classes, init)
+ this.add(cell)
+ return cell
+}
+/**
+ * DSL builder extension function.
+ *
+ * It takes the same parameters as the constructor of the built component.
+ */
+fun Row.thcell(
+ content: String? = null,
+ rich: Boolean = false,
+ align: Align? = null,
+ classes: Set<String> = setOf(), init: (HeaderCell.() -> Unit)? = null
+): HeaderCell {
+ val headerCell = HeaderCell(content, rich, align, Scope.ROW, classes, init)
+ this.add(headerCell)
+ return headerCell
}
diff --git a/src/main/kotlin/pl/treksoft/kvision/table/HeaderCell.kt b/src/main/kotlin/pl/treksoft/kvision/table/HeaderCell.kt
index 14527f0f..f7f45784 100644
--- a/src/main/kotlin/pl/treksoft/kvision/table/HeaderCell.kt
+++ b/src/main/kotlin/pl/treksoft/kvision/table/HeaderCell.kt
@@ -57,24 +57,21 @@ open class HeaderCell(
@Suppress("LeakingThis")
init?.invoke(this)
}
+}
- companion object {
- /**
- * DSL builder extension function.
- *
- * It takes the same parameters as the constructor of the built component.
- */
- fun Row.headerCell(
- content: String? = null,
- rich: Boolean = false,
- align: Align? = null,
- scope: Scope? = null,
- classes: Set<String> = setOf(), init: (HeaderCell.() -> Unit)? = null
- ): HeaderCell {
- val cell = HeaderCell(content, rich, align, scope, classes, init)
- this.add(cell)
- return cell
- }
- }
-
+/**
+ * DSL builder extension function.
+ *
+ * It takes the same parameters as the constructor of the built component.
+ */
+fun Row.headerCell(
+ content: String? = null,
+ rich: Boolean = false,
+ align: Align? = null,
+ scope: Scope? = null,
+ classes: Set<String> = setOf(), init: (HeaderCell.() -> Unit)? = null
+): HeaderCell {
+ val cell = HeaderCell(content, rich, align, scope, classes, init)
+ this.add(cell)
+ return cell
}
diff --git a/src/main/kotlin/pl/treksoft/kvision/table/Row.kt b/src/main/kotlin/pl/treksoft/kvision/table/Row.kt
index 34ce3471..0681953f 100644
--- a/src/main/kotlin/pl/treksoft/kvision/table/Row.kt
+++ b/src/main/kotlin/pl/treksoft/kvision/table/Row.kt
@@ -34,25 +34,21 @@ import pl.treksoft.kvision.html.Tag
open class Row(classes: Set<String> = setOf(), init: (Row.() -> Unit)? = null) : Tag(
TAG.TR, classes = classes
) {
-
init {
@Suppress("LeakingThis")
init?.invoke(this)
}
+}
- companion object {
- /**
- * DSL builder extension function.
- *
- * It takes the same parameters as the constructor of the built component.
- */
- fun Table.row(
- classes: Set<String> = setOf(), init: (Row.() -> Unit)? = null
- ): Row {
- val row = Row(classes, init)
- this.add(row)
- return row
- }
- }
-
+/**
+ * DSL builder extension function.
+ *
+ * It takes the same parameters as the constructor of the built component.
+ */
+fun Table.row(
+ classes: Set<String> = setOf(), init: (Row.() -> Unit)? = null
+): Row {
+ val row = Row(classes, init)
+ this.add(row)
+ return row
}
diff --git a/src/main/kotlin/pl/treksoft/kvision/table/Table.kt b/src/main/kotlin/pl/treksoft/kvision/table/Table.kt
index 6d7c9b6e..114e3dfa 100644
--- a/src/main/kotlin/pl/treksoft/kvision/table/Table.kt
+++ b/src/main/kotlin/pl/treksoft/kvision/table/Table.kt
@@ -200,22 +200,20 @@ open class Table(
override fun getChildren(): List<Component> {
return tbody.getChildren()
}
+}
- companion object {
- /**
- * DSL builder extension function.
- *
- * It takes the same parameters as the constructor of the built component.
- */
- fun Container.table(
- headerNames: List<String>? = null,
- types: Set<TableType> = setOf(), caption: String? = null, responsiveType: ResponsiveType? = null,
- theadType: TheadType? = null, classes: Set<String> = setOf(), init: (Table.() -> Unit)? = null
- ): Table {
- val table =
- Table(headerNames, types, caption, responsiveType, theadType, classes, init)
- this.add(table)
- return table
- }
- }
+/**
+ * DSL builder extension function.
+ *
+ * It takes the same parameters as the constructor of the built component.
+ */
+fun Container.table(
+ headerNames: List<String>? = null,
+ types: Set<TableType> = setOf(), caption: String? = null, responsiveType: ResponsiveType? = null,
+ theadType: TheadType? = null, classes: Set<String> = setOf(), init: (Table.() -> Unit)? = null
+): Table {
+ val table =
+ Table(headerNames, types, caption, responsiveType, theadType, classes, init)
+ this.add(table)
+ return table
}