From 84cdfac30dcc2ab326113a54bc2110f55fc0a76a Mon Sep 17 00:00:00 2001 From: Davide Alberani Date: Tue, 16 Jan 2018 22:24:30 +0100 Subject: [PATCH] add basic templates --- .gitignore | 1 - diffido.py | 13 +++++++------ dist/base.html | 8 ++++++++ dist/diff.html | 5 +++++ dist/index.html | 6 ++++++ dist/page.html | 5 +++++ 6 files changed, 31 insertions(+), 7 deletions(-) create mode 100644 dist/base.html create mode 100644 dist/diff.html create mode 100644 dist/index.html create mode 100644 dist/page.html diff --git a/.gitignore b/.gitignore index fd4e7dc..2cdd8b0 100644 --- a/.gitignore +++ b/.gitignore @@ -2,7 +2,6 @@ node_modules/ storage/ __pycache__ -dist/ npm-debug*.log ssl/*.pem *.py[cod] diff --git a/diffido.py b/diffido.py index dcc68d3..e336360 100755 --- a/diffido.py +++ b/diffido.py @@ -86,15 +86,16 @@ class BaseHandler(tornado.web.RequestHandler): self.write({'error': True, 'message': message}) -class RootHandler(BaseHandler): +class TemplateHandler(BaseHandler): """Handler for the / path.""" app_path = os.path.join(os.path.dirname(__file__), "dist") @gen.coroutine def get(self, *args, **kwargs): - # serve the ./dist/index.html file - with open(self.app_path + "/index.html", 'r') as fd: - self.write(fd.read()) + page = 'index.html' + if args and args[0]: + page = args[0].strip('/') + self.render(page, **self.arguments) def serve(): @@ -128,10 +129,10 @@ def serve(): application = tornado.web.Application([ # (_days_path, DaysHandler, init_params), # (r'/v%s%s' % (API_VERSION, _days_path), DaysHandler, init_params), - (r"/(?:index.html)?", RootHandler, init_params), - (r'/?(.*)', tornado.web.StaticFileHandler, {"path": "dist"}) + (r"/?(.*)", TemplateHandler, init_params), ], static_path=os.path.join(os.path.dirname(__file__), "dist/static"), + template_path=os.path.join(os.path.dirname(__file__), 'dist/'), debug=options.debug) http_server = tornado.httpserver.HTTPServer(application, ssl_options=ssl_options or None) logger.info('Start serving on %s://%s:%d', 'https' if ssl_options else 'http', diff --git a/dist/base.html b/dist/base.html new file mode 100644 index 0000000..f50bf23 --- /dev/null +++ b/dist/base.html @@ -0,0 +1,8 @@ + + + {% block title %}diffido{% end %} + + + {% block body %}{% end %} + + diff --git a/dist/diff.html b/dist/diff.html new file mode 100644 index 0000000..775ea19 --- /dev/null +++ b/dist/diff.html @@ -0,0 +1,5 @@ +{% extends "base.html" %} + +{% block body %} +diff page {{ id }} +{% end %} diff --git a/dist/index.html b/dist/index.html new file mode 100644 index 0000000..6b626f2 --- /dev/null +++ b/dist/index.html @@ -0,0 +1,6 @@ +{% extends "base.html" %} + +{% block body %} +Index +setting 3; diff 3 +{% end %} diff --git a/dist/page.html b/dist/page.html new file mode 100644 index 0000000..1377b10 --- /dev/null +++ b/dist/page.html @@ -0,0 +1,5 @@ +{% extends "base.html" %} + +{% block body %} +setting page {{ id }} +{% end %}