-
-
Save mkhl/5ffc09e7ed1b454104890ab30dada8d3 to your computer and use it in GitHub Desktop.
Revisions
-
mkhl revised this gist
Nov 2, 2017 . 1 changed file with 6 additions and 9 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -2,14 +2,11 @@ class BufferedStream: def __init__(self, callback): self._callback = callback def write(self, msg): self._callback(msg.encode("utf-8")) def transpile(filepath): @@ -21,8 +18,8 @@ def transpile(filepath): def app(environ, start_response): write = start_response("200 OK", [("Content-Type", "text/html")]) stream = BufferedStream(write) view = render(stream) return "" -
FND created this gist
Oct 28, 2017 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,8 @@ $ python3 -m venv venv $ . venv/bin/activate $ pip install js2py gunicorn $ gunicorn app:app → http://localhost:8000 This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,28 @@ import js2py class BufferedStream: def __init__(self): self._buffer = [] def write(self, msg): self._buffer.append(msg.encode("utf-8")) def __iter__(self): return iter(self._buffer) def transpile(filepath): with open(filepath) as fh: return js2py.eval_js(fh.read()) render = transpile("./views.js") def app(environ, start_response): start_response("200 OK", [("Content-Type", "text/html")]) stream = BufferedStream() view = render(stream) return stream This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,8 @@ var render = (function() { return function render(stream) { stream.write("<h1>Hello World</h1>"); stream.write("<p>lorem ipsum dolor sit amet</p>"); }; }());