From c2de89201f0ae310f624df25f2bab9997f490163 Mon Sep 17 00:00:00 2001 From: s3lph <1375407-s3lph@users.noreply.gitlab.com> Date: Mon, 20 Feb 2023 10:02:12 +0100 Subject: [PATCH] Add theme support --- .gitlab-ci.yml | 2 + CHANGELOG.md | 14 +++++++ README.md | 1 + doc | 2 +- matemat.docker.conf | 2 + matemat/__init__.py | 2 +- matemat/__main__.py | 7 +++- matemat/webserver/config.py | 6 +++ matemat/webserver/template/template.py | 3 +- package/debian/matemat/etc/matemat.conf | 3 ++ .../matemat/usr/lib/matemat/matemat.conf | 1 + static/css/matemat.css | 4 ++ templates/base.html | 9 +++-- themes/base/static/css/theme.css | 0 themes/base/templates/.gitkeep | 0 themes/pride/static/css/theme.css | 37 +++++++++++++++++++ themes/pride/templates/.gitkeep | 0 17 files changed, 86 insertions(+), 7 deletions(-) create mode 100644 themes/base/static/css/theme.css create mode 100644 themes/base/templates/.gitkeep create mode 100644 themes/pride/static/css/theme.css create mode 100644 themes/pride/templates/.gitkeep diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index adfd23b..2d7165e 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -93,6 +93,8 @@ build_debian: - gzip -9n package/debian/matemat/usr/share/doc/matemat/changelog - cp -r static/ package/debian/matemat/usr/lib/matemat/static/ - cp -r templates/ package/debian/matemat/usr/lib/matemat/templates/ + - mkdir -p package/debian/matemat/var/lib/matemat/ + - cp -r themes/ package/debian/matemat/usr/lib/matemat/themes/ - python3.7 setup.py egg_info install --root=package/debian/matemat/ --prefix=/usr --optimize=1 - cd package/debian - mkdir -p matemat/usr/lib/python3/dist-packages/ diff --git a/CHANGELOG.md b/CHANGELOG.md index 0d1a580..2168875 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,19 @@ # Matemat Changelog + +## Version 0.3.0 + +THEMES! + +### Changes + + +- Add support for theming +- Themes can override both templates and static files + + + + ## Version 0.2.14 diff --git a/README.md b/README.md index 3e48955..ebf7d20 100644 --- a/README.md +++ b/README.md @@ -33,6 +33,7 @@ python -m matemat - s3lph - SPiNNiX +- jonny ## License diff --git a/doc b/doc index b49477b..832ba0b 160000 --- a/doc +++ b/doc @@ -1 +1 @@ -Subproject commit b49477b0c0f518ac6f3c1cfdc7c46c040a247366 +Subproject commit 832ba0b4f363578653e6c2a04afedc65d90d979a diff --git a/matemat.docker.conf b/matemat.docker.conf index ccb8451..b55bef8 100644 --- a/matemat.docker.conf +++ b/matemat.docker.conf @@ -5,6 +5,8 @@ Port=80 StaticPath=/static TemplatePath=/templates +ThemePath=/themes +Theme=base LogTarget=stdout diff --git a/matemat/__init__.py b/matemat/__init__.py index 215eb4c..aed0de4 100644 --- a/matemat/__init__.py +++ b/matemat/__init__.py @@ -1,2 +1,2 @@ -__version__ = '0.2.14' +__version__ = '0.3.0' diff --git a/matemat/__main__.py b/matemat/__main__.py index a5cbe0b..48fda2a 100644 --- a/matemat/__main__.py +++ b/matemat/__main__.py @@ -1,3 +1,4 @@ +import logging from typing import Any, Dict, Iterable, Union import sys @@ -62,8 +63,12 @@ def _init(config: Dict[str, Any]): @bottle.route('/static/') def serve_static_files(filename: str): config = get_config() + themeroot = os.path.abspath(os.path.join(config['themeroot'], config['theme'], 'static')) staticroot = os.path.abspath(config['staticroot']) - return bottle.static_file(filename, root=staticroot) + resp = bottle.static_file(filename, root=themeroot) + if resp.status_code == 404: + resp = bottle.static_file(filename, root=staticroot) + return resp def main(): diff --git a/matemat/webserver/config.py b/matemat/webserver/config.py index d42cf8a..9a4373f 100644 --- a/matemat/webserver/config.py +++ b/matemat/webserver/config.py @@ -68,6 +68,10 @@ def parse_config_file(paths: Union[str, Iterable[str]]) -> None: config['staticroot'] = '/var/matemat/static' # Root directory of Jinja2 templates config['templateroot'] = '/var/matemat/templates' + # Root directory of themes + config['themeroot'] = '/var/matemat/themes' + # Active theme - "base" is the default theme that does not override anything + config['theme'] = 'base' # Log level config['log_level'] = logging.INFO # Log target: An IO stream (stderr, stdout, ...) or a filename @@ -104,6 +108,8 @@ def parse_config_file(paths: Union[str, Iterable[str]]) -> None: parse_logging(parser['Matemat'].get('LogLevel', config['log_level']), parser['Matemat'].get('LogTarget', 'stderr')) config['templateroot'] = parser['Matemat'].get('TemplatePath', os.path.expanduser(config['templateroot'])) + config['themeroot'] = parser['Matemat'].get('ThemePath', os.path.expanduser(config['themeroot'])) + config['theme'] = parser['Matemat'].get('Theme', config['theme']) # Read all values from the [Pagelets] section, if present. These values are passed to pagelet functions if 'Pagelets' in parser.sections(): diff --git a/matemat/webserver/template/template.py b/matemat/webserver/template/template.py index 94e6250..0238776 100644 --- a/matemat/webserver/template/template.py +++ b/matemat/webserver/template/template.py @@ -11,8 +11,9 @@ __jinja_env: jinja2.Environment = None def init(config: Dict[str, Any]) -> None: global __jinja_env + themepath = os.path.abspath(os.path.join(config['themeroot'], config['theme'], 'templates')) __jinja_env = jinja2.Environment( - loader=jinja2.FileSystemLoader(os.path.abspath(config['templateroot'])), + loader=jinja2.FileSystemLoader([themepath, os.path.abspath(config['templateroot'])]), autoescape=jinja2.select_autoescape(default=True), ) __jinja_env.filters['chf'] = format_chf diff --git a/package/debian/matemat/etc/matemat.conf b/package/debian/matemat/etc/matemat.conf index f76f673..c28fcd1 100644 --- a/package/debian/matemat/etc/matemat.conf +++ b/package/debian/matemat/etc/matemat.conf @@ -5,6 +5,9 @@ Address=:: # The TCP port to listen on Port=80 +# The theme to apply +#Theme=base + # The log level, one of NONE, DEBUG, INFO, WARNING, ERROR, CRITICAL LogLevel=DEBUG diff --git a/package/debian/matemat/usr/lib/matemat/matemat.conf b/package/debian/matemat/usr/lib/matemat/matemat.conf index 364af72..876c9cc 100644 --- a/package/debian/matemat/usr/lib/matemat/matemat.conf +++ b/package/debian/matemat/usr/lib/matemat/matemat.conf @@ -2,6 +2,7 @@ StaticPath=/usr/lib/matemat/static TemplatePath=/usr/lib/matemat/templates +ThemePath=/var/lib/matemat/themes LogTarget=stdout diff --git a/static/css/matemat.css b/static/css/matemat.css index 0cbfc0f..e36f817 100644 --- a/static/css/matemat.css +++ b/static/css/matemat.css @@ -7,6 +7,10 @@ user-select: none; } +nav div { + display: inline-block; +} + .thumblist-item { display: inline-block; margin: 5px; diff --git a/templates/base.html b/templates/base.html index f39da0f..063d3ad 100644 --- a/templates/base.html +++ b/templates/base.html @@ -1,11 +1,12 @@ - - + + {% block head %} {# Show the setup name, as set in the config file, as tab title. Don't escape HTML entities. #} {{ setupname|safe }} + {% endblock %} @@ -15,7 +16,8 @@ {% block header %} {# Always show a link to the home page, either a list of users or of products. #} - Home + {% endblock %} diff --git a/themes/base/static/css/theme.css b/themes/base/static/css/theme.css new file mode 100644 index 0000000..e69de29 diff --git a/themes/base/templates/.gitkeep b/themes/base/templates/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/themes/pride/static/css/theme.css b/themes/pride/static/css/theme.css new file mode 100644 index 0000000..0200b6c --- /dev/null +++ b/themes/pride/static/css/theme.css @@ -0,0 +1,37 @@ + +.thumblist-item:nth-child(6n+1) { background: #E40303; } +.thumblist-item:nth-child(6n+2) { background: #FF8C00; } +.thumblist-item:nth-child(6n+3) { background: #FFED00; } +.thumblist-item:nth-child(6n+4) { background: #008026; } +.thumblist-item:nth-child(6n+5) { background: #24408E; } +.thumblist-item:nth-child(6n+6) { background: #732982; } + +footer li:nth-child(4n+1) { background: #000000; color: white; } +footer li:nth-child(4n+2) { background: #A3A3A3; } +footer li:nth-child(4n+3) { background: #FFFFFF; } +footer li:nth-child(4n+4) { background: #800080; color: white; } + + +.touchkey-svg-node:nth-child(16n+1) { fill: #D52D00; } +.touchkey-svg-node:nth-child(16n+5) { fill: #EF7627; } +.touchkey-svg-node:nth-child(16n+9) { fill: #FF9A56; } +.touchkey-svg-node:nth-child(16n+13) { fill: #FFFFFF; } +.touchkey-svg-node:nth-child(16n+14) { fill: #D162A4; } +.touchkey-svg-node:nth-child(16n+15) { fill: #B55690; } +.touchkey-svg-node:nth-child(16n+16) { fill: #A30262; } + +.touchkey-svg-node:nth-child(16n+2) { fill: #5BCEFA; } +.touchkey-svg-node:nth-child(16n+6) { fill: #F5A9B8; } +.touchkey-svg-node:nth-child(16n+10) { fill: #FFFFFF; } +.touchkey-svg-node:nth-child(16n+11) { fill: #F5A9B8; } +.touchkey-svg-node:nth-child(16n+12) { fill: #5BCEFA; } + +.touchkey-svg-node:nth-child(16n+3) { fill: #D60270; } +.touchkey-svg-node:nth-child(16n+7) { fill: #9B4F96; } +.touchkey-svg-node:nth-child(16n+8) { fill: #0038A8; } + +.osk-kbd-row:nth-child(5n+1) .osk-button { background: #FFFFFF; } +.osk-kbd-row:nth-child(5n+2) .osk-button { background: #FFAFC8; } +.osk-kbd-row:nth-child(5n+3) .osk-button { background: #74D7EE; } +.osk-kbd-row:nth-child(5n+4) .osk-button { background: #613915; fill: white; } +.osk-kbd-row:nth-child(5n+5) .osk-button { background: #000000; fill: white; } \ No newline at end of file diff --git a/themes/pride/templates/.gitkeep b/themes/pride/templates/.gitkeep new file mode 100644 index 0000000..e69de29