From 94e9c08422277eed4b027010a88de8e9912fe606 Mon Sep 17 00:00:00 2001 From: Peter Pfeufer Date: Thu, 8 Aug 2024 10:14:31 +0200 Subject: [PATCH] [ADD] Theme html tags --- allianceauth/theme/bootstrap/auth_hooks.py | 3 ++- allianceauth/theme/darkly/auth_hooks.py | 1 + allianceauth/theme/flatly/auth_hooks.py | 1 + allianceauth/theme/hooks.py | 18 +++++++++++++----- allianceauth/theme/materia/auth_hooks.py | 1 + 5 files changed, 18 insertions(+), 6 deletions(-) diff --git a/allianceauth/theme/bootstrap/auth_hooks.py b/allianceauth/theme/bootstrap/auth_hooks.py index b888f5df..72fe265a 100644 --- a/allianceauth/theme/bootstrap/auth_hooks.py +++ b/allianceauth/theme/bootstrap/auth_hooks.py @@ -27,6 +27,7 @@ class BootstrapThemeHook(ThemeHook): self, "Bootstrap", "Powerful, extensible, and feature-packed frontend toolkit.", + html_tags={"data-theme": "bootstrap"}, css=CSS_STATICS, js=JS_STATICS, header_padding="3.5em" @@ -44,9 +45,9 @@ class BootstrapDarkThemeHook(ThemeHook): self, "Bootstrap Dark", "Powerful, extensible, and feature-packed frontend toolkit.", + html_tags={"data-theme": "bootstrap-dark"}, css=CSS_STATICS, js=JS_STATICS, - html_tags="data-bs-theme=dark", header_padding="3.5em" ) diff --git a/allianceauth/theme/darkly/auth_hooks.py b/allianceauth/theme/darkly/auth_hooks.py index a569e547..0affe359 100644 --- a/allianceauth/theme/darkly/auth_hooks.py +++ b/allianceauth/theme/darkly/auth_hooks.py @@ -13,6 +13,7 @@ class DarklyThemeHook(ThemeHook): self, "Darkly", "Flatly in night mode!", + html_tags={"data-theme": "darkly"}, css=[{ "url": "https://cdnjs.cloudflare.com/ajax/libs/bootswatch/5.3.3/darkly/bootstrap.min.css", "integrity": "sha512-HDszXqSUU0om4Yj5dZOUNmtwXGWDa5ppESlX98yzbBS+z+3HQ8a/7kcdI1dv+jKq+1V5b01eYurE7+yFjw6Rdg==" diff --git a/allianceauth/theme/flatly/auth_hooks.py b/allianceauth/theme/flatly/auth_hooks.py index b7dda2b3..cab72dc1 100644 --- a/allianceauth/theme/flatly/auth_hooks.py +++ b/allianceauth/theme/flatly/auth_hooks.py @@ -13,6 +13,7 @@ class FlatlyThemeHook(ThemeHook): self, "Flatly", "Flat and modern!", + html_tags={"data-theme": "flatly"}, css=[{ "url": "https://cdnjs.cloudflare.com/ajax/libs/bootswatch/5.3.3/flatly/bootstrap.min.css", "integrity": "sha512-qoT4KwnRpAQ9uczPsw7GunsNmhRnYwSlE2KRCUPRQHSkDuLulCtDXuC2P/P6oqr3M5hoGagUG9pgHDPkD2zCDA==" diff --git a/allianceauth/theme/hooks.py b/allianceauth/theme/hooks.py index 7a618676..dde11493 100644 --- a/allianceauth/theme/hooks.py +++ b/allianceauth/theme/hooks.py @@ -1,10 +1,10 @@ -from typing import List, Optional +from typing import List, Optional, Union class ThemeHook: """ - Theme hook for injecting a Bootstrap 5 Theme and associated JS into alliance auth. - these can be local or CDN delivered + Theme hook for injecting a Bootstrap 5 Theme and associated JS into alliance auth. + These can be local or CDN delivered. """ def __init__(self, @@ -14,7 +14,7 @@ class ThemeHook: js: List[dict], css_template: Optional[str] = None, js_template: Optional[str] = None, - html_tags: Optional[str] = "", + html_tags: Optional[Union[dict, str]] = None, header_padding: Optional[str] = "4em"): """ :param name: Theme python name @@ -29,6 +29,10 @@ class ThemeHook: :type css_template: Optional[str], optional :param js_template: _description_, defaults to None :type js_template: Optional[str], optional + :param html_tags: Attributes added to the `` tag, defaults to None + :type html_tags: Optional[dict|str], optional + :param header_padding: Top padding, defaults to "4em" + :type header_padding: Optional[str], optional """ self.name = name self.description = description @@ -41,7 +45,11 @@ class ThemeHook: self.css_template = css_template self.js_template = js_template - self.html_tags = html_tags + self.html_tags = ( + " ".join([f"{key}={value}" for key, value in html_tags.items()]) + if isinstance(html_tags, dict) + else html_tags + ) self.header_padding = header_padding def get_name(self): return f"{self.__class__.__module__}.{self.__class__.__name__}" diff --git a/allianceauth/theme/materia/auth_hooks.py b/allianceauth/theme/materia/auth_hooks.py index 8a0f5cfe..32d31916 100644 --- a/allianceauth/theme/materia/auth_hooks.py +++ b/allianceauth/theme/materia/auth_hooks.py @@ -13,6 +13,7 @@ class MateriaThemeHook(ThemeHook): self, "Materia", "Material is the metaphor", + html_tags={"data-theme": "materia"}, css=[{ "url": "https://cdnjs.cloudflare.com/ajax/libs/bootswatch/5.3.3/materia/bootstrap.min.css", "integrity": "sha512-2S9Do+uTmZmmJpdmAcOKdUrK/YslcvAuRfIF2ws8+BW9AvZXMRZM+o8Wq+PZrfISD6ZlIaeCWWZAdeprXIoYuQ=="