Update app directory structure, add home and routes
This commit is contained in:
parent
d29dae1253
commit
5007a246fb
43
app.py
43
app.py
@ -1,42 +1,11 @@
|
|||||||
#!/usr/bin/env python
|
#!/usr/bin/env python
|
||||||
|
|
||||||
|
from atst.app import make_app
|
||||||
import tornado.ioloop
|
import tornado.ioloop
|
||||||
import tornado.web
|
|
||||||
import os
|
import os
|
||||||
from webassets import Environment, Bundle
|
|
||||||
|
|
||||||
# Set up assets.
|
app = make_app(debug=os.getenv('DEBUG',False))
|
||||||
static_path = os.path.join(os.path.dirname(__file__), "static")
|
port = 8888
|
||||||
scss_path = os.path.join(os.path.dirname(__file__), "scss")
|
app.listen(port)
|
||||||
assets = Environment(directory=scss_path, url='/static')
|
print("Listening on http://localhost:%i" % port)
|
||||||
css = Bundle('atat.scss', filters='scss', output='../static/assets/out.css')
|
tornado.ioloop.IOLoop.current().start()
|
||||||
assets.register('css', css)
|
|
||||||
helpers = {
|
|
||||||
'assets': assets
|
|
||||||
}
|
|
||||||
|
|
||||||
class MainHandler(tornado.web.RequestHandler):
|
|
||||||
|
|
||||||
def get_template_namespace(self):
|
|
||||||
ns = super(MainHandler, self).get_template_namespace()
|
|
||||||
ns.update(helpers)
|
|
||||||
return ns
|
|
||||||
|
|
||||||
def get(self):
|
|
||||||
self.render("hello.html.to")
|
|
||||||
|
|
||||||
def make_app():
|
|
||||||
app = tornado.web.Application([
|
|
||||||
(r"/", MainHandler),
|
|
||||||
],
|
|
||||||
debug=os.getenv('DEBUG',False),
|
|
||||||
template_path=os.path.join(os.path.dirname(__file__), "templates"),
|
|
||||||
static_path=static_path
|
|
||||||
)
|
|
||||||
return app
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
|
||||||
app = make_app()
|
|
||||||
app.listen(8888)
|
|
||||||
print("Listening on http://localhost:8888")
|
|
||||||
tornado.ioloop.IOLoop.current().start()
|
|
||||||
|
0
atst/__init__.py
Normal file
0
atst/__init__.py
Normal file
13
atst/app.py
Normal file
13
atst/app.py
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
import tornado.web
|
||||||
|
from atst.handlers.main import MainHandler
|
||||||
|
from atst.home import home
|
||||||
|
|
||||||
|
def make_app(**kwargs):
|
||||||
|
app = tornado.web.Application([
|
||||||
|
(r"/", MainHandler),
|
||||||
|
],
|
||||||
|
template_path = home.child('templates'),
|
||||||
|
static_path = home.child('static'),
|
||||||
|
**kwargs
|
||||||
|
)
|
||||||
|
return app
|
24
atst/handler.py
Normal file
24
atst/handler.py
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
import os
|
||||||
|
from webassets import Environment, Bundle
|
||||||
|
import tornado.web
|
||||||
|
from atst.home import home
|
||||||
|
|
||||||
|
class BaseHandler(tornado.web.RequestHandler):
|
||||||
|
|
||||||
|
def get_template_namespace(self):
|
||||||
|
assets = Environment(
|
||||||
|
directory = home.child('scss'),
|
||||||
|
url = '/static')
|
||||||
|
css = Bundle(
|
||||||
|
'atat.scss',
|
||||||
|
filters = 'scss',
|
||||||
|
output = '../static/assets/out.css')
|
||||||
|
|
||||||
|
assets.register( 'css', css )
|
||||||
|
helpers = {
|
||||||
|
'assets': assets
|
||||||
|
}
|
||||||
|
|
||||||
|
ns = super(BaseHandler, self).get_template_namespace()
|
||||||
|
ns.update(helpers)
|
||||||
|
return ns
|
0
atst/handlers/__init__.py
Normal file
0
atst/handlers/__init__.py
Normal file
5
atst/handlers/main.py
Normal file
5
atst/handlers/main.py
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
from atst.handler import BaseHandler
|
||||||
|
|
||||||
|
class MainHandler(BaseHandler):
|
||||||
|
def get(self):
|
||||||
|
self.render("hello.html.to")
|
3
atst/home.py
Normal file
3
atst/home.py
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
from unipath import Path
|
||||||
|
|
||||||
|
home = Path( __file__ ).parent.parent
|
@ -2,3 +2,4 @@ tornado==5.0.2
|
|||||||
webassets==0.12.1
|
webassets==0.12.1
|
||||||
pytest==3.6.0
|
pytest==3.6.0
|
||||||
pytest-tornado==0.5.0
|
pytest-tornado==0.5.0
|
||||||
|
Unipath==1.1
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
import pytest
|
import pytest
|
||||||
import tornado.web
|
import tornado.web
|
||||||
from app import make_app
|
from atst.app import make_app
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def app():
|
def app():
|
||||||
|
Loading…
x
Reference in New Issue
Block a user