diff options
-rw-r--r-- | .gitignore | 3 | ||||
-rw-r--r-- | Pipfile | 4 | ||||
-rw-r--r-- | Pipfile.lock | 29 | ||||
-rwxr-xr-x | app/__init__.py | 51 | ||||
-rw-r--r-- | app/_main.py | 38 | ||||
-rw-r--r-- | app/static/css/elements.scss (renamed from app/static/elements.css) | 0 | ||||
-rw-r--r-- | app/static/css/page.scss | 88 | ||||
-rw-r--r-- | app/static/js/elements.js (renamed from app/static/elements.js) | 0 | ||||
-rw-r--r-- | app/static/page.css | 85 | ||||
-rw-r--r-- | app/templates/default.html | 10 |
10 files changed, 190 insertions, 118 deletions
diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..c2a99e4 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +app/static/index.js +app/static/index.css +app/static/.webassets* @@ -8,7 +8,11 @@ python_version = '3.7' [packages] flask = '*' +flask-assets = '*' +jsmin = '*' +cssmin = '*' gunicorn = '*' + regex = '*' #textout = { git = 'https://forge.touhey.fr/pc/textout.git' } diff --git a/Pipfile.lock b/Pipfile.lock index 91ae2d6..2738935 100644 --- a/Pipfile.lock +++ b/Pipfile.lock @@ -1,7 +1,7 @@ { "_meta": { "hash": { - "sha256": "7b11e765f2360742f6308ad957f91dd540eb13dc41b448d8fa3a12abd4532dbd" + "sha256": "99fc91cd977949dcbe35158661109050c1338ddfb8a9b725861c40942e40b783" }, "pipfile-spec": 6, "requires": { @@ -23,6 +23,13 @@ ], "version": "==7.0" }, + "cssmin": { + "hashes": [ + "sha256:e012f0cc8401efcf2620332339011564738ae32be8c84b2e43ce8beaec1067b6" + ], + "index": "pypi", + "version": "==0.2.0" + }, "flask": { "hashes": [ "sha256:2271c0070dbcb5275fad4a82e29f23ab92682dc45f9dfbc22c02ba9b9322ce48", @@ -31,6 +38,13 @@ "index": "pypi", "version": "==1.0.2" }, + "flask-assets": { + "hashes": [ + "sha256:6031527b89fb3509d1581d932affa5a79dd348cfffb58d0aef99a43461d47847" + ], + "index": "pypi", + "version": "==0.12" + }, "gunicorn": { "hashes": [ "sha256:aa8e0b40b4157b36a5df5e599f45c9c76d6af43845ba3b3b0efe2c70473c2471", @@ -53,6 +67,13 @@ ], "version": "==2.10" }, + "jsmin": { + "hashes": [ + "sha256:b6df99b2cd1c75d9d342e4335b535789b8da9107ec748212706ef7bbe5c2553b" + ], + "index": "pypi", + "version": "==2.2.2" + }, "markupsafe": { "hashes": [ "sha256:a6be69091dac236ea9c6bc7d012beab42010fa914c459791d627dad4910eb665" @@ -78,6 +99,12 @@ "git": "https://gitea.planet-casio.com/cake/textout.git", "ref": "774d427fdaa566bee7896607c5bdc3744fab9ccd" }, + "webassets": { + "hashes": [ + "sha256:e7d9c8887343123fd5b32309b33167428cb1318cdda97ece12d0907fd69d38db" + ], + "version": "==0.12.1" + }, "werkzeug": { "hashes": [ "sha256:c3fd7a7d41976d9f44db327260e263132466836cef6f91512889ed60ad26557c", diff --git a/app/__init__.py b/app/__init__.py index 76815f5..be89656 100755 --- a/app/__init__.py +++ b/app/__init__.py @@ -1,42 +1,35 @@ #!/usr/bin/env python3 +#****************************************************************************** +# Copyright (C) 2018 Thomas "Cakeisalie5" Touhey <thomas@touhey.fr> +# This file is part of the textoutpc project, which is MIT-licensed. +#****************************************************************************** +""" textoutpc demonstration application definition. """ import os.path as _path -from flask import Flask as _Flask, render_template as _template, \ - request as _r -from textoutpc import tohtml as _translate +from flask import Flask as _Flask +from flask_assets import (Environment as _AssetsEnvironment, + Bundle as _AssetsBundle) -__all__ = ["app"] - -_gd = lambda x: _path.relpath(_path.join(_path.dirname(__file__), x)) -app = _Flask('textout', root_path = _path.curdir, - template_folder = _gd('templates'), static_folder = _gd('static'), - static_url_path = '/static') - -@app.route('/', methods = ['GET']) -@app.route('/index.html', methods = ['GET']) -def _empty_page(): - """ Page sans entrée. """ +from ._main import main as _main - return _template('page.html', result = None, text = '') - -@app.route('/index.html', methods = ['POST']) -def _process_page(): - """ Page avec entrée. """ +__all__ = ["app"] - result = None - text = '' +# Make the app and register blueprints. - if 'text' in _r.form: - text = _r.form['text'] - result = _translate(text) +_gd = lambda x: _path.relpath(_path.join(_path.dirname(__file__), x)) +app = _Flask('textout', + template_folder = _gd('templates'), + static_folder = _gd('static'), static_url_path = '/static') +app.register_blueprint(_main) - return _template('page.html', result = result, text = text) +# Add the assets. -@app.route('/guide.html', methods = ['GET']) -def _guide_page(): - """ Page de guide. """ +_assets = _AssetsEnvironment(app) - return _template('guide.html') +_assets.register('js', _AssetsBundle('js/elements.js', + filters = 'jsmin', output = 'index.js')) +_assets.register('css', _AssetsBundle('css/elements.scss', 'css/page.scss', + filters = ('scss', 'cssmin'), output = 'index.css')) # End of file. diff --git a/app/_main.py b/app/_main.py new file mode 100644 index 0000000..3f93804 --- /dev/null +++ b/app/_main.py @@ -0,0 +1,38 @@ +#!/usr/bin/env python3 + +from flask import (Blueprint as _Blueprint, render_template as _template, + request as _r) +from textoutpc import tohtml as _translate + +__all__ = ["main"] + +main = _Blueprint('main', __name__) + +@main.route('/', methods = ['GET']) +@main.route('/index.html', methods = ['GET']) +def _empty_page(): + """ Page sans entrée. """ + + return _template('page.html', result = None, text = '') + +@main.route('/index.html', methods = ['POST']) +def _process_page(): + """ Page avec entrée. """ + + result = None + text = '' + + if 'text' in _r.form: + text = _r.form['text'].strip() + if text: + result = _translate(text) + + return _template('page.html', result = result, text = text) + +@main.route('/guide.html', methods = ['GET']) +def _guide_page(): + """ Page de guide. """ + + return _template('guide.html') + +# End of file. diff --git a/app/static/elements.css b/app/static/css/elements.scss index e69de29..e69de29 100644 --- a/app/static/elements.css +++ b/app/static/css/elements.scss diff --git a/app/static/css/page.scss b/app/static/css/page.scss new file mode 100644 index 0000000..dc25df3 --- /dev/null +++ b/app/static/css/page.scss @@ -0,0 +1,88 @@ +* { + box-sizing: border-box; + font-family: Georgia; +} + +html, body { + margin: 0; + padding: 0; +} + +body { + margin-top: 50px; + overflow-y: scroll; +} + +.container { + width: 100%; + max-width: 600px; + margin: 0 auto; +} + +.header h1, .header p { + display: inline; +} + +.nav { + list-style-type: none; + padding: 0; + + li { + display: inline; + padding: 5px 10px; + } +} + +.demo { + background-color: #CCC; + padding: 2px 10px; + margin-top: 10px; + margin-bottom: 10px; +} + +.inp { + margin-top: 10px; + + textarea, .inp input[type="submit"] { + width: 100%; + border-radius: 4px; + } + + textarea { + border: 3px solid #CCC; + border-radius: 4px; + min-height: 150px; + padding: 5px 7px; + box-sizing: border-box; + background-color: #f8f8f8; + resize: vertical; + + transition: border 0.2s ease-in-out; + } + textarea:focus { + border: 3px solid #555; + } + + input[type="submit"] { + width: 100%; + background-color: #777; + border: 2px solid #555; + border-radius: 4px; + color: white; + padding: 4px 4px; + text-decoration: none; + margin-top: 5px; + cursor: pointer; + } +} + +a, a:visited, a:hover, a:active { + color: #707070; + text-decoration: none; +} +a:hover { + color: #505050; +} +a:active { + color: #202020; +} diff --git a/app/static/elements.js b/app/static/js/elements.js index e69de29..e69de29 100644 --- a/app/static/elements.js +++ b/app/static/js/elements.js diff --git a/app/static/page.css b/app/static/page.css deleted file mode 100644 index 385ebf0..0000000 --- a/app/static/page.css +++ /dev/null @@ -1,85 +0,0 @@ -* { - box-sizing: border-box; - font-family: Georgia; -} - -html, body { - margin: 0; - padding: 0; -} - -body { - margin-top: 50px; - overflow-y: scroll; -} - -.container { - width: 100%; - max-width: 600px; - margin: 0 auto; -} - -.header h1, .header p { - display: inline; -} - -.nav { - list-style-type: none; - padding: 0; -} -.nav li { - display: inline; - padding: 5px 10px; -} - -.demo { - background-color: #CCC; - padding: 2px 10px; - margin-top: 10px; - margin-bottom: 10px; -} - -.inp { - margin-top: 10px; -} - -.inp textarea, .inp input[type="submit"] { - width: 100%; - border-radius: 4px; -} - -.inp textarea { - border: 3px solid #CCC; - height: auto; - min-height: 150px; - padding: 5px 7px; - box-sizing: border-box; - background-color: #f8f8f8; - resize: vertical; - - transition: border 0.2s ease-in-out; -} -.inp textarea:focus { - border: 3px solid #555; -} - -.inp input[type="submit"] { - background-color: #777; - border: 2px solid #555; - color: white; - padding: 4px 4px; - text-decoration: none; - margin-top: 5px; - cursor: pointer; -} - -a, a:visited, a:hover, a:active { - color: #707070; - text-decoration: none; -} -a:hover { - color: #505050; -} -a:active { - color: #202020; -} diff --git a/app/templates/default.html b/app/templates/default.html index 3f3b48d..1cd9567 100644 --- a/app/templates/default.html +++ b/app/templates/default.html @@ -11,8 +11,9 @@ <link rel="shortcut icon" type="image/ico" href="{{ url_for('static', filename = 'favicon.ico') }}"> <![endif]--> -<link rel="stylesheet" type="text/css" href="{{ url_for('static', filename = 'page.css') }}"> -<link rel="stylesheet" type="text/css" href="{{ url_for('static', filename = 'elements.css') }}"> +{% assets "css" %} +<link rel="stylesheet" type="text/css" href="{{ ASSET_URL }}"> +{% endassets %} </head><body><div class="container"> <div class="header"> <h1>textoutpc</h1><p> — moteur de traduction BBcode</p> @@ -22,5 +23,8 @@ {% block content %}{% endblock %} </div> -<script src="{{ url_for('static', filename = 'elements.js') }}"></script> + +{% assets "js" %} +<script src="{{ ASSET_URL }}"></script> +{% endassets %} </body></html> |