Coverage for src / local_deep_research / web / utils / theme_helper.py: 100%
21 statements
« prev ^ index » next coverage.py v7.13.4, created at 2026-02-25 01:07 +0000
« prev ^ index » next coverage.py v7.13.4, created at 2026-02-25 01:07 +0000
1"""
2Theme Helper for Flask - Compatibility Layer
4This module provides backward-compatible Flask integration for the theme system.
5It wraps the ThemeRegistry from the themes module.
7Usage:
8 from local_deep_research.web.utils.theme_helper import theme_helper
9 theme_helper.init_app(app)
10"""
12from flask import Flask
13from loguru import logger
15from ..themes import (
16 get_theme_metadata,
17 get_themes,
18 get_themes_json,
19 theme_registry,
20)
23class ThemeHelper:
24 """Flask integration helper for the theme system.
26 This class provides backward-compatible Flask integration,
27 delegating to the ThemeRegistry for actual theme management.
28 """
30 def __init__(self, app: Flask | None = None):
31 """Initialize the theme helper.
33 Args:
34 app: Optional Flask application instance
35 """
36 self.app = app
37 if app:
38 self.init_app(app)
40 def init_app(self, app: Flask) -> None:
41 """Initialize the helper with a Flask application.
43 Registers Jinja2 template globals for theme access:
44 - get_themes(): Returns list of theme IDs
45 - get_themes_json(): Returns JSON array of theme IDs
46 - get_theme_metadata(): Returns JSON object with theme metadata
48 Args:
49 app: Flask application instance
50 """
51 self.app = app
53 # Register template functions
54 app.jinja_env.globals["get_themes"] = get_themes
55 app.jinja_env.globals["get_themes_json"] = get_themes_json
56 app.jinja_env.globals["get_theme_metadata"] = get_theme_metadata
58 theme_count = len(theme_registry.themes)
59 logger.info(f"Theme system initialized with {theme_count} themes")
61 def get_themes(self) -> list[str]:
62 """Get list of available theme names.
64 Returns:
65 Sorted list of theme ID strings
66 """
67 return theme_registry.get_theme_ids()
69 def clear_cache(self) -> None:
70 """Clear the theme cache.
72 Useful for development or when theme files are modified.
73 """
74 theme_registry.clear_cache()
75 logger.debug("Theme cache cleared")
78# Singleton instance for backward compatibility
79theme_helper = ThemeHelper()