add basic templates

This commit is contained in:
Davide Alberani 2018-01-16 22:24:30 +01:00
parent 6a1b632dcb
commit 84cdfac30d
6 changed files with 31 additions and 7 deletions

1
.gitignore vendored
View file

@ -2,7 +2,6 @@
node_modules/ node_modules/
storage/ storage/
__pycache__ __pycache__
dist/
npm-debug*.log npm-debug*.log
ssl/*.pem ssl/*.pem
*.py[cod] *.py[cod]

View file

@ -86,15 +86,16 @@ class BaseHandler(tornado.web.RequestHandler):
self.write({'error': True, 'message': message}) self.write({'error': True, 'message': message})
class RootHandler(BaseHandler): class TemplateHandler(BaseHandler):
"""Handler for the / path.""" """Handler for the / path."""
app_path = os.path.join(os.path.dirname(__file__), "dist") app_path = os.path.join(os.path.dirname(__file__), "dist")
@gen.coroutine @gen.coroutine
def get(self, *args, **kwargs): def get(self, *args, **kwargs):
# serve the ./dist/index.html file page = 'index.html'
with open(self.app_path + "/index.html", 'r') as fd: if args and args[0]:
self.write(fd.read()) page = args[0].strip('/')
self.render(page, **self.arguments)
def serve(): def serve():
@ -128,10 +129,10 @@ def serve():
application = tornado.web.Application([ application = tornado.web.Application([
# (_days_path, DaysHandler, init_params), # (_days_path, DaysHandler, init_params),
# (r'/v%s%s' % (API_VERSION, _days_path), DaysHandler, init_params), # (r'/v%s%s' % (API_VERSION, _days_path), DaysHandler, init_params),
(r"/(?:index.html)?", RootHandler, init_params), (r"/?(.*)", TemplateHandler, init_params),
(r'/?(.*)', tornado.web.StaticFileHandler, {"path": "dist"})
], ],
static_path=os.path.join(os.path.dirname(__file__), "dist/static"), static_path=os.path.join(os.path.dirname(__file__), "dist/static"),
template_path=os.path.join(os.path.dirname(__file__), 'dist/'),
debug=options.debug) debug=options.debug)
http_server = tornado.httpserver.HTTPServer(application, ssl_options=ssl_options or None) 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', logger.info('Start serving on %s://%s:%d', 'https' if ssl_options else 'http',

8
dist/base.html vendored Normal file
View file

@ -0,0 +1,8 @@
<html>
<head>
<title>{% block title %}diffido{% end %}</title>
</head>
<body>
{% block body %}{% end %}
</body>
</html>

5
dist/diff.html vendored Normal file
View file

@ -0,0 +1,5 @@
{% extends "base.html" %}
{% block body %}
diff page {{ id }}
{% end %}

6
dist/index.html vendored Normal file
View file

@ -0,0 +1,6 @@
{% extends "base.html" %}
{% block body %}
Index
<a href="/page.html/?id=3">setting 3</a>; <a href="/diff.html?id=3">diff 3</a>
{% end %}

5
dist/page.html vendored Normal file
View file

@ -0,0 +1,5 @@
{% extends "base.html" %}
{% block body %}
setting page {{ id }}
{% end %}