Coverage for fastblocks/adapters/styles/_base.py: 100%

18 statements  

« prev     ^ index     » next       coverage.py v7.10.7, created at 2025-10-09 00:47 -0700

1"""Base classes and protocols for style adapters.""" 

2 

3from contextlib import suppress 

4from typing import Protocol 

5from uuid import UUID 

6 

7from acb.config import AdapterBase, Settings 

8from acb.depends import depends 

9 

10 

11class StylesBaseSettings(Settings): # type: ignore[misc] 

12 """Base settings for style adapters.""" 

13 

14 cdn_url: str | None = None 

15 version: str = "latest" 

16 additional_stylesheets: list[str] = [] 

17 

18 

19class StylesProtocol(Protocol): 

20 """Protocol for style adapter implementations.""" 

21 

22 def get_stylesheet_links(self) -> list[str]: ... 

23 def get_component_class(self, component: str) -> str: ... 

24 

25 

26class StylesBase(AdapterBase): # type: ignore[misc] 

27 """Base class for style adapters.""" 

28 

29 # Required ACB 0.19.0+ metadata 

30 MODULE_ID: UUID = UUID("01937d86-4f2a-7b3c-8d9e-f3b4d3c2b1a2") # Static UUID7 

31 MODULE_STATUS = "stable" 

32 

33 def __init__(self) -> None: 

34 """Initialize style adapter.""" 

35 # Register with ACB dependency system 

36 with suppress(Exception): 

37 depends.set(self) 

38 

39 def get_stylesheet_links(self) -> list[str]: 

40 """Generate stylesheet link tags.""" 

41 raise NotImplementedError() 

42 

43 def get_component_class(self, component: str) -> str: 

44 """Get style-specific class names for components.""" 

45 raise NotImplementedError()