filters

Page actions AI-ready formats and sharing
Open LLM text
Share with AI
Ask Claude Ask ChatGPT Ask Gemini Ask Copilot

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 allis internal and…

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

function reset_colors

Clear all registered semantic color names for the current context.

Jump to symbol
function register_colors

Register semantic color names (e.g. Pokémon types) forresolve_color().

RaisesValueErrorimmediately if any color value fails sanitize_color() validation.

Jump to symbol
function sanitize_color

Return the color if it matches a safe CSS color pattern, else None.

Jump to symbol
function contrast_text

Returnwhite or #1a1a1afor readable text on solid css_color.

Supports hex,rgb(), hsl(), and oklch()color formats. EmitsChirpUIValidationWarningwhen…

Jump to symbol
function resolve_color

Resolve a named color from the registry, then validate as a CSS color string.

Jump to symbol
function bem

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"…
Jump to symbol
function validate_variant

Return value if in allowed, else default.

Always emitsChirpUIValidationWarning on fallback (raisesValueErrorin strict mode).

Semantic alias groups (e.g.error / danger…

Jump to symbol
function validate_variant_block

Return value if in VARIANT_REGISTRY for block, else default. When strict, log warning.

Jump to symbol
function validate_appearance_block

Return value if in APPEARANCE_REGISTRY for block, else fallback.

Jump to symbol
function validate_tone_block

Return value if in TONE_REGISTRY for block, else fallback.

Jump to symbol
function deprecate_param

Warn when a deprecated parameter is used and return value unchanged.

Used in templates to signal deprecation while preserving backward compat::

{% set _attrs_raw…
Jump to symbol
function value_type

Map Python types to ChirpUI CSS variant names for description_item.

Returns: "unset" | "bool" | "number" | "path" | "" (plain string).

Jump to symbol
function validate_size

Return value if in SIZE_REGISTRY for block, else default.

Always emitsChirpUIValidationWarning on fallback when the block has a registered size list (raisesValueError…

Jump to symbol
function icon

Resolve icon name to glyph; unknown names pass through.

Always emitsChirpUIValidationWarning for unrecognized names (raisesValueErrorin strict mode).

Jump to symbol
function field_errors

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…

Jump to symbol
function resolve_status_variant

Map a status string to a badge variant usingSTATUS_WORDS.

Lookup is case-insensitive. Unrecognized words return default and emitChirpUIValidationWarning.

Jump to symbol
function build_hx_attrs

Build a dict of hyphenated HTML attributes from keyword arguments.

Converts underscores to hyphens in keys:hx_post becomes hx-post. Pipe throughhtml_attrsto…

Jump to symbol
function check_required_id

Return value if provided, else fallback with a validation warning.

Use in macros where a hardcoded fallback ID would cause collisions if multiple instances…

Jump to symbol
function make_route_link_attrs

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 …

Jump to symbol
function html_attrs

Render HTML attrs from mapping or legacy raw string.

Jump to symbol
function chirpui_asset_path

Return the Bengal logical asset path for a Chirp UI provider asset.

Jump to symbol
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
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