mirror of
https://github.com/django-components/django-components.git
synced 2025-08-30 10:47:20 +00:00
refactor: fix slot context behavior (#445)
This commit is contained in:
parent
f3d6337ecc
commit
3ad0dd8677
6 changed files with 287 additions and 80 deletions
|
@ -1,6 +1,7 @@
|
|||
from typing import List
|
||||
from unittest.mock import Mock
|
||||
|
||||
from django.template import Context
|
||||
from django.template import Context, Node
|
||||
from django.template.response import TemplateResponse
|
||||
from django.test import SimpleTestCase
|
||||
|
||||
|
@ -32,3 +33,22 @@ def create_and_process_template_response(template, context=None, use_middleware=
|
|||
else:
|
||||
response.render()
|
||||
return response.content.decode("utf-8")
|
||||
|
||||
|
||||
def print_nodes(nodes: List[Node], indent=0) -> None:
|
||||
"""
|
||||
Render a Nodelist, inlining child nodes with extra on separate lines and with
|
||||
extra indentation.
|
||||
"""
|
||||
for node in nodes:
|
||||
child_nodes: List[Node] = []
|
||||
for attr in node.child_nodelists:
|
||||
attr_child_nodes = getattr(node, attr, None) or []
|
||||
if attr_child_nodes:
|
||||
child_nodes.extend(attr_child_nodes)
|
||||
|
||||
repr = str(node)
|
||||
repr = "\n".join([(" " * 4 * indent) + line for line in repr.split("\n")])
|
||||
print(repr)
|
||||
if child_nodes:
|
||||
print_nodes(child_nodes, indent=indent + 1)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue