Template filters required by chirp-ui components.
These match Chirp's filter API so chirp-ui works with any Chirp version.
Register viaregister_filters() when using Chirp.
Everything not in all is internal and may change without notice.
filters
| Name | Type | Default | Description |
|---|---|---|---|
type
|
|
— | |
qualified_name
|
|
— | |
element_type
|
|
— | |
description
|
|
— | |
source_file
|
|
— | |
line_number
|
|
— | |
is_autodoc
|
|
— | |
autodoc_element
|
|
— | |
_autodoc_template
|
|
— | |
_autodoc_url_path
|
|
— | |
_autodoc_page_type
|
|
— | |
title
|
|
— | |
doc_content_hash
|
|
— |
Symbols on this page
Clear all registered semantic color names for the current context.
Register semantic color names (e.g. Pokémon types) forresolve_color().
RaisesValueErrorimmediately if any color value fails
sanitize_color() validation.
Return the color if it matches a safe CSS color pattern, else None.
Returnwhite or #1a1a1afor readable text on solid css_color.
Supports hex,rgb(), hsl(), and oklch()color formats.
EmitsChirpUIValidationWarningwhen…
Resolve a named color from the registry, then validate as a CSS color string.
Build chirpui BEM class string from block, axes, size, and modifiers.
Example::
class="{{ "btn" | bem(variant="primary", size="lg", modifier="loading") }}" → "chirpui-btn chirpui-btn--primary chirpui-btn--lg chirpui-btn--loading"…Return value if in allowed, else default.
Always emitsChirpUIValidationWarning
on fallback (raisesValueErrorin strict mode).
Semantic alias groups (e.g.error / danger…
Return value if in VARIANT_REGISTRY for block, else default. When strict, log warning.
Return value if in APPEARANCE_REGISTRY for block, else fallback.
Return value if in TONE_REGISTRY for block, else fallback.
Warn when a deprecated parameter is used and return value unchanged.
Used in templates to signal deprecation while preserving backward compat::
{% set _attrs_raw…Map Python types to ChirpUI CSS variant names for description_item.
Returns: "unset" | "bool" | "number" | "path" | "" (plain string).
Return value if in SIZE_REGISTRY for block, else default.
Always emitsChirpUIValidationWarning
on fallback when the block has a registered size list
(raisesValueError…
Resolve icon name to glyph; unknown names pass through.
Always emitsChirpUIValidationWarning
for unrecognized names (raisesValueErrorin strict mode).
Extract error messages for a field from a ValidationError-style dict.
Returns empty list if errors is None, not a dict, or field has no…
Map a status string to a badge variant usingSTATUS_WORDS.
Lookup is case-insensitive. Unrecognized words return default and
emitChirpUIValidationWarning.
Build a dict of hyphenated HTML attributes from keyword arguments.
Converts underscores to hyphens in keys:hx_post becomes hx-post.
Pipe throughhtml_attrsto…
Return value if provided, else fallback with a validation warning.
Use in macros where a hardcoded fallback ID would cause collisions if multiple instances…
Build a template global for route-aware link attrs.
The default no-op version keeps standalone chirp-ui renderable. When
swap_resolveris supplied (for example by Chirp's …
Render HTML attrs from mapping or legacy raw string.
Return the Bengal logical asset path for a Chirp UI provider asset.
reset_colors
function
def reset_colors() -> None
Clear all registered semantic color names for the current context.
No parameters.
register_colors
function
def register_colors(mapping: Mapping[str, str]) -> None
Register semantic color names (e.g. Pokémon types) forresolve_color().
RaisesValueErrorimmediately if any color value fails
sanitize_color() validation.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
mapping
|
Mapping[str, str]
|
— |
sanitize_color
function
def sanitize_color(value: object) -> str | None
Return the color if it matches a safe CSS color pattern, else None.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
value
|
object
|
— |
contrast_text
function
def contrast_text(css_color: str) -> str
Returnwhite or #1a1a1afor readable text on solid css_color.
Supports hex,rgb(), hsl(), and oklch()color formats.
EmitsChirpUIValidationWarningwhen the
color cannot be parsed (falls back towhite).
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
css_color
|
str
|
— |
resolve_color
function
def resolve_color(value: object) -> str | None
Resolve a named color from the registry, then validate as a CSS color string.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
value
|
object
|
— |
bem
function
def bem(block: str, variant: str = '', appearance: str = '', tone: str = '', size: str = '', modifier: str | list[str] = '', cls: str = '') -> str
Build chirpui BEM class string from block, axes, size, and modifiers.
Example::
class="{{ "btn" | bem(variant="primary", size="lg", modifier="loading") }}"
→ "chirpui-btn chirpui-btn--primary chirpui-btn--lg chirpui-btn--loading"
class="{{ "btn" | bem(appearance="outlined", tone="danger") }}"
→ "chirpui-btn chirpui-btn--outlined chirpui-btn--danger"
modifier accepts a single string or a list of strings for additive flags.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
block
|
str
|
— | |
variant
|
str
|
''
|
|
appearance
|
str
|
''
|
|
tone
|
str
|
''
|
|
size
|
str
|
''
|
|
modifier
|
str | list[str]
|
''
|
|
cls
|
str
|
''
|
validate_variant
function
def validate_variant(value: str, allowed: tuple[str, ...], default: str = '') -> str
Return value if in allowed, else default.
Always emitsChirpUIValidationWarning
on fallback (raisesValueErrorin strict mode).
Semantic alias groups (e.g.error / danger) are accepted when the
block's allowed tuple includes any member of the same group.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
value
|
str
|
— | |
allowed
|
tuple[str, ...]
|
— | |
default
|
str
|
''
|
validate_variant_block
function
def validate_variant_block(value: str, block: str, default: str = '') -> str
Return value if in VARIANT_REGISTRY for block, else default. When strict, log warning.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
value
|
str
|
— | |
block
|
str
|
— | |
default
|
str
|
''
|
validate_appearance_block
function
def validate_appearance_block(value: str, block: str, default: str = '') -> str
Return value if in APPEARANCE_REGISTRY for block, else fallback.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
value
|
str
|
— | |
block
|
str
|
— | |
default
|
str
|
''
|
validate_tone_block
function
def validate_tone_block(value: str, block: str, default: str = '') -> str
Return value if in TONE_REGISTRY for block, else fallback.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
value
|
str
|
— | |
block
|
str
|
— | |
default
|
str
|
''
|
deprecate_param
function
def deprecate_param(value: Any, old_name: str, new_name: str) -> Any
Warn when a deprecated parameter is used and return value unchanged.
Used in templates to signal deprecation while preserving backward compat::
{% set _attrs_raw = attrs_unsafe or (attrs | deprecate_param("attrs", "attrs_unsafe or attrs_map")) %}
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
value
|
Any
|
— | |
old_name
|
str
|
— | |
new_name
|
str
|
— |
value_type
function
def value_type(value: Any) -> str
Map Python types to ChirpUI CSS variant names for description_item.
Returns: "unset" | "bool" | "number" | "path" | "" (plain string).
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
value
|
Any
|
— |
validate_size
function
def validate_size(value: str, block: str, default: str = '') -> str
Return value if in SIZE_REGISTRY for block, else default.
Always emitsChirpUIValidationWarning
on fallback when the block has a registered size list
(raisesValueErrorin strict mode).
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
value
|
str
|
— | |
block
|
str
|
— | |
default
|
str
|
''
|
icon
function
def icon(name: str) -> str
Resolve icon name to glyph; unknown names pass through.
Always emitsChirpUIValidationWarning
for unrecognized names (raisesValueErrorin strict mode).
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
name
|
str
|
— |
field_errors
function
def field_errors(errors: dict[str, object] | None, field_name: str) -> list[str]
Extract error messages for a field from a ValidationError-style dict.
Returns empty list if errors is None, not a dict, or field has no errors.
Expectserrors[field_name]to be a list or tuple of strings.
Non-list values (e.g. nested dicts from DRF/Pydantic) are coerced to
[str(val)] with a ChirpUIValidationWarning.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
errors
|
dict[str, object] | None
|
— | |
field_name
|
str
|
— |
resolve_status_variant
function
def resolve_status_variant(status: str, default: str = 'muted') -> str
Map a status string to a badge variant usingSTATUS_WORDS.
Lookup is case-insensitive. Unrecognized words return default and
emitChirpUIValidationWarning.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
status
|
str
|
— | |
default
|
str
|
'muted'
|
build_hx_attrs
function
def build_hx_attrs(hx: dict[str, Any] | None = None, **kwargs: Any) -> dict[str, Any]
Build a dict of hyphenated HTML attributes from keyword arguments.
Converts underscores to hyphens in keys:hx_post becomes hx-post.
Pipe throughhtml_attrs to render: {{ build_hx_attrs(...) | html_attrs }}.
Accepts an optionalhxdict whose keys are the short htmx names
(e.g.{"post": "/save", "target": "#out"} → hx-post, hx-target).
Individualhx_* kwargs override keys from the hxdict.
EmitsChirpUIValidationWarningfor
unrecognized htmx attribute names (possible typos). Event handlers
(hx-on:*) and non-hx-keys pass through without warning.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
hx
|
dict[str, Any] | None
|
None
|
|
**kwargs
|
Any
|
— |
check_required_id
function
def check_required_id(value: str | None, fallback: str, component: str = '') -> str
Return value if provided, else fallback with a validation warning.
Use in macros where a hardcoded fallback ID would cause collisions if multiple instances appear on the same page::
{% set _id = check_required_id(swap_id, "inline-edit-field", "inline_edit_field") %}
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
value
|
str | None
|
— | |
fallback
|
str
|
— | |
component
|
str
|
''
|
make_route_link_attrs
function
def make_route_link_attrs(*, swap_resolver: Callable[..., Mapping[str, Any]] | None = None) -> Callable[..., dict[str, Any]]
Build a template global for route-aware link attrs.
The default no-op version keeps standalone chirp-ui renderable. When
swap_resolver is supplied (for example by Chirp's use_chirp_ui),
internalhref values can inherit route-aware hx-target / hx-boost
attrs automatically.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
swap_resolver
|
Callable[..., Mapping[str, Any]] | None
|
None
|
html_attrs
function
def html_attrs(value: Any) -> str | Markup
Render HTML attrs from mapping or legacy raw string.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
value
|
Any
|
— |
chirpui_asset_path
function
def chirpui_asset_path(path: str) -> str
Return the Bengal logical asset path for a Chirp UI provider asset.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
path
|
str
|
— |
View source · /home/runner/work/chirp-ui/chirp-ui/site/../src/chirp_ui/filters.py:1