Last active
September 2, 2018 02:07
-
-
Save zacharycarter/b68aded56439c77ebdf6022a729c61e8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<div> | |
<h1>Hello, World!</h1> | |
<h2>It is 8:44:27 PM.</h2> | |
</div> | |
tagged_template_literal.js:908:3 | |
<div> | |
<h1>Hello, World!</h1> | |
<h2>It is 8:44:28 PM.</h2> | |
</div> | |
tagged_template_literal.js:908:3 | |
<div> | |
<h1>Hello, World!</h1> | |
<h2>It is 8:44:29 PM.</h2> | |
</div> | |
tagged_template_literal.js:908:3 | |
<div> | |
<h1>Hello, World!</h1> | |
<h2>It is 8:44:30 PM.</h2> | |
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Hello, World! | |
It is 8:44:27 PM. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import dom, jsconsole, litz, jsffi | |
proc jsBind(p: JsObject, e: JsObject): JsObject {. importcpp: "#.bind(#)" .} | |
proc `^`(s: cstring): cstring {.importcpp: "eval('`' + # + '`')".} | |
proc t() {.html_templ.} = | |
# the 'html_templ' pragma provides | |
# a dsl for writing HTML | |
`div`: # could use 'd:' instead of '`div`:' - div is a reserved keyword in Nim | |
h1: "Hello, World!" | |
h2: "It is ${new Date().toLocaleTimeString()}." | |
proc renderT(t: cstring): JsObject = | |
var this {.nodecl, importc.}: JsObject | |
console.log(^t) | |
this.innerHTML = ^t | |
return this | |
proc tick(r: JsObject) = | |
var | |
t {.global.} = newT() | |
temp = t.render() | |
discard to(r, proc(t: cstring): JsObject)(temp) | |
proc litzb(e: Element): JsObject = | |
result = jsBind(toJs(renderT), toJs(e)) | |
discard window.setInterval(proc () = tick(litzb(document.body)), 1000) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="utf-8"> | |
<title>title</title> | |
</head> | |
<body> | |
<!-- page content --> | |
<script src="./nimcache/tagged_template_literal.js"></script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment