Better asset handling
This commit is contained in:
parent
d696540371
commit
de0fce88f1
5
.gitignore
vendored
Normal file
5
.gitignore
vendored
Normal file
@ -0,0 +1,5 @@
|
||||
node_modules
|
||||
.sass-cache/
|
||||
static/fonts/*
|
||||
.webassets-cache
|
||||
scss/assets
|
22
app.py
22
app.py
@ -3,19 +3,37 @@
|
||||
import tornado.ioloop
|
||||
import tornado.web
|
||||
import os
|
||||
from webassets import Environment, Bundle
|
||||
|
||||
# Set up assets.
|
||||
static_path = os.path.join(os.path.dirname(__file__), "static")
|
||||
scss_path = os.path.join(os.path.dirname(__file__), "scss")
|
||||
assets = Environment(directory=scss_path, url='/static')
|
||||
css = Bundle('atat.scss', output='assets/out.css')
|
||||
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():
|
||||
return tornado.web.Application([
|
||||
app = tornado.web.Application([
|
||||
(r"/", MainHandler),
|
||||
],
|
||||
debug=os.getenv('DEBUG',False),
|
||||
template_path=os.path.join(os.path.dirname(__file__), "templates"),
|
||||
static_path=os.path.join(os.path.dirname(__file__), "static"),
|
||||
static_path=static_path
|
||||
)
|
||||
return app
|
||||
|
||||
if __name__ == "__main__":
|
||||
app = make_app()
|
||||
|
@ -1 +1,2 @@
|
||||
tornado==5.0.2
|
||||
webassets==0.12.1
|
||||
|
@ -4,7 +4,9 @@
|
||||
<meta charset="utf-8">
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
||||
<title>{% block title %}JEDI{% end %}</title>
|
||||
<link rel="stylesheet" href="static/assets/atat.css">
|
||||
{% for url in assets['css'].urls() %}
|
||||
<link rel="stylesheet" href="{{ url }}" type="text/css">
|
||||
{% end %}
|
||||
</head>
|
||||
<body>
|
||||
<header class="usa-header usa-header-basic" role="banner">
|
||||
|
Loading…
x
Reference in New Issue
Block a user