From dc535d9d6d04dc033dbf528c476e39a31b586773 Mon Sep 17 00:00:00 2001 From: Taka Date: Sat, 7 Jul 2018 03:16:53 +0000 Subject: [PATCH] Added infrastructure for generating HTML snippets. --- .pylintrc | 1 + MANIFEST.in | 1 + vasl_templates/webapp/config/constants.py | 1 + .../webapp/data/default-templates/scenario.j2 | 3 + .../default-templates/victory_conditions.j2 | 1 + vasl_templates/webapp/generate.py | 23 + vasl_templates/webapp/static/css/main.css | 37 +- .../webapp/static/growl/jquery.growl.css | 96 +++ .../webapp/static/growl/jquery.growl.js | 311 ++++++++++ vasl_templates/webapp/static/jinja.js | 577 ++++++++++++++++++ .../static/{jquery => }/jquery-3.3.1.min.js | 0 vasl_templates/webapp/static/main.js | 80 ++- vasl_templates/webapp/static/utils.js | 112 ++++ vasl_templates/webapp/templates/main.html | 22 +- vasl_templates/webapp/tests/conftest.py | 6 +- vasl_templates/webapp/tests/test_generate.py | 96 ++- vasl_templates/webapp/tests/utils.py | 20 + 17 files changed, 1378 insertions(+), 9 deletions(-) create mode 100644 vasl_templates/webapp/data/default-templates/scenario.j2 create mode 100644 vasl_templates/webapp/data/default-templates/victory_conditions.j2 create mode 100644 vasl_templates/webapp/static/growl/jquery.growl.css create mode 100644 vasl_templates/webapp/static/growl/jquery.growl.js create mode 100644 vasl_templates/webapp/static/jinja.js rename vasl_templates/webapp/static/{jquery => }/jquery-3.3.1.min.js (100%) create mode 100644 vasl_templates/webapp/static/utils.js diff --git a/.pylintrc b/.pylintrc index fa3b444..543224a 100644 --- a/.pylintrc +++ b/.pylintrc @@ -135,6 +135,7 @@ disable=print-statement, exception-escape, comprehension-escape, bad-whitespace, + bad-continuation, invalid-name, wrong-import-position diff --git a/MANIFEST.in b/MANIFEST.in index b0d0e4a..94c8037 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -1,3 +1,4 @@ recursive-include vasl_templates/webapp/config *.* +recursive-include vasl_templates/webapp/data *.* recursive-include vasl_templates/webapp/static *.* recursive-include vasl_templates/webapp/templates *.* diff --git a/vasl_templates/webapp/config/constants.py b/vasl_templates/webapp/config/constants.py index 58efbd8..1c0c215 100644 --- a/vasl_templates/webapp/config/constants.py +++ b/vasl_templates/webapp/config/constants.py @@ -7,3 +7,4 @@ APP_VERSION = "v0.1" APP_DESCRIPTION = "Generate HTML for use in VASL scenarios." BASE_DIR = os.path.abspath( os.path.join( os.path.split(__file__)[0], ".." ) ) +DATA_DIR = os.path.join( BASE_DIR, "data" ) diff --git a/vasl_templates/webapp/data/default-templates/scenario.j2 b/vasl_templates/webapp/data/default-templates/scenario.j2 new file mode 100644 index 0000000..aebf3fa --- /dev/null +++ b/vasl_templates/webapp/data/default-templates/scenario.j2 @@ -0,0 +1,3 @@ +name = [{{SCENARIO_NAME}}] +loc = [{{SCENARIO_LOCATION}}] +date = [{{SCENARIO_DATE}}] diff --git a/vasl_templates/webapp/data/default-templates/victory_conditions.j2 b/vasl_templates/webapp/data/default-templates/victory_conditions.j2 new file mode 100644 index 0000000..03aa799 --- /dev/null +++ b/vasl_templates/webapp/data/default-templates/victory_conditions.j2 @@ -0,0 +1 @@ +VC: {{VICTORY_CONDITIONS}} diff --git a/vasl_templates/webapp/generate.py b/vasl_templates/webapp/generate.py index be54ac1..6d9651c 100644 --- a/vasl_templates/webapp/generate.py +++ b/vasl_templates/webapp/generate.py @@ -1,3 +1,26 @@ """ Webapp handlers. """ +import os + +from flask import jsonify + +from vasl_templates.webapp import app +from vasl_templates.webapp.config.constants import DATA_DIR + # --------------------------------------------------------------------- + +@app.route( "/templates" ) +def get_templates(): + """Get the specified templates.""" + + # load the default templates + templates = {} + dname = os.path.join( DATA_DIR, "default-templates" ) + for fname in os.listdir(dname): + if os.path.splitext(fname)[1] != ".j2": + continue + fname2 = os.path.join( dname, fname ) + with open(fname2,"r") as fp: + templates[os.path.splitext(fname)[0]] = fp.read() + + return jsonify( templates ) diff --git a/vasl_templates/webapp/static/css/main.css b/vasl_templates/webapp/static/css/main.css index f577ce3..6014de6 100644 --- a/vasl_templates/webapp/static/css/main.css +++ b/vasl_templates/webapp/static/css/main.css @@ -4,7 +4,12 @@ body { height: 100% ; } /* -------------------------------------------------------------------- */ -#tabs { position: absolute ; top: 5px ; bottom: 5px ; left: 5px ; right: 5px ; } +#tabs { + display: none ; + position: absolute ; top: 5px ; bottom: 5px ; left: 5px ; right: 5px ; +} + +/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ #tabs-scenario { display: grid ; display: -ms-grid ; @@ -53,6 +58,32 @@ body { height: 100% ; } height: 100% ; } -fieldset { height: calc(100% - 10px) ; margin: 0 5px 5px 5px ; } +fieldset { height: calc(100% - 30px) ; margin: 0 5px 5px 5px ; padding: 10px ; } #tabs-other fieldset { border: none ; } -fieldset legend { padding: 0 0.2em 0 0.2em ; } +fieldset legend { padding: 0 0.2em 0 0.2em ; font-style: italic ; font-weight: bold ; } + +/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ + +.label { font-weight: bold ; } +input[type="text"] { margin-bottom: 0.25em ; } + +#panel-scenario .form-grid { + display: grid ; display: -ms-grid ; + grid-template-columns: 5em 1fr ; -ms-grid-columns: 5em 1fr ; +} +#panel-scenario input[type="button"] { float: right ; } +/* FUDGE! IE hackamathon follows (nb: