From b99a5430f0cd8abcf086cb774c728da498ee6ebe Mon Sep 17 00:00:00 2001 From: Zed <9434921+zedeus@users.noreply.github.com> Date: Wed, 10 Jul 2019 14:46:08 +0200 Subject: [PATCH] Add support for rendering styles to string (#102) --- karax/vdom.nim | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/karax/vdom.nim b/karax/vdom.nim index 56cf9e6..7f8dcb7 100644 --- a/karax/vdom.nim +++ b/karax/vdom.nim @@ -8,7 +8,7 @@ else: Node* = ref object import macros, vstyles, kbase -from strutils import toUpperAscii +from strutils import toUpperAscii, toLowerAscii, tokenize type VNodeKind* {.pure.} = enum @@ -399,7 +399,17 @@ proc add*(result: var string, n: VNode, indent = 0, indWidth = 2) = result.add("=\"") result.addEscapedAttr(v) result.add('"') - # XXX add style to string + if n.style != nil: + result.add " style=\"" + for k, v in pairs(n.style): + if v.len == 0: continue + for t in tokenize($k, seps={'A' .. 'Z'}): + if t.isSep: result.add '-' + result.add toLowerAscii(t.token) + result.add ": " + result.add v + result.add "; " + result.add('"') if n.len > 0: result.add('>') if n.len > 1: