v0.163.0
 1from __future__ import annotations
 2
 3from typing import Any
 4
 5from jinja2.runtime import Context
 6from plain.assets.finders import _APP_ASSETS_DIR
 7from plain.runtime import settings
 8from plain.templates import register_template_extension
 9from plain.templates.jinja.extensions import InclusionTagExtension
10
11
12@register_template_extension
13class TailwindCSSExtension(InclusionTagExtension):
14    tags = {"tailwind_css"}  # noqa: RUF012 — jinja2 types `tags` as an instance attribute; ClassVar here fails ty's LSP check
15    template_name = "tailwind/css.html"
16
17    def get_context(
18        self, context: Context, *args: Any, **kwargs: Any
19    ) -> dict[str, str]:
20        tailwind_css_path = str(
21            settings.TAILWIND_DIST_PATH.relative_to(_APP_ASSETS_DIR)
22        )
23        return {"tailwind_css_path": tailwind_css_path}