dj_angles.replacers.attributes¶
Replace attributes like <div dj-if=”condition”> with Django template tags.
Parses HTML into a tree structure
Groups conditional elements by their parent (siblings)
Chains siblings together (if → elif → else)
Generates output with proper {% if %}/{% endif %} wrapping
Module Contents¶
- class dj_angles.replacers.attributes.Element¶
Represents an HTML element with a dj-* attribute.
- full_end: int¶
Position just after the element’s closing tag, or
tag_endfor void/self-closing tags.
- class dj_angles.replacers.attributes.ConditionalElement¶
Bases:
ElementRepresents an element with a dj-if/elif/else attribute.
- next_in_chain: ConditionalElement | None = None¶
- dj_angles.replacers.attributes.replace_conditionals(html: str) str¶
Convert dj-if/elif/else attributes to Django template tags.
- Parameters:
html – The HTML string to process
prefix – The attribute prefix (default “dj-“). If None, uses detailed configuration.
- Returns:
HTML with Django template tags
- dj_angles.replacers.attributes.replace_values(html: str) str¶
Convert dj-value attributes to Django variable output.
The attribute is removed from the opening tag, the element’s inner content is replaced with {{ value }}, and void/self-closing tags are turned into paired tags so the value has a place to render.
- Parameters:
html – The HTML string to process.
- Returns:
HTML with dj-value attributes replaced by Django template variables.