aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorRobert Jaros <rjaros@finn.pl>2017-09-02 22:58:49 +0200
committerRobert Jaros <rjaros@finn.pl>2017-09-02 22:58:49 +0200
commit64e2bca354a1eb6018086427365336c3acb75cb8 (patch)
tree0a154d36120fc731d5704d4320af3dba711de37b /src
parent0407e661dced3adcf8386b27738295e285a043a0 (diff)
downloadkvision-64e2bca354a1eb6018086427365336c3acb75cb8.tar.gz
kvision-64e2bca354a1eb6018086427365336c3acb75cb8.tar.bz2
kvision-64e2bca354a1eb6018086427365336c3acb75cb8.zip
Tag widget refactoring
Diffstat (limited to 'src')
-rw-r--r--src/main/kotlin/pl/treksoft/kvision/Showcase.kt2
-rw-r--r--src/main/kotlin/pl/treksoft/kvision/basic/Label.kt7
-rw-r--r--src/main/kotlin/pl/treksoft/kvision/html/InTag.kt48
-rw-r--r--src/main/kotlin/pl/treksoft/kvision/html/Tag.kt17
-rw-r--r--src/test/kotlin/test/pl/treksoft/kvision/html/TagSpec.kt38
5 files changed, 58 insertions, 54 deletions
diff --git a/src/main/kotlin/pl/treksoft/kvision/Showcase.kt b/src/main/kotlin/pl/treksoft/kvision/Showcase.kt
index caa66269..2a376f17 100644
--- a/src/main/kotlin/pl/treksoft/kvision/Showcase.kt
+++ b/src/main/kotlin/pl/treksoft/kvision/Showcase.kt
@@ -31,7 +31,7 @@ class Showcase : ApplicationBase() {
val p = Tag(TAG.P, "To jest prawo", align = ALIGN.RIGHT)
p.title = "Tytuł"
root.add(p)
- val del = InTag(INTAG.DEL, "To jest deleted")
+ val del = Tag(TAG.DEL, "To jest deleted")
root.add(del)
val list = ListTag(LIST.DL_HORIZ, listOf("abc", "de<b>fdasdasdasddasd</b>tdasdas", "Dasdsada", "dasdasdads"), true)
diff --git a/src/main/kotlin/pl/treksoft/kvision/basic/Label.kt b/src/main/kotlin/pl/treksoft/kvision/basic/Label.kt
index c0aa5ad2..cf0587db 100644
--- a/src/main/kotlin/pl/treksoft/kvision/basic/Label.kt
+++ b/src/main/kotlin/pl/treksoft/kvision/basic/Label.kt
@@ -1,7 +1,6 @@
package pl.treksoft.kvision.basic
-import pl.treksoft.kvision.html.InTag
-import pl.treksoft.kvision.html.INTAG
+import pl.treksoft.kvision.html.TAG
+import pl.treksoft.kvision.html.Tag
-open class Label(text: String, rich: Boolean = false) : InTag(INTAG.SPAN, text, rich) {
-} \ No newline at end of file
+open class Label(text: String, rich: Boolean = false) : Tag(TAG.SPAN, text, rich) \ No newline at end of file
diff --git a/src/main/kotlin/pl/treksoft/kvision/html/InTag.kt b/src/main/kotlin/pl/treksoft/kvision/html/InTag.kt
deleted file mode 100644
index 88f69435..00000000
--- a/src/main/kotlin/pl/treksoft/kvision/html/InTag.kt
+++ /dev/null
@@ -1,48 +0,0 @@
-package pl.treksoft.kvision.html
-
-import com.github.snabbdom.VNode
-import pl.treksoft.kvision.core.KVManager
-import pl.treksoft.kvision.core.Widget
-
-enum class INTAG(val tagName: String) {
- MARK("mark"),
- DEL("del"),
- S("s"),
- INS("ins"),
- U("u"),
- SMALL("small"),
- STRONG("strong"),
- EM("em"),
- CITE("cite"),
- CODE("code"),
- KBD("kbd"),
- VAR("var"),
- SAMP("samp"),
- SPAN("span")
-}
-
-open class InTag(type: INTAG, text: String, rich: Boolean = false, classes: Set<String> = setOf()) : Widget(classes) {
- var type = type
- set(value) {
- field = value
- refresh()
- }
- var text = text
- set(value) {
- field = value
- refresh()
- }
- var rich = rich
- set(value) {
- field = value
- refresh()
- }
-
- override fun render(): VNode {
- if (rich) {
- return kvh(type.tagName, arrayOf(KVManager.virtualize("<span>$text</span>")))
- } else {
- return kvh(type.tagName, arrayOf(text))
- }
- }
-} \ No newline at end of file
diff --git a/src/main/kotlin/pl/treksoft/kvision/html/Tag.kt b/src/main/kotlin/pl/treksoft/kvision/html/Tag.kt
index 60910707..4178fbfb 100644
--- a/src/main/kotlin/pl/treksoft/kvision/html/Tag.kt
+++ b/src/main/kotlin/pl/treksoft/kvision/html/Tag.kt
@@ -17,7 +17,22 @@ enum class TAG(val tagName: String) {
ADDRESS("address"),
BLOCKQUOTE("blockquote"),
FOOTER("footer"),
- PRE("pre")
+ PRE("pre"),
+
+ MARK("mark"),
+ DEL("del"),
+ S("s"),
+ INS("ins"),
+ U("u"),
+ SMALL("small"),
+ STRONG("strong"),
+ EM("em"),
+ CITE("cite"),
+ CODE("code"),
+ KBD("kbd"),
+ VAR("var"),
+ SAMP("samp"),
+ SPAN("span")
}
enum class ALIGN(val className: String) {
diff --git a/src/test/kotlin/test/pl/treksoft/kvision/html/TagSpec.kt b/src/test/kotlin/test/pl/treksoft/kvision/html/TagSpec.kt
new file mode 100644
index 00000000..1ba7f97b
--- /dev/null
+++ b/src/test/kotlin/test/pl/treksoft/kvision/html/TagSpec.kt
@@ -0,0 +1,38 @@
+package test.pl.treksoft.kvision.html
+
+import pl.treksoft.kvision.core.Root
+import pl.treksoft.kvision.html.ALIGN
+import pl.treksoft.kvision.html.TAG
+import pl.treksoft.kvision.html.Tag
+import test.pl.treksoft.kvision.DomSpec
+import kotlin.browser.document
+import kotlin.test.Test
+import kotlin.test.assertEquals
+import kotlin.test.assertTrue
+
+class TagSpec : DomSpec {
+
+ @Test
+ fun render() {
+ run {
+ val root = Root("test")
+ val tag = Tag(TAG.H1, "This is <b>h1</b>", rich = false, align = ALIGN.CENTER)
+ root.add(tag)
+ val element = document.getElementById("test")
+ assertEquals("<h1 class=\"text-center\">This is &lt;b&gt;h1&lt;/b&gt;</h1>", element?.innerHTML, "Should render correct html tag")
+ }
+ }
+
+ @Test
+ fun render_rich() {
+ run {
+ val root = Root("test")
+ val tag = Tag(TAG.H1, "This is <b>h1</b>", rich = true, align = ALIGN.CENTER)
+ root.add(tag)
+ val element = document.getElementById("test")
+ assertEquals("<h1 class=\"text-center\"><span>This is <b>h1</b></span></h1>", element?.innerHTML, "Should render correct html tag")
+ }
+ }
+
+
+} \ No newline at end of file