vibe.filters¶
Jinja filter helpers used throughout VIBE templates.
format_amount ¶
format_amount(amount_obj: dict[str, Any] | NestedValue) -> str
Format an amount object (dict or NestedValue) into a currency string.
Example: {'value': 150, 'currency': 'USD'} -> '$150.00'.
format_amount_helper ¶
format_amount_helper(data_dict: dict[str, Any], definition_dict: dict[str, Any]) -> str
Shared helper to format an amount object based on its definition.
markdown_filter ¶
markdown_filter(md: object) -> str
Render Markdown to sanitized HTML for safe inline insertion.
Converts the given value to string, renders with the Markdown library and sanitizes using nh3 before returning HTML. Keeps server-side control of rendering consistent with the server-first ethos.
selected_choices ¶
selected_choices(choice_dict: dict[str, bool] | NestedValue) -> list[str]
Filter for multichoice dictionaries that returns only the selected choices.
| Parameters: |
|
|---|
| Returns: |
|
|---|
safe_default ¶
safe_default(ctx: Context, value: object, default_value: object = '', boolean: bool = False) -> object
Replace Jinja's default filter with probe context awareness.
In probe mode, always raise UndefinedError if given an undefined value. Also recognize get_preview_placeholder_value() output and replace it with the given argument (which is presumably better tailored to the specific situation).
period_unit_name ¶
period_unit_name(unit: str) -> str
Return the localized display name for a period unit.
| Parameters: |
|
|---|
| Returns: |
|
|---|
format_period_display ¶
format_period_display(period_value: dict[str, Any] | NestedValue | None, locale_aware: bool = True) -> str
Format a period value for display using locale-aware formatting.
| Parameters: |
|
|---|
| Returns: |
|
|---|
plural_filter ¶
plural_filter(ctx: Context, value: str | Linguistic, overrides: str | None = None, if_: int | None = None) -> Linguistic
Jinja filter for pluralization. Uses the Linguistic object.
| Parameters: |
|
|---|
definite_filter ¶
definite_filter(ctx: Context, value: str | Linguistic, overrides: str | None = None) -> Linguistic
Jinja filter for definite form. Uses the Linguistic object.
| Parameters: |
|
|---|
possessive_filter ¶
possessive_filter(ctx: Context, value: str | Linguistic, overrides: str | None = None, subject: str | None = None) -> Linguistic
Jinja filter for possessive form. Uses the Linguistic object.
| Parameters: |
|
|---|
itemize_filter ¶
itemize_filter(ctx: Context, value: str | Linguistic, conjunction: str | None = None, **kwargs: object) -> Linguistic
Jinja filter for formatting lists of items with custom conjunctions.
This filter is special because its main job is to set the conjunction on the Linguistic object for when it's finally rendered as a string. It also handles the special case where it receives a raw string instead of a Linguistic object.
Accepts localized parameter names (e.g., 'konjunktion' for Swedish/German, 'conjonction' for French, 'conjuncion' for Spanish).
cardinal_filter_jinja ¶
cardinal_filter_jinja(ctx: Context, value: int | float, cutoff: int | None = None) -> str
Jinja filter for converting numbers to words with optional cutoff threshold.
ordinal_filter_jinja ¶
ordinal_filter_jinja(ctx: Context, value: int) -> str
Jinja filter for converting numbers to ordinal words.
doublet_filter_jinja ¶
doublet_filter_jinja(ctx: Context, value: int | float, unit: str | None = None) -> str
Jinja filter for creating legal doublet format: 10 -> "ten (10)" with optional unit.
roman_filter_jinja ¶
roman_filter_jinja(value: int, case: str = 'upper') -> str
Jinja filter for converting numbers to Roman numerals.
alpha_filter_jinja ¶
alpha_filter_jinja(value: int, case: str = 'upper') -> str
Jinja filter for converting numbers to alphabetical labels (1=A, 2=B, ...).
indefinite_filter_jinja ¶
indefinite_filter_jinja(ctx: Context, value: str, overrides: str | None = None) -> str
Jinja filter for adding indefinite article (a/an, en/ett, etc.).
| Parameters: |
|
|---|