From 9068686614a3cf87d6ca1cb3e42663df82d1e4bd Mon Sep 17 00:00:00 2001 From: Dominik Picheta Date: Wed, 23 May 2018 22:30:06 +0100 Subject: [PATCH] General improvements and fixes (#58) * Fixes Nimble package structure. * Improves readme. * Fixes compatibility with devel. * Add nice error message when ROOT is missing. * Pass responseText instead of statusText in ajax callbacks. * Implements verbatim node. * Apparently it should just be true all the time. * Small fix to readme. * Fixes verbatim node updates. * Move karun into the `karax` directory so that it's installable. --- karax.nimble | 4 ++-- karax/kajax.nim | 2 +- karax/karax.nim | 16 ++++++++++++++++ {tools => karax/tools}/karun.nim | 0 karax/vdom.nim | 9 ++++++++- readme.rst | 6 ++++-- 6 files changed, 31 insertions(+), 6 deletions(-) rename {tools => karax/tools}/karun.nim (100%) diff --git a/karax.nimble b/karax.nimble index bc49e03..743d85b 100644 --- a/karax.nimble +++ b/karax.nimble @@ -9,6 +9,6 @@ license = "MIT" requires "nim >= 0.16.1" -skipDirs = @["examples", "experiments"] +skipDirs = @["examples", "experiments", "tests"] -bin = @["tools/karun"] +bin = @["karax/tools/karun"] diff --git a/karax/kajax.nim b/karax/kajax.nim index 800d315..80184d1 100644 --- a/karax/kajax.nim +++ b/karax/kajax.nim @@ -38,7 +38,7 @@ proc ajax*(meth, url: cstring; headers: openarray[(cstring, cstring)]; if this.status == 200: contWrapper(this.status, this.responseText) else: - contWrapper(this.status, this.statusText) + contWrapper(this.status, this.responseText) if useBinary: ajax.send(blob) else: diff --git a/karax/karax.nim b/karax/karax.nim index 19a7dfb..bd3451c 100644 --- a/karax/karax.nim +++ b/karax/karax.nim @@ -4,6 +4,8 @@ import kdom, vdom, jstrutils, compact, jdict, vstyles export kdom.Event, kdom.Blob +{.experimental: "notnil".} + proc kout*[T](x: T) {.importc: "console.log", varargs, deprecated.} ## the preferred way of debugging karax applications. Now deprecated, ## you can now use ``system.echo`` instead. @@ -135,6 +137,10 @@ proc vnodeToDom*(n: VNode; kxi: KaraxInstance): Node = if n.kind == VNodeKind.text: result = document.createTextNode(n.text) attach n + elif n.kind == VNodeKind.verbatim: + result = document.createElement("div") + result.innerHTML = n.text + return result elif n.kind == VNodeKind.vthunk: let x = callThunk(vcomponents[n.text], n) result = vnodeToDom(x, kxi) @@ -183,6 +189,8 @@ proc same(n: VNode, e: Node; nesting = 0): bool = if kxi.orphans.contains(n.id): return true if n.kind == VNodeKind.component: result = same(VComponent(n).expanded, e, nesting+1) + elif n.kind == VNodeKind.verbatim: + result = true elif n.kind == VNodeKind.vthunk or n.kind == VNodeKind.dthunk: # we don't check these for now: result = true @@ -239,6 +247,9 @@ proc eq(a, b: VNode): EqResult = if a.len != b.len: return different for i in 0..