dj_angles.regex_replacer

Module Contents

dj_angles.regex_replacer.TAG_NAME_TO_DJANGO_TEMPLATE_TAG_MAP: dict[str | None, collections.abc.Callable | str] | None

Default mappings for tag names to Django template tags.

dj_angles.regex_replacer.tag_map: dict[str | None, collections.abc.Callable | str] | None = None
dj_angles.regex_replacer.get_tag_map() dict[str | None, collections.abc.Callable | str] | None

Get the complete tag map based on the default, dynamic, and settings mappers.

dj_angles.regex_replacer.clear_tag_map() None

Clear the generated tag map so that it will be re-generated. Useful for tests.

dj_angles.regex_replacer.get_replacements(html: str, *, raise_for_missing_start_tag: bool = True) list[tuple[str, str]]

Get a list of replacements (tuples that consists of 2 strings) based on the template HTML.

Parameters:
  • html (param) – Template HTML.

  • raise_for_missing_start_tag (param) – Whether or not to raise an error if an invalid tag is discovered.

Returns:

A list of tuples where the first item in the tuple is the existing tag element, e.g. “<dj-csrf />” and the second item is the replacement string, e.g. “{% csrf_token %}”.

dj_angles.regex_replacer.replace_django_template_tags(html: str) str

Gets a list of replacements based on template HTML, replaces the necessary strings, and returns the new string.

Parameters:

html (param) – Template HTML.

Returns:

The converted template HTML.