From 4fcc479ed7656f675491c3563eff6c966118a30e Mon Sep 17 00:00:00 2001 From: raylu Date: Sat, 19 Oct 2013 18:30:23 -0700 Subject: switch to cleancss --- config.py | 1 + config.yaml.example | 1 + server.py | 58 ++++++++++++++++++++++++++++++++++++++++++++++++ web/server.py | 57 ----------------------------------------------- web/static/css/base.ccss | 31 ++++++++++++++++++++++++++ web/static/css/base.less | 37 ------------------------------ 6 files changed, 91 insertions(+), 94 deletions(-) create mode 100755 server.py delete mode 100755 web/server.py create mode 100644 web/static/css/base.ccss delete mode 100644 web/static/css/base.less diff --git a/config.py b/config.py index 1f9be4d..46df4d4 100644 --- a/config.py +++ b/config.py @@ -14,6 +14,7 @@ class WebConfig(Config): 'port', 'host', 'cookie_secret', + 'debug', ]) class DBConfig(Config): diff --git a/config.yaml.example b/config.yaml.example index 37a6e17..d521366 100644 --- a/config.yaml.example +++ b/config.yaml.example @@ -2,6 +2,7 @@ web: port: 8888 host: 'localhost:8888' cookie_secret: 'dis is super sekrit' + debug: true db: host: localhost diff --git a/server.py b/server.py new file mode 100755 index 0000000..7dcf2d3 --- /dev/null +++ b/server.py @@ -0,0 +1,58 @@ +#!/usr/bin/env python3 + +import json +import operator +import os + +import cleancss +import tornado.gen +import tornado.httpclient +import tornado.ioloop +import tornado.web + +from config import web as config + +class BaseHandler(tornado.web.RequestHandler): + def render(self, *args, **kwargs): + kwargs['host'] = config.host + return super(BaseHandler, self).render(*args, **kwargs) + + def render_string(self, *args, **kwargs): + s = super(BaseHandler, self).render_string(*args, **kwargs) + return s.replace(b'\n', b'') # this is like Django's {% spaceless %} + +class MainHandler(BaseHandler): + @tornado.web.asynchronous + @tornado.gen.coroutine + def get(self): + http_client = tornado.httpclient.AsyncHTTPClient() + kills_url = 'https://zkillboard.com/api/kills/corporationID/98182803/limit/1' + losses_url = 'https://zkillboard.com/api/losses/corporationID/98182803/limit/1' + kills_res, losses_res = yield [http_client.fetch(kills_url), http_client.fetch(losses_url)] + kills = json.loads(kills_res.body.decode('utf-8')) + losses = json.loads(losses_res.body.decode('utf-8')) + kills = sorted(kills + losses, key=operator.itemgetter('killTime'), reverse=True) + self.render('home.html', kills=kills) + + +class CSSHandler(tornado.web.RequestHandler): + def get(self, css_path): + css_path = os.path.join(os.path.dirname(__file__), 'web', 'static', css_path) + '.ccss' + with open(css_path, 'r') as f: + self.set_header('Content-Type', 'text/css') + self.write(cleancss.convert(f)) + + +if __name__ == '__main__': + tornado.web.Application( + handlers=[ + (r'/', MainHandler), + (r"/(css/.+)\.css", CSSHandler), + ], + template_path=os.path.join(os.path.dirname(__file__), 'templates'), + static_path=os.path.join(os.path.dirname(__file__), 'static'), + cookie_secret=config.cookie_secret, + debug=config.debug, + ).listen(config.port) + print('listening on :%d' % config.port) + tornado.ioloop.IOLoop.instance().start() diff --git a/web/server.py b/web/server.py deleted file mode 100755 index 01475c1..0000000 --- a/web/server.py +++ /dev/null @@ -1,57 +0,0 @@ -#!/usr/bin/env python3 - -import json -from lesscss import lessc -import tornado.gen -import tornado.httpclient -import tornado.ioloop -import tornado.web -import operator -import os - -import config - -class BaseHandler(tornado.web.RequestHandler): - def render(self, *args, **kwargs): - kwargs['host'] = config.web.host - return super(BaseHandler, self).render(*args, **kwargs) - - def render_string(self, *args, **kwargs): - s = super(BaseHandler, self).render_string(*args, **kwargs) - return s.replace(b'\n', b'') # this is like Django's {% spaceless %} - -class MainHandler(BaseHandler): - @tornado.web.asynchronous - @tornado.gen.coroutine - def get(self): - http_client = tornado.httpclient.AsyncHTTPClient() - kills_url = 'https://zkillboard.com/api/kills/corporationID/98182803/limit/1' - losses_url = 'https://zkillboard.com/api/losses/corporationID/98182803/limit/1' - kills_res, losses_res = yield [http_client.fetch(kills_url), http_client.fetch(losses_url)] - kills = json.loads(kills_res.body.decode('utf-8')) - losses = json.loads(losses_res.body.decode('utf-8')) - kills = sorted(kills + losses, key=operator.itemgetter('killTime'), reverse=True) - self.render('home.html', kills=kills) - - -class CSSHandler(tornado.web.RequestHandler): - def get(self, css_path): - css_path = os.path.join(os.path.dirname(__file__), 'static', css_path) + '.less' - with open(css_path, 'r') as f: - self.set_header('Content-Type', 'text/css') - css = lessc.compile(f.read()) - self.write(css) - -if __name__ == '__main__': - tornado.web.Application( - handlers=[ - (r'/', MainHandler), - (r"/(css/.+)\.css", CSSHandler), - ], - template_path=os.path.join(os.path.dirname(__file__), 'templates'), - static_path=os.path.join(os.path.dirname(__file__), 'static'), - cookie_secret=config.web.cookie_secret, - debug=True, - ).listen(config.web.port) - print('Listening on :%d' % config.web.port) - tornado.ioloop.IOLoop.instance().start() diff --git a/web/static/css/base.ccss b/web/static/css/base.ccss new file mode 100644 index 0000000..e515323 --- /dev/null +++ b/web/static/css/base.ccss @@ -0,0 +1,31 @@ +*: + box-sizing: border-box; + -moz-box-sizing: border-box; + -webkit-box-sizing: border-box; + +body: + margin: 0; + padding: 0; + height: 100%; + background: #000; + color: #ddd; + font-family: sans-serif; + +a: + text-decoration: none; + color: #dde; + +form: + input: + background: #fff; + border: 1px solid #cdd; + padding: 5px 10px; + } + +.clear: + clear: both; + +#wrapper: + width: 900px; + margin: 50px auto; + background: #111; diff --git a/web/static/css/base.less b/web/static/css/base.less deleted file mode 100644 index 714d5ab..0000000 --- a/web/static/css/base.less +++ /dev/null @@ -1,37 +0,0 @@ -* { - box-sizing: border-box; - -moz-box-sizing: border-box; - -webkit-box-sizing: border-box; -} - -body { - margin: 0; - padding: 0; - height: 100%; - background: #000; - color: #ddd; - font-family: sans-serif; -} - -a { - text-decoration: none; - color: #dde; -} - -form { - input { - background: #fff; - border: 1px solid #cdd; - padding: 5px 10px; - } -} - -.clear { - clear: both; -} - -#wrapper { - width: 900px; - margin: 50px auto; - background: #111; -} -- cgit v1.2.3