so the site's theme colors/font can no longer be used as a fallback
here (only hardcoded defaults, from MsgBarConfig's own field defaults).
|
# TODO: HtmlInjectorPluginBase gives plugins no access to the engine/db, |
|
# so the site's theme colors/font can no longer be used as a fallback |
|
# here (only hardcoded defaults, from MsgBarConfig's own field defaults). |
"""
class MsgBarPlugin(HtmlInjectorPluginBase):
"""Plugin that displays a customizable message bar at the top of web pages."""
accepted_page_sections: frozenset[PageSection] = frozenset({"body"})
def __init__(self, config: dict[str, Any]) -> None:
"""Validate the configuration and precompute the message bar HTML.
Args:
config: Raw configuration dict from the platzky engine.
Raises:
ConfigPluginError: If the configuration is invalid.
"""
super().__init__(config)
try:
msgbar_config = MsgBarConfig.model_validate(config)
except ValidationError as e:
raise ConfigPluginError(f"Invalid configuration: {e}") from e
# TODO: HtmlInjectorPluginBase gives plugins no access to the engine/db,
# so the site's theme colors/font can no longer be used as a fallback
# here (only hardcoded defaults, from MsgBarConfig's own field defaults).
self._bar_html = _build_bar_html(
message=_render_message(msgbar_config.message),
background_color=msgbar_config.get_validated_background_color(),
text_color=msgbar_config.get_validated_text_color(),
font_size=msgbar_config.get_validated_font_size(),
font_family=msgbar_config.get_validated_font_family(),
bar_height=msgbar_config.get_validated_bar_height(),
)
def get_body_html(self) -> str:
"""Return the message bar HTML to inject at the start of the page body."""
return self._bar_html
so the site's theme colors/font can no longer be used as a fallback
here (only hardcoded defaults, from MsgBarConfig's own field defaults).
platzky-msgbar/platzky_msgbar/plugin.py
Lines 168 to 170 in 5341d8f