tag_formatter ¤
ComponentFormatter ¤
ComponentFormatter(tag: str)
Bases: TagFormatterABC
The original django_component's component tag formatter, it uses the component
and endcomponent
tags, and the component name is gives as the first positional arg.
Example as block:
Example as inlined tag:
Source code in src/django_components/tag_formatter.py
InternalTagFormatter ¤
InternalTagFormatter(tag_formatter: TagFormatterABC)
ShorthandComponentFormatter ¤
Bases: TagFormatterABC
The component tag formatter that uses <name>
/ end<name>
tags.
This is similar to django-web-components and django-slippers syntax.
Example as block:
Example as inlined tag:
TagFormatterABC ¤
Bases: ABC
end_tag abstractmethod
¤
parse abstractmethod
¤
Given the tokens (words) of a component start tag, this function extracts the component name from the tokens list, and returns TagResult
, which is a tuple of (component_name, remaining_tokens)
.
Example:
Given a component declarations:
{% component "my_comp" key=val key2=val2 %}
This function receives a list of tokens
['component', '"my_comp"', 'key=val', 'key2=val2']
component
is the tag name, which we drop. "my_comp"
is the component name, but we must remove the extra quotes. And we pass remaining tokens unmodified, as that's the input to the component.
So in the end, we return a tuple:
('my_comp', ['key=val', 'key2=val2'])
Source code in src/django_components/tag_formatter.py
TagResult ¤
get_tag_formatter ¤
get_tag_formatter(registry: ComponentRegistry) -> InternalTagFormatter
Returns an instance of the currently configured component tag formatter.