mirror of
https://github.com/django-components/django-components.git
synced 2025-10-17 01:07:12 +00:00
Introduce {% fill %} replacing 'fill' func of 'slot' tag
Partial implementation fill-tags plus update tests Implement {% fill %} tags. Next: update tests. Bring back support for {%slot%} blocks for bckwrd-compat and implement ambig. resolution policy Update tests to use fill blocks. Add extra checks that raise errors Add new tests for fill-slot nesting Update README. Editing still required remove unused var ctxt after flake8 complaint fix flake8 warning about slotless f-string [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci Add new slot aliases in fill context. Clean up rendering logic in Component. Update docs. fix flake8, isort, black errors Refactor duplicated name validation Add if_filled tag + elif_filled...else_filled...endif_filled for cond. slots Fix mistake in do_if_filled() docstring Upload templates for tests! D'oh Incorporate PR feedback Drop Literal type hint; Use isort off-on instead of skip in tests Treat all fill,slot,if_filled,component names as variables Reset sampleproject components Add test for variable filled name Update examples in docs
This commit is contained in:
parent
714fc9edb0
commit
a8dfcce24e
20 changed files with 1090 additions and 307 deletions
|
@ -5,13 +5,12 @@ from django.template import Context, Template
|
|||
|
||||
# isort: off
|
||||
from .django_test_setup import * # NOQA
|
||||
from .testutils import Django30CompatibleSimpleTestCase as SimpleTestCase
|
||||
|
||||
# isort: on
|
||||
|
||||
from django_components import component
|
||||
|
||||
from .testutils import Django30CompatibleSimpleTestCase as SimpleTestCase
|
||||
|
||||
|
||||
class ComponentTest(SimpleTestCase):
|
||||
def test_empty_component(self):
|
||||
|
@ -19,7 +18,7 @@ class ComponentTest(SimpleTestCase):
|
|||
pass
|
||||
|
||||
with self.assertRaises(ImproperlyConfigured):
|
||||
EmptyComponent("empty_component").get_template_name()
|
||||
EmptyComponent("empty_component").get_template_name(Context({}))
|
||||
|
||||
def test_simple_component(self):
|
||||
class SimpleComponent(component.Component):
|
||||
|
@ -275,13 +274,13 @@ class ComponentIsolationTests(SimpleTestCase):
|
|||
"""
|
||||
{% load component_tags %}
|
||||
{% component_block "test" %}
|
||||
{% slot "header" %}Override header{% endslot %}
|
||||
{% fill "header" %}Override header{% endfill %}
|
||||
{% endcomponent_block %}
|
||||
{% component_block "test" %}
|
||||
{% slot "main" %}Override main{% endslot %}
|
||||
{% fill "main" %}Override main{% endfill %}
|
||||
{% endcomponent_block %}
|
||||
{% component_block "test" %}
|
||||
{% slot "footer" %}Override footer{% endslot %}
|
||||
{% fill "footer" %}Override footer{% endfill %}
|
||||
{% endcomponent_block %}
|
||||
"""
|
||||
)
|
||||
|
@ -309,43 +308,3 @@ class ComponentIsolationTests(SimpleTestCase):
|
|||
</custom-template>
|
||||
""",
|
||||
)
|
||||
|
||||
|
||||
class RecursiveSlotNameTest(SimpleTestCase):
|
||||
def setUp(self):
|
||||
@component.register("outer")
|
||||
class OuterComponent(component.Component):
|
||||
template_name = "slotted_template.html"
|
||||
|
||||
@component.register("inner")
|
||||
class InnerComponent(component.Component):
|
||||
template_name = "slotted_template.html"
|
||||
|
||||
def test_no_infinite_recursion_when_slot_name_is_reused(self):
|
||||
template = Template(
|
||||
"""
|
||||
{% load component_tags %}
|
||||
{% component_block "outer" %}
|
||||
{% slot "header" %}
|
||||
{% component_block "inner" %}{% endcomponent_block %}
|
||||
{% endslot %}
|
||||
{% endcomponent_block %}
|
||||
"""
|
||||
)
|
||||
|
||||
self.assertHTMLEqual(
|
||||
template.render(Context({})),
|
||||
"""
|
||||
<custom-template>
|
||||
<header>
|
||||
<custom-template>
|
||||
<header>Default header</header>
|
||||
<main>Default main</main>
|
||||
<footer>Default footer</footer>
|
||||
</custom-template>
|
||||
</header>
|
||||
<main>Default main</main>
|
||||
<footer>Default footer</footer>
|
||||
</custom-template>
|
||||
""",
|
||||
)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue