mirror of
https://github.com/django-components/django-components.git
synced 2025-09-26 07:29:09 +00:00
fix: incorrect name for default slot in is_filled dict (#482)
This commit is contained in:
parent
dee1524dc0
commit
dd6540cfcc
2 changed files with 46 additions and 17 deletions
|
@ -461,7 +461,17 @@ def _resolve_default_slot(
|
||||||
|
|
||||||
# Here we've identified which slot the default/implicit fill belongs to
|
# Here we've identified which slot the default/implicit fill belongs to
|
||||||
if default_fill:
|
if default_fill:
|
||||||
named_fills[slot.name] = default_fill._replace(name=slot.name)
|
# NOTE: We recreate new instance, passing all fields, instead of using
|
||||||
|
# `NamedTuple._replace`, because `_replace` is not typed.
|
||||||
|
named_fills[slot.name] = SlotFill(
|
||||||
|
is_filled=default_fill.is_filled,
|
||||||
|
nodelist=default_fill.nodelist,
|
||||||
|
context_data=default_fill.context_data,
|
||||||
|
alias=default_fill.alias,
|
||||||
|
# Updated fields
|
||||||
|
name=slot.name,
|
||||||
|
escaped_name=_escape_slot_name(slot.name),
|
||||||
|
)
|
||||||
|
|
||||||
# Check: Only component templates that include a 'default' slot
|
# Check: Only component templates that include a 'default' slot
|
||||||
# can be invoked with implicit filling.
|
# can be invoked with implicit filling.
|
||||||
|
|
|
@ -1157,7 +1157,7 @@ class ComponentNestingTests(BaseTestCase):
|
||||||
class ComplexParentComponent(component.Component):
|
class ComplexParentComponent(component.Component):
|
||||||
template: types.django_html = """
|
template: types.django_html = """
|
||||||
{% load component_tags %}
|
{% load component_tags %}
|
||||||
ITEMS: {{ items }}
|
ITEMS: {{ items|safe }}
|
||||||
{% for item in items %}
|
{% for item in items %}
|
||||||
<li>
|
<li>
|
||||||
{% component "complex_child" %}
|
{% component "complex_child" %}
|
||||||
|
@ -1296,7 +1296,7 @@ class ComponentNestingTests(BaseTestCase):
|
||||||
items = [{"value": 1}, {"value": 2}, {"value": 3}]
|
items = [{"value": 1}, {"value": 2}, {"value": 3}]
|
||||||
rendered = template.render(Context({"items": items}))
|
rendered = template.render(Context({"items": items}))
|
||||||
expected = """
|
expected = """
|
||||||
ITEMS: [{'value': 1}, {'value': 2}, {'value': 3}]
|
ITEMS: [{'value': 1}, {'value': 2}, {'value': 3}]
|
||||||
<li>
|
<li>
|
||||||
<div> 1 </div>
|
<div> 1 </div>
|
||||||
</li>
|
</li>
|
||||||
|
@ -1522,12 +1522,12 @@ class ContextVarsTests(BaseTestCase):
|
||||||
template: types.django_html = """
|
template: types.django_html = """
|
||||||
{% load component_tags %}
|
{% load component_tags %}
|
||||||
<div class="frontmatter-component">
|
<div class="frontmatter-component">
|
||||||
{% slot "title" %}{% endslot %}
|
{% slot "title" default %}{% endslot %}
|
||||||
{% slot "my_title" %}{% endslot %}
|
{% slot "my_title" %}{% endslot %}
|
||||||
{% slot "my title 1" %}{% endslot %}
|
{% slot "my title 1" %}{% endslot %}
|
||||||
{% slot "my-title-2" %}{% endslot %}
|
{% slot "my-title-2" %}{% endslot %}
|
||||||
{% slot "escape this: #$%^*()" %}{% endslot %}
|
{% slot "escape this: #$%^*()" %}{% endslot %}
|
||||||
{{ component_vars.is_filled }}
|
{{ component_vars.is_filled|safe }}
|
||||||
</div>
|
</div>
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
@ -1546,14 +1546,33 @@ class ContextVarsTests(BaseTestCase):
|
||||||
{% endcomponent %}
|
{% endcomponent %}
|
||||||
"""
|
"""
|
||||||
rendered = Template(template).render(Context())
|
rendered = Template(template).render(Context())
|
||||||
# NOTE: `'` are escaped quotes
|
|
||||||
expected = """
|
expected = """
|
||||||
<div class="frontmatter-component">
|
<div class="frontmatter-component">
|
||||||
{'title': True,
|
{'title': True,
|
||||||
'my_title': False,
|
'my_title': False,
|
||||||
'my_title_1': False,
|
'my_title_1': False,
|
||||||
'my_title_2': True,
|
'my_title_2': True,
|
||||||
'escape_this_________': True}
|
'escape_this_________': True}
|
||||||
|
</div>
|
||||||
|
"""
|
||||||
|
self.assertHTMLEqual(rendered, expected)
|
||||||
|
|
||||||
|
def test_is_filled_vars_default(self):
|
||||||
|
template: types.django_html = """
|
||||||
|
{% load component_tags %}
|
||||||
|
{% component "is_filled_vars" %}
|
||||||
|
bla bla
|
||||||
|
{% endcomponent %}
|
||||||
|
"""
|
||||||
|
rendered = Template(template).render(Context())
|
||||||
|
expected = """
|
||||||
|
<div class="frontmatter-component">
|
||||||
|
bla bla
|
||||||
|
{'title': True,
|
||||||
|
'my_title': False,
|
||||||
|
'my_title_1': False,
|
||||||
|
'my_title_2': False,
|
||||||
|
'escape_this_________': False}
|
||||||
</div>
|
</div>
|
||||||
"""
|
"""
|
||||||
self.assertHTMLEqual(rendered, expected)
|
self.assertHTMLEqual(rendered, expected)
|
||||||
|
@ -2337,10 +2356,10 @@ class IterationFillTest(BaseTestCase):
|
||||||
{% load component_tags %}
|
{% load component_tags %}
|
||||||
{% component "slot_in_a_loop" objects=objects %}
|
{% component "slot_in_a_loop" objects=objects %}
|
||||||
{% fill "slot_inner" %}
|
{% fill "slot_inner" %}
|
||||||
{{ outer_scope_variable_1 }}
|
{{ outer_scope_variable_1|safe }}
|
||||||
{% component "slot_in_a_loop" objects=objects %}
|
{% component "slot_in_a_loop" objects=objects %}
|
||||||
{% fill "slot_inner" as "super_slot_inner" %}
|
{% fill "slot_inner" as "super_slot_inner" %}
|
||||||
{{ outer_scope_variable_2 }}
|
{{ outer_scope_variable_2|safe }}
|
||||||
{{ super_slot_inner.default }}
|
{{ super_slot_inner.default }}
|
||||||
{% endfill %}
|
{% endfill %}
|
||||||
{% endcomponent %}
|
{% endcomponent %}
|
||||||
|
@ -2363,13 +2382,13 @@ class IterationFillTest(BaseTestCase):
|
||||||
"""
|
"""
|
||||||
OUTER_SCOPE_VARIABLE1
|
OUTER_SCOPE_VARIABLE1
|
||||||
OUTER_SCOPE_VARIABLE2
|
OUTER_SCOPE_VARIABLE2
|
||||||
{'inner': ['ITER1_OBJ1', 'ITER1_OBJ2']} default
|
{'inner': ['ITER1_OBJ1', 'ITER1_OBJ2']} default
|
||||||
OUTER_SCOPE_VARIABLE2
|
OUTER_SCOPE_VARIABLE2
|
||||||
{'inner': ['ITER2_OBJ1', 'ITER2_OBJ2']} default
|
{'inner': ['ITER2_OBJ1', 'ITER2_OBJ2']} default
|
||||||
OUTER_SCOPE_VARIABLE1
|
OUTER_SCOPE_VARIABLE1
|
||||||
OUTER_SCOPE_VARIABLE2
|
OUTER_SCOPE_VARIABLE2
|
||||||
{'inner': ['ITER1_OBJ1', 'ITER1_OBJ2']} default
|
{'inner': ['ITER1_OBJ1', 'ITER1_OBJ2']} default
|
||||||
OUTER_SCOPE_VARIABLE2
|
OUTER_SCOPE_VARIABLE2
|
||||||
{'inner': ['ITER2_OBJ1', 'ITER2_OBJ2']} default
|
{'inner': ['ITER2_OBJ1', 'ITER2_OBJ2']} default
|
||||||
""",
|
""",
|
||||||
)
|
)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue