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:
  • choice_dict (dict[str, bool] | NestedValue) –

    Dictionary with {option: boolean} structure

Returns:
  • list[str]

    List of selected option names (where value is True)

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:
  • unit (str) –

    The unit key ('days', 'weeks', 'months', 'years')

Returns:
  • str( str ) –

    The localized unit name

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:
  • period_value (dict) –

    Period value dict with mode, quantity, unit, date, event

  • locale_aware (bool, default: True ) –

    Whether to use locale-aware formatting

Returns:
  • str( str ) –

    Formatted period string

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:
  • ctx (Context) –

    Jinja context

  • value (str | Linguistic) –

    The word to pluralize

  • overrides (str | None, default: None ) –

    Optional override string for ad-hoc irregular forms. Format: "singular->plural,singular2->plural2" Example: {{ djur | plural("gås->gäss,åsna->åsnor") }}

  • if_ (int | None, default: None ) –

    Optional count - if 1, don't pluralize

definite_filter

definite_filter(ctx: Context, value: str | Linguistic, overrides: str | None = None) -> Linguistic

Jinja filter for definite form. Uses the Linguistic object.

Parameters:
  • ctx (Context) –

    Jinja context

  • value (str | Linguistic) –

    The word to make definite

  • overrides (str | None, default: None ) –

    Optional override string for ad-hoc forms. Format: "word->definite,word2->definite2" Example: {{ "konto" | definite("konto->kontot") }}

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:
  • ctx (Context) –

    Jinja context

  • value (str | Linguistic) –

    The word to make possessive

  • overrides (str | None, default: None ) –

    Optional override string for ad-hoc forms. Format: "word->possessive,word2->possessive2" Example: {{ "konto" | possessive("konto->kontots") }}

  • subject (str | None, default: None ) –

    Optional subject to add (e.g., "slut" -> "kontots slut")

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:
  • ctx (Context) –

    Jinja context

  • value (str) –

    The word to add indefinite article to

  • overrides (str | None, default: None ) –

    Optional override string for ad-hoc forms. Format: "word->indefinite,word2->indefinite2" Example: {{ "konto" | indefinite("konto->ett konto") }}