mirror of
https://github.com/django-components/django-components.git
synced 2025-09-26 15:39:08 +00:00
Rework slot management to avoid nodelist copying (fixes #64)
Co-authored-by: rbeard0330 <@dul2k3BKW6m>
This commit is contained in:
parent
5e8ae9d27b
commit
a5bd0cf2e3
4 changed files with 52 additions and 40 deletions
2
tests/templates/template_with_illegal_slot.html
Normal file
2
tests/templates/template_with_illegal_slot.html
Normal file
|
@ -0,0 +1,2 @@
|
|||
{% load component_tags %}
|
||||
{% include 'slotted_template.html' with context=None only %}
|
|
@ -2,9 +2,9 @@ from textwrap import dedent
|
|||
|
||||
from django.template import Context, Template, TemplateSyntaxError
|
||||
|
||||
from .django_test_setup import * # NOQA
|
||||
from django_components import component
|
||||
|
||||
from .django_test_setup import * # NOQA
|
||||
from .testutils import Django30CompatibleSimpleTestCase as SimpleTestCase
|
||||
|
||||
|
||||
|
@ -33,6 +33,11 @@ class SlottedComponent(component.Component):
|
|||
return "slotted_template.html"
|
||||
|
||||
|
||||
class BrokenComponent(component.Component):
|
||||
def template(self, context):
|
||||
return "template_with_illegal_slot.html"
|
||||
|
||||
|
||||
class SlottedComponentWithMissingVariable(component.Component):
|
||||
def template(self, context):
|
||||
return "slotted_template_with_missing_variable.html"
|
||||
|
@ -589,6 +594,7 @@ class TemplateSyntaxErrorTests(SimpleTestCase):
|
|||
def setUpClass(cls):
|
||||
super().setUpClass()
|
||||
component.registry.register('test', SlottedComponent)
|
||||
component.registry.register('broken_component', BrokenComponent)
|
||||
|
||||
def test_variable_outside_slot_tag_is_error(self):
|
||||
with self.assertRaises(TemplateSyntaxError):
|
||||
|
@ -634,3 +640,25 @@ class TemplateSyntaxErrorTests(SimpleTestCase):
|
|||
{% slot "header" %}{% endslot %}
|
||||
"""
|
||||
)
|
||||
|
||||
def test_slot_with_no_parent_is_error(self):
|
||||
with self.assertRaises(TemplateSyntaxError):
|
||||
Template(
|
||||
"""
|
||||
{% load component_tags %}
|
||||
{% slot "header" %}contents{% endslot %}
|
||||
"""
|
||||
).render(Context({}))
|
||||
|
||||
def test_isolated_slot_is_error(self):
|
||||
with self.assertRaises(TemplateSyntaxError):
|
||||
Template(
|
||||
"""
|
||||
{% load component_tags %}
|
||||
{% component_block "broken_component" %}
|
||||
{% slot "header" %}Custom header{% endslot %}
|
||||
{% slot "main" %}Custom main{% endslot %}
|
||||
{% slot "footer" %}Custom footer{% endslot %}
|
||||
{% endcomponent_block %}
|
||||
"""
|
||||
).render(Context({}))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue