aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/main/kotlin/pl/treksoft/kvision/html/Tag.kt7
-rw-r--r--src/test/kotlin/test/pl/treksoft/kvision/html/TagSpec.kt19
2 files changed, 25 insertions, 1 deletions
diff --git a/src/main/kotlin/pl/treksoft/kvision/html/Tag.kt b/src/main/kotlin/pl/treksoft/kvision/html/Tag.kt
index 48f6a9eb..f3f41939 100644
--- a/src/main/kotlin/pl/treksoft/kvision/html/Tag.kt
+++ b/src/main/kotlin/pl/treksoft/kvision/html/Tag.kt
@@ -172,6 +172,13 @@ open class Tag(
return cl
}
+ operator fun String.unaryPlus() {
+ if (content == null)
+ content = this
+ else
+ content += this
+ }
+
companion object {
/**
* DSL builder extension function.
diff --git a/src/test/kotlin/test/pl/treksoft/kvision/html/TagSpec.kt b/src/test/kotlin/test/pl/treksoft/kvision/html/TagSpec.kt
index 91c6df81..29a5c079 100644
--- a/src/test/kotlin/test/pl/treksoft/kvision/html/TagSpec.kt
+++ b/src/test/kotlin/test/pl/treksoft/kvision/html/TagSpec.kt
@@ -78,4 +78,21 @@ class TagSpec : DomSpec {
)
}
}
-} \ No newline at end of file
+
+ @Test
+ fun renderUnaryPlus() {
+ run {
+ val root = Root("test", true)
+ val tag = Tag(TAG.H1, rich = true) {
+ +"This is <b>h1</b>"
+ }
+ root.add(tag)
+ val element = document.getElementById("test")
+ assertEqualsHtml(
+ "<h1><span>This is <b>h1</b></span></h1>",
+ element?.innerHTML,
+ "Should render correct html tag with children"
+ )
+ }
+ }
+}