aboutsummaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
Diffstat (limited to 'app')
-rwxr-xr-xapp/__init__.py51
-rw-r--r--app/_main.py38
-rw-r--r--app/static/css/elements.scss (renamed from app/static/elements.css)0
-rw-r--r--app/static/css/page.scss88
-rw-r--r--app/static/js/elements.js (renamed from app/static/elements.js)0
-rw-r--r--app/static/page.css85
-rw-r--r--app/templates/default.html10
7 files changed, 155 insertions, 117 deletions
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>