aboutsummaryrefslogtreecommitdiff
path: root/src/main/kotlin/pl/treksoft/kvision/html
diff options
context:
space:
mode:
authorRobert Jaros <rjaros@finn.pl>2018-02-12 08:04:05 +0100
committerRobert Jaros <rjaros@finn.pl>2018-02-12 08:04:05 +0100
commit2feea5e7cf8d492663e826ebcfb0a58e61820352 (patch)
tree2586cefdd5bf15193158d92b53442608632cd9d9 /src/main/kotlin/pl/treksoft/kvision/html
parent4f1a7d4331ec802789009937cda5a1e0e2213cb4 (diff)
downloadkvision-2feea5e7cf8d492663e826ebcfb0a58e61820352.tar.gz
kvision-2feea5e7cf8d492663e826ebcfb0a58e61820352.tar.bz2
kvision-2feea5e7cf8d492663e826ebcfb0a58e61820352.zip
DSL syntax for containers
Diffstat (limited to 'src/main/kotlin/pl/treksoft/kvision/html')
-rw-r--r--src/main/kotlin/pl/treksoft/kvision/html/List.kt8
-rw-r--r--src/main/kotlin/pl/treksoft/kvision/html/Tag.kt8
2 files changed, 14 insertions, 2 deletions
diff --git a/src/main/kotlin/pl/treksoft/kvision/html/List.kt b/src/main/kotlin/pl/treksoft/kvision/html/List.kt
index c8252080..261555c9 100644
--- a/src/main/kotlin/pl/treksoft/kvision/html/List.kt
+++ b/src/main/kotlin/pl/treksoft/kvision/html/List.kt
@@ -51,10 +51,11 @@ enum class LISTTYPE(internal val tagName: String) {
* @param elements optional list of elements
* @param rich determines if [elements] can contain HTML code
* @param classes a set of CSS class names
+ * @param init an initializer extension function
*/
open class ListTag(
type: LISTTYPE, elements: List<String>? = null, rich: Boolean = false,
- classes: Set<String> = setOf()
+ classes: Set<String> = setOf(), init: (ListTag.() -> Unit)? = null
) : SimplePanel(classes) {
/**
* List type.
@@ -81,6 +82,11 @@ open class ListTag(
refresh()
}
+ init {
+ @Suppress("LeakingThis")
+ init?.invoke(this)
+ }
+
override fun render(): VNode {
val childrenElements = when (type) {
LISTTYPE.UL, LISTTYPE.OL, LISTTYPE.UNSTYLED, LISTTYPE.INLINE -> elements?.map { el ->
diff --git a/src/main/kotlin/pl/treksoft/kvision/html/Tag.kt b/src/main/kotlin/pl/treksoft/kvision/html/Tag.kt
index 557784b0..91fa2587 100644
--- a/src/main/kotlin/pl/treksoft/kvision/html/Tag.kt
+++ b/src/main/kotlin/pl/treksoft/kvision/html/Tag.kt
@@ -87,10 +87,11 @@ enum class ALIGN(val className: String) {
* @param rich determines if [text] can contain HTML code
* @param align text align
* @param classes a set of CSS class names
+ * @param init an initializer extension function
*/
open class Tag(
type: TAG, text: String? = null, rich: Boolean = false, align: ALIGN? = null,
- classes: Set<String> = setOf()
+ classes: Set<String> = setOf(), init: (Tag.() -> Unit)? = null
) : SimplePanel(classes) {
/**
@@ -126,6 +127,11 @@ open class Tag(
refresh()
}
+ init {
+ @Suppress("LeakingThis")
+ init?.invoke(this)
+ }
+
override fun render(): VNode {
return if (text != null) {
if (rich) {