aboutsummaryrefslogtreecommitdiff
path: root/src/main/kotlin/pl/treksoft/kvision/html
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/kotlin/pl/treksoft/kvision/html')
-rw-r--r--src/main/kotlin/pl/treksoft/kvision/html/Div.kt4
-rw-r--r--src/main/kotlin/pl/treksoft/kvision/html/Label.kt4
-rw-r--r--src/main/kotlin/pl/treksoft/kvision/html/Tag.kt10
-rw-r--r--src/main/kotlin/pl/treksoft/kvision/html/Template.kt19
4 files changed, 30 insertions, 7 deletions
diff --git a/src/main/kotlin/pl/treksoft/kvision/html/Div.kt b/src/main/kotlin/pl/treksoft/kvision/html/Div.kt
index 6acc9d5b..42d6b496 100644
--- a/src/main/kotlin/pl/treksoft/kvision/html/Div.kt
+++ b/src/main/kotlin/pl/treksoft/kvision/html/Div.kt
@@ -34,7 +34,7 @@ import pl.treksoft.kvision.core.Container
* @param init an initializer extension function
*/
open class Div(
- content: String,
+ content: String? = null,
rich: Boolean = false,
align: Align? = null,
classes: Set<String> = setOf(),
@@ -54,7 +54,7 @@ open class Div(
* It takes the same parameters as the constructor of the built component.
*/
fun Container.div(
- content: String,
+ content: String? = null,
rich: Boolean = false,
align: Align? = null,
classes: Set<String> = setOf(),
diff --git a/src/main/kotlin/pl/treksoft/kvision/html/Label.kt b/src/main/kotlin/pl/treksoft/kvision/html/Label.kt
index 2ec45274..41406cf2 100644
--- a/src/main/kotlin/pl/treksoft/kvision/html/Label.kt
+++ b/src/main/kotlin/pl/treksoft/kvision/html/Label.kt
@@ -30,7 +30,7 @@ import pl.treksoft.kvision.core.Container
* @param content label text
* @param rich determines if [content] can contain HTML code
*/
-open class Label(content: String, rich: Boolean = false) : Tag(TAG.SPAN, content, rich) {
+open class Label(content: String? = null, rich: Boolean = false) : Tag(TAG.SPAN, content, rich) {
companion object {
/**
* DSL builder extension function.
@@ -38,7 +38,7 @@ open class Label(content: String, rich: Boolean = false) : Tag(TAG.SPAN, content
* It takes the same parameters as the constructor of the built component.
*/
fun Container.label(
- content: String, rich: Boolean = false, init: (Label.() -> Unit)? = null
+ content: String? = null, rich: Boolean = false, init: (Label.() -> Unit)? = null
): Label {
val label = Label(content, rich).apply { init?.invoke(this) }
this.add(label)
diff --git a/src/main/kotlin/pl/treksoft/kvision/html/Tag.kt b/src/main/kotlin/pl/treksoft/kvision/html/Tag.kt
index fce5acaa..936d7b89 100644
--- a/src/main/kotlin/pl/treksoft/kvision/html/Tag.kt
+++ b/src/main/kotlin/pl/treksoft/kvision/html/Tag.kt
@@ -104,7 +104,7 @@ enum class Align(val className: String) {
open class Tag(
type: TAG, content: String? = null, rich: Boolean = false, align: Align? = null,
classes: Set<String> = setOf(), init: (Tag.() -> Unit)? = null
-) : SimplePanel(classes) {
+) : SimplePanel(classes), Template {
/**
* Tag type.
@@ -113,15 +113,19 @@ open class Tag(
/**
* Text content of the tag.
*/
- var content by refreshOnUpdate(content)
+ override var content by refreshOnUpdate(content)
/**
* Determines if [content] can contain HTML code.
*/
- var rich by refreshOnUpdate(rich)
+ override var rich by refreshOnUpdate(rich)
/**
* Text align.
*/
var align by refreshOnUpdate(align)
+ /**
+ * Handlebars template.
+ */
+ override var template: (Any?) -> String by refreshOnUpdate()
init {
@Suppress("LeakingThis")
diff --git a/src/main/kotlin/pl/treksoft/kvision/html/Template.kt b/src/main/kotlin/pl/treksoft/kvision/html/Template.kt
new file mode 100644
index 00000000..f54c6115
--- /dev/null
+++ b/src/main/kotlin/pl/treksoft/kvision/html/Template.kt
@@ -0,0 +1,19 @@
+/*
+ * Copyright (c) 2018. Robert Jaros
+ */
+package pl.treksoft.kvision.html
+
+interface Template {
+ var content: String?
+ var rich: Boolean
+ var template: (Any?) -> String
+
+ var templateData: Any?
+ get() {
+ return null
+ }
+ set(value) {
+ if (!rich) rich = true
+ content = template(value)
+ }
+}