Skip to content

ElusiveIconsProvider

Base classes

Name Children Inherits
FontProvider
pycons.font_providers.base
Base class for font providers.

⋔ Inheritance diagram

graph TD
  3069315207["providers.ElusiveIconsProvider"]
  2987344157["base.FontProvider"]
  925645236["abc.ABC"]
  2751680898["builtins.object"]
  2987344157 --> 3069315207
  925645236 --> 2987344157
  2751680898 --> 925645236

🛈 DocStrings

Bases: FontProvider

Provider for Elusive Icons.

Source code in src/pycons/font_providers/providers.py
class ElusiveIconsProvider(FontProvider):
    """Provider for Elusive Icons."""

    NAME: ClassVar[str] = "elusive"
    PREFIX: ClassVar[str] = "el"
    DISPLAY_NAME: ClassVar[str] = "Elusive Icons"

    # No need for version URL as we're using a static version
    VERSION_URL = "https://api.github.com/repos/dovy/elusive-icons/tags"
    BASE_URL = "https://raw.githubusercontent.com/dovy/elusive-icons/master"
    CSS_PATTERN = r'\.el-([^:]+):before\s*{\s*content:\s*"\\([^"]+)"\s*;\s*}'

    async def get_latest_version(self) -> str:
        """Get latest version, or use 'master' if API fails."""
        try:
            data = await fetch_url(self.VERSION_URL, use_cache=self.use_cache)
            tags = load_json(data, return_type=list)
            return tags[0]["name"].lstrip("v")
        except Exception:  # noqa: BLE001
            # Fall back to master branch if API fails
            return "master"

    def get_download_urls(self, version: str) -> tuple[str, str]:
        """Get URLs for font file and CSS."""
        return (
            "https://github.com/dovy/elusive-icons/raw/master/fonts/elusiveicons-webfont.ttf",
            f"{self.BASE_URL}/css/elusive-icons.css",
        )

    def process_mapping(self, mapping_data: bytes) -> dict[str, str]:
        """Process Elusive Icons CSS to extract icon names and unicode points."""
        content = mapping_data.decode("utf-8")
        icons = {}

        # Parse CSS looking for patterns like: .el-home:before { content: "\f189"; }
        for line in content.splitlines():
            if ".el-" in line and ":before" in line:
                # Extract icon name
                icon_name = line.split(".el-")[1].split(":before")[0]

                # Look for the content property in the same or next line
                content_search = line
                if "{" in line and "content:" not in line:
                    # Content might be on next line
                    idx = content.find(line) + len(line)
                    next_brace = content.find("}", idx)
                    if next_brace > idx:
                        content_search = content[idx:next_brace]

                # Extract unicode value if available
                if "content:" in content_search:
                    # Format is: content: "\f189";
                    match = re.search(r'content:\s*"\\([^"]+)"', content_search)
                    if match:
                        unicode_value = match.group(1)
                        icons[icon_name] = f"0x{unicode_value.lower()}"

        return icons

get_download_urls

get_download_urls(version: str) -> tuple[str, str]

Get URLs for font file and CSS.

Source code in src/pycons/font_providers/providers.py
def get_download_urls(self, version: str) -> tuple[str, str]:
    """Get URLs for font file and CSS."""
    return (
        "https://github.com/dovy/elusive-icons/raw/master/fonts/elusiveicons-webfont.ttf",
        f"{self.BASE_URL}/css/elusive-icons.css",
    )

get_latest_version async

get_latest_version() -> str

Get latest version, or use 'master' if API fails.

Source code in src/pycons/font_providers/providers.py
async def get_latest_version(self) -> str:
    """Get latest version, or use 'master' if API fails."""
    try:
        data = await fetch_url(self.VERSION_URL, use_cache=self.use_cache)
        tags = load_json(data, return_type=list)
        return tags[0]["name"].lstrip("v")
    except Exception:  # noqa: BLE001
        # Fall back to master branch if API fails
        return "master"

process_mapping

process_mapping(mapping_data: bytes) -> dict[str, str]

Process Elusive Icons CSS to extract icon names and unicode points.

Source code in src/pycons/font_providers/providers.py
def process_mapping(self, mapping_data: bytes) -> dict[str, str]:
    """Process Elusive Icons CSS to extract icon names and unicode points."""
    content = mapping_data.decode("utf-8")
    icons = {}

    # Parse CSS looking for patterns like: .el-home:before { content: "\f189"; }
    for line in content.splitlines():
        if ".el-" in line and ":before" in line:
            # Extract icon name
            icon_name = line.split(".el-")[1].split(":before")[0]

            # Look for the content property in the same or next line
            content_search = line
            if "{" in line and "content:" not in line:
                # Content might be on next line
                idx = content.find(line) + len(line)
                next_brace = content.find("}", idx)
                if next_brace > idx:
                    content_search = content[idx:next_brace]

            # Extract unicode value if available
            if "content:" in content_search:
                # Format is: content: "\f189";
                match = re.search(r'content:\s*"\\([^"]+)"', content_search)
                if match:
                    unicode_value = match.group(1)
                    icons[icon_name] = f"0x{unicode_value.lower()}"

    return icons

:fa-brands-github: Show source on GitHub