diff --git a/.gitignore b/.gitignore new file mode 100644 index 00000000..93e14570 --- /dev/null +++ b/.gitignore @@ -0,0 +1,5 @@ +node_modules +.sass-cache/ +static/fonts/* +.webassets-cache +scss/assets diff --git a/README.md b/README.md index bca802ef..45a9de95 100644 --- a/README.md +++ b/README.md @@ -9,7 +9,7 @@ pip install --upgrade pip pip install -r requirements.txt npm install - ./gen-css + gem install sass ## Running (development) @@ -17,10 +17,6 @@ To start the app and watch for changes: DEBUG=1 ./app.py -To rebuild css whenever the scss changes: - - ./gen-css --watch - ## Notes tornado templates are like mustache templates -- add the diff --git a/app.py b/app.py index e5dbda82..8c1f0c08 100755 --- a/app.py +++ b/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', filters='scss', output='../static/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() diff --git a/gen-css b/gen-css deleted file mode 100755 index ad996c67..00000000 --- a/gen-css +++ /dev/null @@ -1,14 +0,0 @@ -#!/bin/sh - -opts=$1 - -cp -a node_modules/uswds/dist/fonts static/ - -if [ "$opts" == "--watch" ]; then - set -x - sass --watch scss/atat.scss:static/assets/atat.css -else - set -x - sass scss/atat.scss > static/assets/atat.css -fi - diff --git a/requirements.txt b/requirements.txt index 041ebcb4..69d97d96 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1 +1,2 @@ tornado==5.0.2 +webassets==0.12.1 diff --git a/templates/base.html.to b/templates/base.html.to index 6d6f0b98..b50fb5c0 100644 --- a/templates/base.html.to +++ b/templates/base.html.to @@ -4,7 +4,9 @@ {% block title %}JEDI{% end %} - + {% for url in assets['css'].urls() %} + + {% end %}