Skip to content

Instantly share code, notes, and snippets.

@mkhl
Forked from FND/README.md
Last active November 2, 2017 10:42
Show Gist options
  • Save mkhl/5ffc09e7ed1b454104890ab30dada8d3 to your computer and use it in GitHub Desktop.
Save mkhl/5ffc09e7ed1b454104890ab30dada8d3 to your computer and use it in GitHub Desktop.
complate-wsgi sandbox
$ python3 -m venv venv
$ . venv/bin/activate

$ pip install js2py gunicorn

$ gunicorn app:app

http://localhost:8000

import js2py
class BufferedStream:
def __init__(self, callback):
self._callback = callback
def write(self, msg):
self._callback(msg.encode("utf-8"))
def transpile(filepath):
with open(filepath) as fh:
return js2py.eval_js(fh.read())
render = transpile("./views.js")
def app(environ, start_response):
write = start_response("200 OK", [("Content-Type", "text/html")])
stream = BufferedStream(write)
view = render(stream)
return ""
var render = (function() {
return function render(stream) {
stream.write("<h1>Hello World</h1>");
stream.write("<p>lorem ipsum dolor sit amet</p>");
};
}());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment