From 7b246d0d40612e230cd53bbbb535428711aff585 Mon Sep 17 00:00:00 2001 From: Fabian Keller Date: Sat, 17 Jun 2017 16:57:36 +0200 Subject: [PATCH 1/5] added travis link --- readme.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/readme.rst b/readme.rst index 4aafac8..13e670a 100644 --- a/readme.rst +++ b/readme.rst @@ -1,4 +1,4 @@ -Karax -- Single page applications in Nim +Karax – Single page applications in Nim [![Build Status](https://travis-ci.org/pragmagic/karax.svg?branch=master)](https://travis-ci.org/pragmagic/karax) ======================================== Karax is a framework for developing single page applications in Nim. From 972fcb0950a275e06f3fab0b054d264cc386fdbd Mon Sep 17 00:00:00 2001 From: Fabian Keller Date: Sat, 17 Jun 2017 17:05:37 +0200 Subject: [PATCH 2/5] proper rst solution --- readme.rst | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/readme.rst b/readme.rst index 13e670a..3fac7ad 100644 --- a/readme.rst +++ b/readme.rst @@ -1,5 +1,5 @@ -Karax – Single page applications in Nim [![Build Status](https://travis-ci.org/pragmagic/karax.svg?branch=master)](https://travis-ci.org/pragmagic/karax) -======================================== +Karax – Single page applications in Nim |travis| +================================================ Karax is a framework for developing single page applications in Nim. It's still in heavy development, so keep in mind that the API is subject @@ -33,3 +33,6 @@ Goals - Leverage Nim's macro system to produce a framework that allows for the development of applications that are boilerplate free. - Keep it small, keep it fast, keep it flexible. + +.. |travis| image:: https://travis-ci.org/pragmagic/karax.svg?branch=master + :target: https://travis-ci.org/pragmagic/karax From b189b24a4f6f3afb5856db9634a55cbf6ca86375 Mon Sep 17 00:00:00 2001 From: Fabian Keller Date: Sun, 18 Jun 2017 00:01:27 +0200 Subject: [PATCH 3/5] fixes #25 (#26) --- .gitignore | 1 + src/karaxdsl.nim | 10 ++++++++-- tests/compiler_tests.nim | 18 ++++++++++++++++++ tests/{diffDomTests.nims => nim.cfg} | 0 tests/tester.nim | 1 + 5 files changed, 28 insertions(+), 2 deletions(-) create mode 100644 tests/compiler_tests.nim rename tests/{diffDomTests.nims => nim.cfg} (100%) diff --git a/.gitignore b/.gitignore index 67d9b34..42b07a7 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ nimcache/ +/tests/tester \ No newline at end of file diff --git a/src/karaxdsl.nim b/src/karaxdsl.nim index a3558c8..e3e8290 100644 --- a/src/karaxdsl.nim +++ b/src/karaxdsl.nim @@ -47,12 +47,18 @@ proc tcall2(n, tmpContext: NimNode): NimNode = assert n.len == result.len if L > 0: result[L-1] = tcall2(result[L-1], tmpContext) - of nnkStmtList, nnkStmtListExpr, nnkWhenStmt, nnkIfStmt, nnkCaseStmt, - nnkTryStmt, nnkFinally: + of nnkStmtList, nnkStmtListExpr, nnkWhenStmt, nnkIfStmt, nnkTryStmt, + nnkFinally: # recurse for every child: result = copyNimNode(n) for x in n: result.add tcall2(x, tmpContext) + of nnkCaseStmt: + # recurse for children, but don't add call for case ident + result = copyNimNode(n) + result.add n[0] + for i in 1 ..< n.len: + result.add tcall2(n[i], tmpContext) of nnkVarSection, nnkLetSection, nnkConstSection: result = n of nnkCallKinds: diff --git a/tests/compiler_tests.nim b/tests/compiler_tests.nim new file mode 100644 index 0000000..4352cab --- /dev/null +++ b/tests/compiler_tests.nim @@ -0,0 +1,18 @@ +include karaxprelude + +block: + type + TestEnum {.pure.} = enum + ValA, ValB + + var e = TestEnum.ValA + + proc renderDom(): VNode {.used.} = + result = buildHtml(): + tdiv(): + case e + of TestEnum.ValA: + tdiv: text "A" + of TestEnum.ValB: + tdiv: text "B" + diff --git a/tests/diffDomTests.nims b/tests/nim.cfg similarity index 100% rename from tests/diffDomTests.nims rename to tests/nim.cfg diff --git a/tests/tester.nim b/tests/tester.nim index 5dc7426..482cad3 100644 --- a/tests/tester.nim +++ b/tests/tester.nim @@ -8,6 +8,7 @@ proc exec(cmd: string) = proc main = exec("nim js tests/diffDomTests.nim") + exec("nim js tests/compiler_tests.nim") exec("nim js examples/todoapp/todoapp.nim") exec("nim js examples/scrollapp/scrollapp.nim") exec("nim js examples/mediaplayer/playerapp.nim") From e58cbb78d20c94490a86337b5316a69ce0831884 Mon Sep 17 00:00:00 2001 From: Andreas Rumpf Date: Wed, 21 Jun 2017 08:21:05 +0200 Subject: [PATCH 4/5] fixes jstrutils.isInt --- src/jstrutils.nim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/jstrutils.nim b/src/jstrutils.nim index 0be4076..f0f22c0 100644 --- a/src/jstrutils.nim +++ b/src/jstrutils.nim @@ -19,7 +19,7 @@ proc `&`*(s: cstring): cstring {.importcpp: "(#)", nodecl.} proc isInt*(s: cstring): bool {.asmNoStackFrame.} = asm """ - return s.match(/^[0-9]+$/); + return `s`.match(/^[0-9]+$/); """ proc parseInt*(s: cstring): int {.importcpp: "parseInt(#, 10)", nodecl.} From 8dbc1da708a7e48433f335e4b76e02a30e47e638 Mon Sep 17 00:00:00 2001 From: Andreas Rumpf Date: Wed, 21 Jun 2017 18:20:57 +0200 Subject: [PATCH 5/5] fixes #28 --- src/jstrutils.nim | 1 + src/vstyles.nim | 8 ++++++++ 2 files changed, 9 insertions(+) diff --git a/src/jstrutils.nim b/src/jstrutils.nim index 63a9ae8..507e7a6 100644 --- a/src/jstrutils.nim +++ b/src/jstrutils.nim @@ -14,6 +14,7 @@ proc `&`*(a, b: cstring): cstring {.importcpp: "(# + #)", nodecl.} proc toCstr*(s: int): cstring {.importcpp: "((#)+'')", nodecl.} proc `&`*(s: int): cstring {.importcpp: "((#)+'')", nodecl.} proc `&`*(s: bool): cstring {.importcpp: "((#)+'')", nodecl.} +proc `&`*(s: float): cstring {.importcpp: "((#)+'')", nodecl.} proc `&`*(s: cstring): cstring {.importcpp: "(#)", nodecl.} diff --git a/src/vstyles.nim b/src/vstyles.nim index 649c322..161c207 100644 --- a/src/vstyles.nim +++ b/src/vstyles.nim @@ -255,3 +255,11 @@ proc applyStyle*(n: Node; s: VStyle) = n.style = Style() for x in s.mask: n.style.setStyle(toStyleAttrName[x], s.attrs[x]) + +import jstrutils + +proc rgb*(r, g, b: range[0..255]): cstring = + cstring"rgb(" & &r & cstring", " & &g & cstring", " & &b & cstring")" + +proc rgba*(r, g, b: range[0..255], alpha: float): cstring = + cstring"rgb(" & &r & cstring", " & &g & cstring", " & &b & cstring", " & &alpha & cstring")"