template_parser ¤
Overrides for the Django Template system to allow finer control over template parsing.
Based on Django Slippers v0.6.2 - https://github.com/mixxorz/slippers/blob/main/slippers/template.py
parse_bits ¤
parse_bits(
parser: Parser, bits: List[str], params: List[str], name: str
) -> Tuple[List[FilterExpression], List[Tuple[str, FilterExpression]]]
Parse bits for template tag helpers simple_tag and inclusion_tag, in particular by detecting syntax errors and by extracting positional and keyword arguments.
This is a simplified version of django.template.library.parse_bits
where we use custom regex to handle special characters in keyword names.
Furthermore, our version allows duplicate keys, and instead of return kwargs as a dict, we return it as a list of key-value pairs. So it is up to the user of this function to decide whether they support duplicate keys or not.
Source code in src/django_components/template_parser.py
token_kwargs ¤
Parse token keyword arguments and return a dictionary of the arguments retrieved from the bits
token list.
bits
is a list containing the remainder of the token (split by spaces) that is to be checked for arguments. Valid arguments are removed from this list.
There is no requirement for all remaining token bits
to be keyword arguments, so return the dictionary as soon as an invalid argument format is reached.