fix: Using empty default fill with no whitespace (#673)

This commit is contained in:
Juro Oravec 2024-09-14 22:22:22 +02:00 committed by GitHub
parent fa556d281c
commit 6b3c112968
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 29 additions and 1 deletions

View file

@ -25,9 +25,11 @@ class BaseNode(Node):
self.kwargs = kwargs or RuntimeKwargs({})
# NOTE: We consider Nodes to have content only if they have anything else
# beside whitespace and comments.
def nodelist_has_content(nodelist: NodeList) -> bool:
for node in nodelist:
if isinstance(node, TextNode) and node.s.isspace():
if isinstance(node, TextNode) and (not node.s or node.s.isspace()):
pass
elif isinstance(node, CommentNode):
pass

View file

@ -511,3 +511,29 @@ class MultilineTagsTests(BaseTestCase):
Variable: <strong>123</strong>
"""
self.assertHTMLEqual(rendered, expected)
class NestedTagsTests(BaseTestCase):
# See https://github.com/EmilStenstrom/django-components/discussions/671
@parametrize_context_behavior(["django", "isolated"])
def test_nested_tags(self):
@register("test_component")
class SimpleComponent(Component):
template: types.django_html = """
Variable: <strong>{{ var }}</strong>
"""
def get_context_data(self, var):
return {
"var": var,
}
template: types.django_html = """
{% load component_tags %}
{% component "test_component" var="{% lorem 1 w %}" %}{% endcomponent %}
"""
rendered = Template(template).render(Context())
expected = """
Variable: <strong>lorem</strong>
"""
self.assertHTMLEqual(rendered, expected)