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

19 statements  

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

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

2 

3from contextlib import suppress 

4from typing import Any, Protocol 

5from uuid import UUID 

6 

7from acb.config import AdapterBase, Settings 

8from acb.depends import depends 

9 

10 

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

12 """Base settings for icon adapters.""" 

13 

14 cdn_url: str | None = None 

15 version: str = "latest" 

16 default_prefix: str = "" 

17 icon_mapping: dict[str, str] = {} 

18 

19 

20class IconsProtocol(Protocol): 

21 """Protocol for icon adapter implementations.""" 

22 

23 def get_icon_class(self, icon_name: str) -> str: ... 

24 def get_icon_tag(self, icon_name: str, **attributes: Any) -> str: ... 

25 

26 

27class IconsBase(AdapterBase): # type: ignore[misc] 

28 """Base class for icon adapters.""" 

29 

30 # Required ACB 0.19.0+ metadata 

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

32 MODULE_STATUS = "stable" 

33 

34 def __init__(self) -> None: 

35 """Initialize icon adapter.""" 

36 # Register with ACB dependency system 

37 with suppress(Exception): 

38 depends.set(self) 

39 

40 def get_icon_class(self, icon_name: str) -> str: 

41 """Get icon-specific class names.""" 

42 raise NotImplementedError() 

43 

44 def get_icon_tag(self, icon_name: str, **attributes: Any) -> str: 

45 """Generate complete icon tags with attributes.""" 

46 raise NotImplementedError()