mirror of
https://github.com/django-components/django-components.git
synced 2025-09-23 06:02:27 +00:00
refactor: make fill parsers always return list
This commit is contained in:
parent
4562f3b3da
commit
094e05054d
1 changed files with 5 additions and 5 deletions
|
@ -286,7 +286,7 @@ def parse_slot_fill_nodes_from_component_nodelist(
|
||||||
def _try_parse_as_named_fill_tag_set(
|
def _try_parse_as_named_fill_tag_set(
|
||||||
nodelist: NodeList,
|
nodelist: NodeList,
|
||||||
ComponentNodeCls: Type[Node],
|
ComponentNodeCls: Type[Node],
|
||||||
) -> Optional[Iterable[NamedFillNode]]:
|
) -> Sequence[NamedFillNode]:
|
||||||
result = []
|
result = []
|
||||||
seen_name_fexps: Set[FilterExpression] = set()
|
seen_name_fexps: Set[FilterExpression] = set()
|
||||||
for node in nodelist:
|
for node in nodelist:
|
||||||
|
@ -303,19 +303,19 @@ def _try_parse_as_named_fill_tag_set(
|
||||||
elif isinstance(node, TextNode) and node.s.isspace():
|
elif isinstance(node, TextNode) and node.s.isspace():
|
||||||
pass
|
pass
|
||||||
else:
|
else:
|
||||||
return None
|
return []
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
|
||||||
def _try_parse_as_default_fill(
|
def _try_parse_as_default_fill(
|
||||||
nodelist: NodeList,
|
nodelist: NodeList,
|
||||||
ComponentNodeCls: Type[Node],
|
ComponentNodeCls: Type[Node],
|
||||||
) -> Optional[ImplicitFillNode]:
|
) -> Sequence[ImplicitFillNode]:
|
||||||
nodes_stack: List[Node] = list(nodelist)
|
nodes_stack: List[Node] = list(nodelist)
|
||||||
while nodes_stack:
|
while nodes_stack:
|
||||||
node = nodes_stack.pop()
|
node = nodes_stack.pop()
|
||||||
if isinstance(node, NamedFillNode):
|
if isinstance(node, NamedFillNode):
|
||||||
return None
|
return []
|
||||||
elif isinstance(node, ComponentNodeCls):
|
elif isinstance(node, ComponentNodeCls):
|
||||||
# Stop searching here, as fill tags are permitted inside component blocks
|
# Stop searching here, as fill tags are permitted inside component blocks
|
||||||
# embedded within a default fill node.
|
# embedded within a default fill node.
|
||||||
|
@ -323,7 +323,7 @@ def _try_parse_as_default_fill(
|
||||||
for nodelist_attr_name in node.child_nodelists:
|
for nodelist_attr_name in node.child_nodelists:
|
||||||
nodes_stack.extend(getattr(node, nodelist_attr_name, []))
|
nodes_stack.extend(getattr(node, nodelist_attr_name, []))
|
||||||
else:
|
else:
|
||||||
return ImplicitFillNode(nodelist=nodelist)
|
return [ImplicitFillNode(nodelist=nodelist)]
|
||||||
|
|
||||||
|
|
||||||
def _block_has_content(nodelist: NodeList) -> bool:
|
def _block_has_content(nodelist: NodeList) -> bool:
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue