Coverage for src/lexigram/admin/theme/service.py: 100%

13 statements  

« prev     ^ index     » next       coverage.py v7.15.4, created at 2026-08-21 14:56 +0800

1from __future__ import annotations 

2 

3from lexigram.ui import shadcn_css 

4 

5 

6class AdminThemeService: 

7 """Generates and caches theme CSS from a configurable primary color. 

8 

9 Args: 

10 primary_color: Hex color string. 

11 """ 

12 

13 def __init__(self, primary_color: str = "#6b7280") -> None: 

14 self._primary_color = primary_color 

15 self._cached_css: str | None = None 

16 

17 def generate_theme_css(self) -> str: 

18 """Return the full theme CSS, cached until the color changes.""" 

19 if self._cached_css is None: 

20 self._cached_css = shadcn_css(primary=self._primary_color) 

21 return self._cached_css 

22 

23 def update_primary_color(self, color: str) -> None: 

24 """Update the primary color and invalidate the CSS cache.""" 

25 self._primary_color = color 

26 self._cached_css = None