From b995948ffb54efa0a5f889977ab57c7259aa1a9f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sondre=20Gr=C3=B8n=C3=A5s?= <44143748+sondregronas@users.noreply.github.com> Date: Tue, 20 Aug 2024 15:57:51 +0200 Subject: [PATCH] Add prettier & ruff formatting, delete requirements.txt --- .gitignore | 5 + Dockerfile | 2 +- README.md | 4 + package.json | 20 +++ piggy/__init__.py | 12 +- piggy/app.py | 71 ++++---- piggy/caching.py | 67 ++++---- piggy/piggybank.py | 52 +++--- piggy/static/css/styles.css | 154 +++++++++--------- piggy/static/css/tailwind.input.css | 2 +- .../assignments/0-assignments_root.html | 59 ++++--- piggy/templates/assignments/1-year_level.html | 57 ++++--- piggy/templates/assignments/2-class_name.html | 57 ++++--- piggy/templates/assignments/3-subject.html | 35 ++-- piggy/templates/assignments/4-topic.html | 44 ++--- piggy/templates/assignments/5-assignment.html | 54 +++--- piggy/templates/example.html | 34 ++-- piggy/templates/index.html | 16 +- piggy/templates/layout.html | 52 +++--- pyproject.toml | 78 +++++++++ requirements.txt | 2 - run.py | 22 +-- 22 files changed, 527 insertions(+), 372 deletions(-) create mode 100644 package.json create mode 100644 pyproject.toml delete mode 100644 requirements.txt diff --git a/.gitignore b/.gitignore index 1cfb12b..70924e6 100644 --- a/.gitignore +++ b/.gitignore @@ -4,6 +4,7 @@ *.DS_Store .DS_Store? .cache +*.egg-info tailwind.css @@ -12,3 +13,7 @@ turtleconvert/ .idea/ venv/ __pycache__/ + + +node_modules/ +package-lock.json \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index 357968d..5560fb7 100644 --- a/Dockerfile +++ b/Dockerfile @@ -14,7 +14,7 @@ WORKDIR /app COPY requirements.txt /app -RUN pip install -U pip && pip install setuptools wheel && pip install -q -r requirements.txt +RUN pip install -U pip && pip install . RUN pip install gunicorn diff --git a/README.md b/README.md index e6d545a..d832fe2 100644 --- a/README.md +++ b/README.md @@ -2,4 +2,8 @@ [![GitHub Pages](https://badgen.net/badge/visit/github%20pages/?icon=chrome)](https://piggy.iktim.no) +Install `pip install .` + +Install dev `pip install .[dev]` + `npm install` + 🚧 Construction in progress. 🚧 \ No newline at end of file diff --git a/package.json b/package.json new file mode 100644 index 0000000..26b62b0 --- /dev/null +++ b/package.json @@ -0,0 +1,20 @@ +{ + "devDependencies": { + "prettier": "^3.3.3", + "prettier-plugin-jinja-template": "^1.4.1", + "tailwindcss": "^3.4.10" + }, + "prettier": { + "plugins": [ + "prettier-plugin-jinja-template" + ], + "overrides": [ + { + "files": "*.html", + "options": { + "parser": "jinja-template" + } + } + ] + } +} diff --git a/piggy/__init__.py b/piggy/__init__.py index 566f1ae..775e8fc 100644 --- a/piggy/__init__.py +++ b/piggy/__init__.py @@ -2,16 +2,16 @@ from piggy.piggybank import generate_piggymap -PIGGYBANK_FOLDER = Path('piggybank') +PIGGYBANK_FOLDER = Path("piggybank") PIGGYMAP = generate_piggymap(PIGGYBANK_FOLDER) SUPPORTED_LANGUAGES = { - '': {'name': 'Norsk'}, # Default language - 'eng': {'name': 'English'}, - 'ukr': {'name': 'Українська'}, + "": {"name": "Norsk"}, # Default language + "eng": {"name": "English"}, + "ukr": {"name": "Українська"}, } # A prefix for the assignment URLs, to avoid conflicts with other routes -ASSIGNMENT_ROUTE = 'main' +ASSIGNMENT_ROUTE = "main" # Media is on a different prefix to not compete with the assignment routes -MEDIA_ROUTE = 'img' +MEDIA_ROUTE = "img" diff --git a/piggy/app.py b/piggy/app.py index 972f3a3..20e43d3 100644 --- a/piggy/app.py +++ b/piggy/app.py @@ -16,83 +16,82 @@ def create_app(): - app = Flask(__name__, static_folder='static') + app = Flask(__name__, static_folder="static") - assignment_routes = Blueprint(ASSIGNMENT_ROUTE, __name__, url_prefix=f'/{ASSIGNMENT_ROUTE}') - media_routes = Blueprint(MEDIA_ROUTE, __name__, url_prefix=f'/{MEDIA_ROUTE}') + assignment_routes = Blueprint(ASSIGNMENT_ROUTE, __name__, url_prefix=f"/{ASSIGNMENT_ROUTE}") + media_routes = Blueprint(MEDIA_ROUTE, __name__, url_prefix=f"/{MEDIA_ROUTE}") generate_static_files_wrapper() @app.context_processor def context_processor(): """Context variables for all templates in the app.""" - return {'ASSIGNMENT_URL_PREFIX': ASSIGNMENT_ROUTE, - 'MEDIA_URL_PREFIX': MEDIA_ROUTE, - 'piggymap': PIGGYMAP, - 'img_fmt': 'webp'} - - @app.route('/') + return { + "ASSIGNMENT_URL_PREFIX": ASSIGNMENT_ROUTE, + "MEDIA_URL_PREFIX": MEDIA_ROUTE, + "piggymap": PIGGYMAP, + "img_fmt": "webp", + } + + @app.route("/") @lru_cache_wrapper def index(): - html = '
{{ media_abspath }}/header.png+
{{ meta.description or 'No description provided' }}
-{{ media_abspath }}/header.png-
{{ meta.description or 'No description provided' }}
+{{ media_abspath }}/{{ key }}/media/header.png-
{{ media_abspath }}/{{ item }}/media/header.png- {# Header media for child item #} - -
{{ media_abspath }}/{{ item }}/media/header.png+
Difficulty: {{ '⭐' * content.meta.difficulty }}
- {% endif %} + {% if content.meta.difficulty > 50 %} + Difficulty: UMULIG!!! + {% else %} +Difficulty: {{ '⭐' * content.meta.difficulty }}
+ {% endif %} {% endif %}diff --git a/piggy/templates/example.html b/piggy/templates/example.html index e93a56e..8c02e58 100644 --- a/piggy/templates/example.html +++ b/piggy/templates/example.html @@ -1,20 +1,22 @@ {% for item, data in segment.items() %} - {# Name metadata for child item #} -
+ {# Name metadata for child item #} +
+ {# Header media for child item #} + +
{{ media_abspath }}/{{ item }}/media/header.png
- {# Header media for child item #} - -
{{ media_abspath }}/{{ item }}/media/header.png
+
+ {# Link to item, display name #}
+ View {{ data.meta.name }}
+
-
- {# Link to item, display name #}
- View {{ data.meta.name }}
-
-
-
- {% for meta_key, meta_val in data.meta.items() %}
- {{ meta_key }}: {{ meta_val }}
-
- {% endfor %}
-{% endfor %}
\ No newline at end of file
+
+ {% for meta_key, meta_val in data.meta.items() %}
+ {{ meta_key }}: {{ meta_val }}
+
+ {% endfor %}
+{% endfor %}
diff --git a/piggy/templates/index.html b/piggy/templates/index.html
index 6c84afe..40cf46f 100644
--- a/piggy/templates/index.html
+++ b/piggy/templates/index.html
@@ -1,12 +1,12 @@
-
+
-
- - +
+ +
- -