Replace all instances of component_block with component. Remove duplicate tests.

This commit is contained in:
Emil Stenström 2024-02-11 23:14:43 +01:00 committed by Emil Stenström
parent 48fe8171b4
commit edf3885632
14 changed files with 246 additions and 310 deletions

View file

@ -7,7 +7,7 @@ A way to create simple reusable template components in Django.
It lets you create "template components", that contains both the template, the Javascript and the CSS needed to generate the front end code you need for a modern app. Components look like this: It lets you create "template components", that contains both the template, the Javascript and the CSS needed to generate the front end code you need for a modern app. Components look like this:
```htmldjango ```htmldjango
{% component_block "calendar" date="2015-06-19" %}{% endcomponent_block %} {% component "calendar" date="2015-06-19" %}{% endcomponent %}
``` ```
And this is what gets rendered (plus the CSS and Javascript you've specified): And this is what gets rendered (plus the CSS and Javascript you've specified):
@ -220,7 +220,7 @@ First load the `component_tags` tag library, then use the `component_[js/css]_de
{% component_css_dependencies %} {% component_css_dependencies %}
</head> </head>
<body> <body>
{% component_block "calendar" date="2015-06-19" %}{% endcomponent_block %} {% component "calendar" date="2015-06-19" %}{% endcomponent %}
{% component_js_dependencies %} {% component_js_dependencies %}
</body> </body>
<html> <html>
@ -297,7 +297,7 @@ This mechanism makes components more reusable and composable.
In the example below we introduce two block tags that work hand in hand to make this work. These are... In the example below we introduce two block tags that work hand in hand to make this work. These are...
- `{% slot <name> %}`/`{% endslot %}`: Declares a new slot in the component template. - `{% slot <name> %}`/`{% endslot %}`: Declares a new slot in the component template.
- `{% fill <name> %}`/`{% endfill %}`: (Used inside a `component_block` tag pair.) Fills a declared slot with the specified content. - `{% fill <name> %}`/`{% endfill %}`: (Used inside a `component` tag pair.) Fills a declared slot with the specified content.
Let's update our calendar component to support more customization. We'll add `slot` tag pairs to its template, _calendar.html_. Let's update our calendar component to support more customization. We'll add `slot` tag pairs to its template, _calendar.html_.
@ -315,9 +315,9 @@ Let's update our calendar component to support more customization. We'll add `sl
When using the component, you specify which slots you want to fill and where you want to use the defaults from the template. It looks like this: When using the component, you specify which slots you want to fill and where you want to use the defaults from the template. It looks like this:
```htmldjango ```htmldjango
{% component_block "calendar" date="2020-06-06" %} {% component "calendar" date="2020-06-06" %}
{% fill "body" %}Can you believe it's already <span>{{ date }}</span>??{% endfill %} {% fill "body" %}Can you believe it's already <span>{{ date }}</span>??{% endfill %}
{% endcomponent_block %} {% endcomponent %}
``` ```
Since the header block is unspecified, it's taken from the base template. If you put this in a template, and pass in `date=2020-06-06`, this is what gets rendered: Since the header block is unspecified, it's taken from the base template. If you put this in a template, and pass in `date=2020-06-06`, this is what gets rendered:
@ -335,7 +335,7 @@ Since the header block is unspecified, it's taken from the base template. If you
As you can see, component slots lets you write reusable containers that you fill in when you use a component. This makes for highly reusable components that can be used in different circumstances. As you can see, component slots lets you write reusable containers that you fill in when you use a component. This makes for highly reusable components that can be used in different circumstances.
It can become tedious to use `fill` tags everywhere, especially when you're using a component that declares only one slot. To make things easier, `slot` tags can be marked with an optional keyword: `default`. When added to the end of the tag (as shown below), this option lets you pass filling content directly in the body of a `component_block` tag pair without using a `fill` tag. Choose carefully, though: a component template may contain at most one slot that is marked as `default`. The `default` option can be combined with other slot options, e.g. `required`. It can become tedious to use `fill` tags everywhere, especially when you're using a component that declares only one slot. To make things easier, `slot` tags can be marked with an optional keyword: `default`. When added to the end of the tag (as shown below), this option lets you pass filling content directly in the body of a `component` tag pair without using a `fill` tag. Choose carefully, though: a component template may contain at most one slot that is marked as `default`. The `default` option can be combined with other slot options, e.g. `required`.
Here's the same example as before, except with default slots and implicit filling. Here's the same example as before, except with default slots and implicit filling.
@ -355,9 +355,9 @@ The template:
Including the component (notice how the `fill` tag is omitted): Including the component (notice how the `fill` tag is omitted):
```htmldjango ```htmldjango
{% component_block "calendar" date="2020-06-06" %} {% component "calendar" date="2020-06-06" %}
Can you believe it's already <span>{{ date }}</span>?? Can you believe it's already <span>{{ date }}</span>??
{% endcomponent_block %} {% endcomponent %}
``` ```
The rendered result (exactly the same as before): The rendered result (exactly the same as before):
@ -377,32 +377,32 @@ You may be tempted to combine implicit fills with explicit `fill` tags. This wil
```htmldjango ```htmldjango
{# DON'T DO THIS #} {# DON'T DO THIS #}
{% component_block "calendar" date="2020-06-06" %} {% component "calendar" date="2020-06-06" %}
{% fill "header" %}Totally new header!{% endfill %} {% fill "header" %}Totally new header!{% endfill %}
Can you believe it's already <span>{{ date }}</span>?? Can you believe it's already <span>{{ date }}</span>??
{% endcomponent_block %} {% endcomponent %}
``` ```
By contrast, it is permitted to use `fill` tags in nested components, e.g.: By contrast, it is permitted to use `fill` tags in nested components, e.g.:
```htmldjango ```htmldjango
{% component_block "calendar" date="2020-06-06" %} {% component "calendar" date="2020-06-06" %}
{% component_block "beautiful-box" %} {% component "beautiful-box" %}
{% fill "content" %} Can you believe it's already <span>{{ date }}</span>?? {% endfill %} {% fill "content" %} Can you believe it's already <span>{{ date }}</span>?? {% endfill %}
{% endcomponent_block %} {% endcomponent %}
{% endcomponent_block %} {% endcomponent %}
``` ```
This is fine too: This is fine too:
```htmldjango ```htmldjango
{% component_block "calendar" date="2020-06-06" %} {% component "calendar" date="2020-06-06" %}
{% fill "header" %} {% fill "header" %}
{% component_block "calendar-header" %} {% component "calendar-header" %}
Super Special Calendar Header Super Special Calendar Header
{% endcomponent_block %} {% endcomponent %}
{% endfill %} {% endfill %}
{% endcomponent_block %} {% endcomponent %}
``` ```
### Components as views ### Components as views
@ -479,9 +479,9 @@ If you're planning on passing an HTML string, check Django's use of [`format_htm
Certain properties of a slot can be accessed from within a 'fill' context. They are provided as attributes on a user-defined alias of the targeted slot. For instance, let's say you're filling a slot called 'body'. To access properties of this slot, alias it using the 'as' keyword to a new name -- or keep the original name. With the new slot alias, you can call `<alias>.default` to insert the default content. Certain properties of a slot can be accessed from within a 'fill' context. They are provided as attributes on a user-defined alias of the targeted slot. For instance, let's say you're filling a slot called 'body'. To access properties of this slot, alias it using the 'as' keyword to a new name -- or keep the original name. With the new slot alias, you can call `<alias>.default` to insert the default content.
```htmldjango ```htmldjango
{% component_block "calendar" date="2020-06-06" %} {% component "calendar" date="2020-06-06" %}
{% fill "body" as "body" %}{{ body.default }}. Have a great day!{% endfill %} {% fill "body" as "body" %}{{ body.default }}. Have a great day!{% endfill %}
{% endcomponent_block %} {% endcomponent %}
``` ```
Produces: Produces:
@ -614,10 +614,10 @@ COMPONENTS = {
## Component context and scope ## Component context and scope
By default, components can access context variables from the parent template, just like templates that are included with the `{% include %}` tag. Just like with `{% include %}`, if you don't want the component template to have access to the parent context, add `only` to the end of the `{% component_block %}` (or `{% component_block %}{% endcomponent_block %}` tag): By default, components can access context variables from the parent template, just like templates that are included with the `{% include %}` tag. Just like with `{% include %}`, if you don't want the component template to have access to the parent context, add `only` to the end of the `{% component %}` (or `{% component %}{% endcomponent %}` tag):
```htmldjango ```htmldjango
{% component_block "calendar" date="2015-06-19" only %}{% endcomponent_block %} {% component "calendar" date="2015-06-19" only %}{% endcomponent %}
``` ```
NOTE: `{% csrf_token %}` tags need access to the top-level context, and they will not function properly if they are rendered in a component that is called with the `only` modifier. NOTE: `{% csrf_token %}` tags need access to the top-level context, and they will not function properly if they are rendered in a component that is called with the `only` modifier.

View file

@ -88,11 +88,11 @@ class RenderBenchmarks(SimpleTestCase):
template = Template( template = Template(
""" """
{% load component_tags %} {% load component_tags %}
{% component_block 'test_component' %} {% component 'test_component' %}
{% slot "header" %} {% slot "header" %}
{% component_block 'inner_component' variable='foo' %}{% endcomponent_block %} {% component 'inner_component' variable='foo' %}{% endcomponent %}
{% endslot %} {% endslot %}
{% endcomponent_block %} {% endcomponent %}
""" """
) )
@ -102,11 +102,11 @@ class RenderBenchmarks(SimpleTestCase):
template = Template( template = Template(
""" """
{% load component_tags %}{% component_dependencies %} {% load component_tags %}{% component_dependencies %}
{% component_block 'test_component' %} {% component 'test_component' %}
{% slot "header" %} {% slot "header" %}
{% component_block 'inner_component' variable='foo' %}{% endcomponent_block %} {% component 'inner_component' variable='foo' %}{% endcomponent %}
{% endslot %} {% endslot %}
{% endcomponent_block %} {% endcomponent %}
""" """
) )
# Sanity tests # Sanity tests

View file

@ -265,7 +265,7 @@ class BaseFillNode(Node):
raise TemplateSyntaxError( raise TemplateSyntaxError(
"{% fill ... %} block cannot be rendered directly. " "{% fill ... %} block cannot be rendered directly. "
"You are probably seeing this because you have used one outside " "You are probably seeing this because you have used one outside "
"a {% component_block %} context." "a {% component %} context."
) )
@ -286,7 +286,7 @@ class NamedFillNode(BaseFillNode):
class ImplicitFillNode(BaseFillNode): class ImplicitFillNode(BaseFillNode):
""" """
Instantiated when a `component_block` tag pair is passed template content that Instantiated when a `component` tag pair is passed template content that
excludes `fill` tags. Nodes of this type contribute their nodelists to slots marked excludes `fill` tags. Nodes of this type contribute their nodelists to slots marked
as 'default'. as 'default'.
""" """
@ -298,10 +298,10 @@ class ImplicitFillNode(BaseFillNode):
@register.tag("fill") @register.tag("fill")
def do_fill(parser, token): def do_fill(parser, token):
"""Block tag whose contents 'fill' (are inserted into) an identically named """Block tag whose contents 'fill' (are inserted into) an identically named
'slot'-block in the component template referred to by a parent component_block. 'slot'-block in the component template referred to by a parent component.
It exists to make component nesting easier. It exists to make component nesting easier.
This tag is available only within a {% component_block %}..{% endcomponent_block %} block. This tag is available only within a {% component %}..{% endcomponent %} block.
Runtime checks should prohibit other usages. Runtime checks should prohibit other usages.
""" """
bits = token.split_contents() bits = token.split_contents()
@ -406,14 +406,14 @@ class ComponentNode(Node):
return rendered_component return rendered_component
@register.tag(name="component_block") @register.tag(name="component")
def do_component_block(parser, token): def do_component(parser, token):
""" """
To give the component access to the template context: To give the component access to the template context:
{% component_block "name" positional_arg keyword_arg=value ... %} {% component "name" positional_arg keyword_arg=value ... %}
To render the component in an isolated context: To render the component in an isolated context:
{% component_block "name" positional_arg keyword_arg=value ... only %} {% component "name" positional_arg keyword_arg=value ... only %}
Positional and keyword arguments can be literals or template variables. Positional and keyword arguments can be literals or template variables.
The component name must be a single- or double-quotes string and must The component name must be a single- or double-quotes string and must
@ -423,8 +423,8 @@ def do_component_block(parser, token):
bits = token.split_contents() bits = token.split_contents()
bits, isolated_context = check_for_isolated_context_keyword(bits) bits, isolated_context = check_for_isolated_context_keyword(bits)
component_name, context_args, context_kwargs = parse_component_with_args(parser, bits, "component_block") component_name, context_args, context_kwargs = parse_component_with_args(parser, bits, "component")
body: NodeList = parser.parse(parse_until=["endcomponent_block"]) body: NodeList = parser.parse(parse_until=["endcomponent"])
parser.delete_first_token() parser.delete_first_token()
fill_nodes = () fill_nodes = ()
if block_has_content(body): if block_has_content(body):
@ -437,7 +437,7 @@ def do_component_block(parser, token):
break break
else: else:
raise TemplateSyntaxError( raise TemplateSyntaxError(
"Illegal content passed to 'component_block' tag pair. " "Illegal content passed to 'component' tag pair. "
"Possible causes: 1) Explicit 'fill' tags cannot occur alongside other " "Possible causes: 1) Explicit 'fill' tags cannot occur alongside other "
"tags except comment tags; 2) Default (default slot-targeting) content " "tags except comment tags; 2) Default (default slot-targeting) content "
"is mixed with explict 'fill' tags." "is mixed with explict 'fill' tags."

View file

@ -5,12 +5,12 @@
{% component_css_dependencies %} {% component_css_dependencies %}
</head> </head>
<body> <body>
{% component_block "calendar" date=date %}{% endcomponent_block %} {% component "calendar" date=date %}{% endcomponent %}
{% component_block "greeting" name='Joe' %} {% component "greeting" name='Joe' %}
{% fill "message" %} {% fill "message" %}
Howdy? Howdy?
{% endfill %} {% endfill %}
{% endcomponent_block %} {% endcomponent %}
{% component_js_dependencies %} {% component_js_dependencies %}
</body> </body>
</html> </html>

View file

@ -3,17 +3,17 @@
<div>Your to-dos:</div> <div>Your to-dos:</div>
<ul> <ul>
<li> <li>
{% component_block "todo" %} {% component "todo" %}
{% fill "todo_text" %} {% fill "todo_text" %}
Stop forgetting the milk! Stop forgetting the milk!
{% endfill %} {% endfill %}
{% endcomponent_block %} {% endcomponent %}
</li> </li>
<li> <li>
{% component_block "todo" %} {% component "todo" %}
{# As of v0.28, 'fill' tag optional for 1-slot filling if component template specifies a 'default' slot #} {# As of v0.28, 'fill' tag optional for 1-slot filling if component template specifies a 'default' slot #}
Wear all-white clothes to laser tag tournament. Wear all-white clothes to laser tag tournament.
{% endcomponent_block %} {% endcomponent %}
</li> </li>
</ul> </ul>
</div> </div>

View file

@ -200,7 +200,7 @@ Page lightly modified and partially extracted as a component #}
</div> </div>
</header> </header>
<div class="titlebar-container"><h1 class="title">Document and website structure</h1></div> <div class="titlebar-container"><h1 class="title">Document and website structure</h1></div>
{% component_block 'breadcrumb_component' items=5 %}{% endcomponent_block %} {% component 'breadcrumb_component' items=5 %}{% endcomponent %}
<div class="locale-container"> <div class="locale-container">
<form class="language-menu"><label for="select_language" class="visually-hidden">Select your preferred <form class="language-menu"><label for="select_language" class="visually-hidden">Select your preferred
language</label> <select id="select_language" name="language"> language</label> <select id="select_language" name="language">

View file

@ -2,11 +2,11 @@
<div> <div>
<h1>Parent content</h1> <h1>Parent content</h1>
{% component_block name="variable_display" shadowing_variable='override' new_variable='unique_val' %}{% endcomponent_block %} {% component name="variable_display" shadowing_variable='override' new_variable='unique_val' %}{% endcomponent %}
</div> </div>
<div> <div>
{% slot 'content' %} {% slot 'content' %}
<h2>Slot content</h2> <h2>Slot content</h2>
{% component_block name="variable_display" shadowing_variable='slot_default_override' new_variable='slot_default_unique' %}{% endcomponent_block %} {% component name="variable_display" shadowing_variable='slot_default_override' new_variable='slot_default_unique' %}{% endcomponent %}
{% endslot %} {% endslot %}
</div> </div>

View file

@ -2,11 +2,11 @@
<div> <div>
<h1>Parent content</h1> <h1>Parent content</h1>
{% component_block name="variable_display" shadowing_variable=inner_parent_value new_variable='unique_val' %}{% endcomponent_block %} {% component name="variable_display" shadowing_variable=inner_parent_value new_variable='unique_val' %}{% endcomponent %}
</div> </div>
<div> <div>
{% slot 'content' %} {% slot 'content' %}
<h2>Slot content</h2> <h2>Slot content</h2>
{% component_block name="variable_display" shadowing_variable='slot_default_override' new_variable=inner_parent_value %}{% endcomponent_block %} {% component name="variable_display" shadowing_variable='slot_default_override' new_variable=inner_parent_value %}{% endcomponent %}
{% endslot %} {% endslot %}
</div> </div>

View file

@ -1,11 +1,11 @@
{% load component_tags %} {% load component_tags %}
<div class="dashboard-component"> <div class="dashboard-component">
{% component_block "calendar" date="2020-06-06" %} {% component "calendar" date="2020-06-06" %}
{% fill "header" %} {# fills and slots with same name relate to diff. things. #} {% fill "header" %} {# fills and slots with same name relate to diff. things. #}
{% slot "header" %}Welcome to your dashboard!{% endslot %} {% slot "header" %}Welcome to your dashboard!{% endslot %}
{% endfill %} {% endfill %}
{% fill "body" %}Here are your to-do items for today:{% endfill %} {% fill "body" %}Here are your to-do items for today:{% endfill %}
{% endcomponent_block %} {% endcomponent %}
<ol> <ol>
{% for item in items %} {% for item in items %}
<li>{{ item }}</li> <li>{{ item }}</li>

View file

@ -395,15 +395,15 @@ class ComponentIsolationTests(SimpleTestCase):
template = Template( template = Template(
""" """
{% load component_tags %} {% load component_tags %}
{% component_block "test" %} {% component "test" %}
{% fill "header" %}Override header{% endfill %} {% fill "header" %}Override header{% endfill %}
{% endcomponent_block %} {% endcomponent %}
{% component_block "test" %} {% component "test" %}
{% fill "main" %}Override main{% endfill %} {% fill "main" %}Override main{% endfill %}
{% endcomponent_block %} {% endcomponent %}
{% component_block "test" %} {% component "test" %}
{% fill "footer" %}Override footer{% endfill %} {% fill "footer" %}Override footer{% endfill %}
{% endcomponent_block %} {% endcomponent %}
""" """
) )

View file

@ -83,7 +83,7 @@ def render_template_view(request):
template = Template( template = Template(
""" """
{% load component_tags %} {% load component_tags %}
{% component_block "testcomponent" variable="TEMPLATE" %}{% endcomponent_block %} {% component "testcomponent" variable="TEMPLATE" %}{% endcomponent %}
""" """
) )
return HttpResponse(template.render(Context({}))) return HttpResponse(template.render(Context({})))

View file

@ -78,7 +78,7 @@ class ContextTests(SimpleTestCase):
): ):
template = Template( template = Template(
"{% load component_tags %}{% component_dependencies %}" "{% load component_tags %}{% component_dependencies %}"
"{% component_block 'parent_component' %}{% endcomponent_block %}" "{% component 'parent_component' %}{% endcomponent %}"
) )
rendered = template.render(Context()) rendered = template.render(Context())
@ -95,40 +95,7 @@ class ContextTests(SimpleTestCase):
): ):
template = Template( template = Template(
"{% load component_tags %}{% component_dependencies %}" "{% load component_tags %}{% component_dependencies %}"
"{% component_block name='parent_component' %}{% endcomponent_block %}" "{% component name='parent_component' %}{% endcomponent %}"
)
rendered = template.render(Context())
self.assertIn("<h1>Uniquely named variable = unique_val</h1>", rendered, rendered)
self.assertIn(
"<h1>Uniquely named variable = slot_default_unique</h1>",
rendered,
rendered,
)
def test_nested_component_context_shadows_parent_with_unfilled_slots_and_component_block_tag(
self,
):
template = Template(
"{% load component_tags %}{% component_dependencies %}"
"{% component_block 'parent_component' %}{% endcomponent_block %}"
)
rendered = template.render(Context())
self.assertIn("<h1>Shadowing variable = override</h1>", rendered, rendered)
self.assertIn(
"<h1>Shadowing variable = slot_default_override</h1>",
rendered,
rendered,
)
self.assertNotIn("<h1>Shadowing variable = NOT SHADOWED</h1>", rendered, rendered)
def test_nested_component_instances_have_unique_context_with_unfilled_slots_and_component_block_tag(
self,
):
template = Template(
"{% load component_tags %}{% component_dependencies %}"
"{% component_block 'parent_component' %}{% endcomponent_block %}"
) )
rendered = template.render(Context()) rendered = template.render(Context())
@ -143,12 +110,12 @@ class ContextTests(SimpleTestCase):
template = Template( template = Template(
""" """
{% load component_tags %}{% component_dependencies %} {% load component_tags %}{% component_dependencies %}
{% component_block 'parent_component' %} {% component 'parent_component' %}
{% fill 'content' %} {% fill 'content' %}
{% component_block name='variable_display' shadowing_variable='shadow_from_slot' new_variable='unique_from_slot' %} {% component name='variable_display' shadowing_variable='shadow_from_slot' new_variable='unique_from_slot' %}
{% endcomponent_block %} {% endcomponent %}
{% endfill %} {% endfill %}
{% endcomponent_block %} {% endcomponent %}
""" # NOQA """ # NOQA
) )
rendered = template.render(Context()) rendered = template.render(Context())
@ -167,12 +134,12 @@ class ContextTests(SimpleTestCase):
template = Template( template = Template(
""" """
{% load component_tags %}{% component_dependencies %} {% load component_tags %}{% component_dependencies %}
{% component_block 'parent_component' %} {% component 'parent_component' %}
{% fill 'content' %} {% fill 'content' %}
{% component_block name='variable_display' shadowing_variable='shadow_from_slot' new_variable='unique_from_slot' %} {% component name='variable_display' shadowing_variable='shadow_from_slot' new_variable='unique_from_slot' %}
{% endcomponent_block %} {% endcomponent %}
{% endfill %} {% endfill %}
{% endcomponent_block %} {% endcomponent %}
""" # NOQA """ # NOQA
) )
rendered = template.render(Context()) rendered = template.render(Context())
@ -189,24 +156,7 @@ class ContextTests(SimpleTestCase):
): ):
template = Template( template = Template(
"{% load component_tags %}{% component_dependencies %}" "{% load component_tags %}{% component_dependencies %}"
"{% component_block name='parent_component' %}{% endcomponent_block %}" "{% component name='parent_component' %}{% endcomponent %}"
)
rendered = template.render(Context({"shadowing_variable": "NOT SHADOWED"}))
self.assertIn("<h1>Shadowing variable = override</h1>", rendered, rendered)
self.assertIn(
"<h1>Shadowing variable = slot_default_override</h1>",
rendered,
rendered,
)
self.assertNotIn("<h1>Shadowing variable = NOT SHADOWED</h1>", rendered, rendered)
def test_nested_component_context_shadows_outer_context_with_unfilled_slots_and_component_block_tag(
self,
):
template = Template(
"{% load component_tags %}{% component_dependencies %}"
"{% component_block 'parent_component' %}{% endcomponent_block %}"
) )
rendered = template.render(Context({"shadowing_variable": "NOT SHADOWED"})) rendered = template.render(Context({"shadowing_variable": "NOT SHADOWED"}))
@ -224,12 +174,12 @@ class ContextTests(SimpleTestCase):
template = Template( template = Template(
""" """
{% load component_tags %}{% component_dependencies %} {% load component_tags %}{% component_dependencies %}
{% component_block 'parent_component' %} {% component 'parent_component' %}
{% fill 'content' %} {% fill 'content' %}
{% component_block name='variable_display' shadowing_variable='shadow_from_slot' new_variable='unique_from_slot' %} {% component name='variable_display' shadowing_variable='shadow_from_slot' new_variable='unique_from_slot' %}
{% endcomponent_block %} {% endcomponent %}
{% endfill %} {% endfill %}
{% endcomponent_block %} {% endcomponent %}
""" # NOQA """ # NOQA
) )
rendered = template.render(Context({"shadowing_variable": "NOT SHADOWED"})) rendered = template.render(Context({"shadowing_variable": "NOT SHADOWED"}))
@ -247,8 +197,8 @@ class ParentArgsTests(SimpleTestCase):
def test_parent_args_can_be_drawn_from_context(self): def test_parent_args_can_be_drawn_from_context(self):
template = Template( template = Template(
"{% load component_tags %}{% component_dependencies %}" "{% load component_tags %}{% component_dependencies %}"
"{% component_block 'parent_with_args' parent_value=parent_value %}" "{% component 'parent_with_args' parent_value=parent_value %}"
"{% endcomponent_block %}" "{% endcomponent %}"
) )
rendered = template.render(Context({"parent_value": "passed_in"})) rendered = template.render(Context({"parent_value": "passed_in"}))
@ -259,7 +209,7 @@ class ParentArgsTests(SimpleTestCase):
def test_parent_args_available_outside_slots(self): def test_parent_args_available_outside_slots(self):
template = Template( template = Template(
"{% load component_tags %}{% component_dependencies %}" "{% load component_tags %}{% component_dependencies %}"
"{% component_block 'parent_with_args' parent_value='passed_in' %}{%endcomponent_block %}" "{% component 'parent_with_args' parent_value='passed_in' %}{%endcomponent %}"
) )
rendered = template.render(Context()) rendered = template.render(Context())
@ -271,12 +221,12 @@ class ParentArgsTests(SimpleTestCase):
template = Template( template = Template(
""" """
{% load component_tags %}{% component_dependencies %} {% load component_tags %}{% component_dependencies %}
{% component_block 'parent_with_args' parent_value='passed_in' %} {% component 'parent_with_args' parent_value='passed_in' %}
{% fill 'content' %} {% fill 'content' %}
{% component_block name='variable_display' shadowing_variable='value_from_slot' new_variable=inner_parent_value %} {% component name='variable_display' shadowing_variable='value_from_slot' new_variable=inner_parent_value %}
{% endcomponent_block %} {% endcomponent %}
{% endfill %} {% endfill %}
{% endcomponent_block %} {% endcomponent %}
""" # NOQA """ # NOQA
) )
rendered = template.render(Context()) rendered = template.render(Context())
@ -290,30 +240,26 @@ class ContextCalledOnceTests(SimpleTestCase):
def test_one_context_call_with_simple_component(self): def test_one_context_call_with_simple_component(self):
template = Template( template = Template(
"{% load component_tags %}{% component_dependencies %}" "{% load component_tags %}{% component_dependencies %}"
"{% component_block name='incrementer' %}{% endcomponent_block %}" "{% component name='incrementer' %}{% endcomponent %}"
) )
rendered = template.render(Context()).strip() rendered = template.render(Context()).strip()
self.assertEqual(rendered, '<p class="incrementer">value=1;calls=1</p>', rendered) self.assertEqual(rendered, '<p class="incrementer">value=1;calls=1</p>', rendered)
def test_one_context_call_with_simple_component_and_arg(self): def test_one_context_call_with_simple_component_and_arg(self):
template = Template( template = Template("{% load component_tags %}{% component name='incrementer' value='2' %}{% endcomponent %}")
"{% load component_tags %}{% component_block name='incrementer' value='2' %}{% endcomponent_block %}"
)
rendered = template.render(Context()).strip() rendered = template.render(Context()).strip()
self.assertEqual(rendered, '<p class="incrementer">value=3;calls=1</p>', rendered) self.assertEqual(rendered, '<p class="incrementer">value=3;calls=1</p>', rendered)
def test_one_context_call_with_component_block(self): def test_one_context_call_with_component(self):
template = Template("{% load component_tags %}" "{% component_block 'incrementer' %}{% endcomponent_block %}") template = Template("{% load component_tags %}" "{% component 'incrementer' %}{% endcomponent %}")
rendered = template.render(Context()).strip() rendered = template.render(Context()).strip()
self.assertEqual(rendered, '<p class="incrementer">value=1;calls=1</p>', rendered) self.assertEqual(rendered, '<p class="incrementer">value=1;calls=1</p>', rendered)
def test_one_context_call_with_component_block_and_arg(self): def test_one_context_call_with_component_and_arg(self):
template = Template( template = Template("{% load component_tags %}" "{% component 'incrementer' value='3' %}{% endcomponent %}")
"{% load component_tags %}" "{% component_block 'incrementer' value='3' %}{% endcomponent_block %}"
)
rendered = template.render(Context()).strip() rendered = template.render(Context()).strip()
self.assertEqual(rendered, '<p class="incrementer">value=4;calls=1</p>', rendered) self.assertEqual(rendered, '<p class="incrementer">value=4;calls=1</p>', rendered)
@ -321,8 +267,8 @@ class ContextCalledOnceTests(SimpleTestCase):
def test_one_context_call_with_slot(self): def test_one_context_call_with_slot(self):
template = Template( template = Template(
"{% load component_tags %}" "{% load component_tags %}"
"{% component_block 'incrementer' %}{% fill 'content' %}" "{% component 'incrementer' %}{% fill 'content' %}"
"<p>slot</p>{% endfill %}{% endcomponent_block %}" "<p>slot</p>{% endfill %}{% endcomponent %}"
) )
rendered = template.render(Context()).strip() rendered = template.render(Context()).strip()
@ -335,8 +281,8 @@ class ContextCalledOnceTests(SimpleTestCase):
def test_one_context_call_with_slot_and_arg(self): def test_one_context_call_with_slot_and_arg(self):
template = Template( template = Template(
"{% load component_tags %}" "{% load component_tags %}"
"{% component_block 'incrementer' value='3' %}{% fill 'content' %}" "{% component 'incrementer' value='3' %}{% fill 'content' %}"
"<p>slot</p>{% endfill %}{% endcomponent_block %}" "<p>slot</p>{% endfill %}{% endcomponent %}"
) )
rendered = template.render(Context()).strip() rendered = template.render(Context()).strip()
@ -351,7 +297,7 @@ class ComponentsCanAccessOuterContext(SimpleTestCase):
def test_simple_component_can_use_outer_context(self): def test_simple_component_can_use_outer_context(self):
template = Template( template = Template(
"{% load component_tags %}{% component_dependencies %}" "{% load component_tags %}{% component_dependencies %}"
"{% component_block 'simple_component' %}{% endcomponent_block %}" "{% component 'simple_component' %}{% endcomponent %}"
) )
rendered = template.render(Context({"variable": "outer_value"})).strip() rendered = template.render(Context({"variable": "outer_value"})).strip()
self.assertIn("outer_value", rendered, rendered) self.assertIn("outer_value", rendered, rendered)
@ -361,7 +307,7 @@ class IsolatedContextTests(SimpleTestCase):
def test_simple_component_can_pass_outer_context_in_args(self): def test_simple_component_can_pass_outer_context_in_args(self):
template = Template( template = Template(
"{% load component_tags %}{% component_dependencies %}" "{% load component_tags %}{% component_dependencies %}"
"{% component_block 'simple_component' variable only %}{% endcomponent_block %}" "{% component 'simple_component' variable only %}{% endcomponent %}"
) )
rendered = template.render(Context({"variable": "outer_value"})).strip() rendered = template.render(Context({"variable": "outer_value"})).strip()
self.assertIn("outer_value", rendered, rendered) self.assertIn("outer_value", rendered, rendered)
@ -369,7 +315,7 @@ class IsolatedContextTests(SimpleTestCase):
def test_simple_component_cannot_use_outer_context(self): def test_simple_component_cannot_use_outer_context(self):
template = Template( template = Template(
"{% load component_tags %}{% component_dependencies %}" "{% load component_tags %}{% component_dependencies %}"
"{% component_block 'simple_component' only %}{% endcomponent_block %}" "{% component 'simple_component' only %}{% endcomponent %}"
) )
rendered = template.render(Context({"variable": "outer_value"})).strip() rendered = template.render(Context({"variable": "outer_value"})).strip()
self.assertNotIn("outer_value", rendered, rendered) self.assertNotIn("outer_value", rendered, rendered)
@ -392,7 +338,7 @@ class IsolatedContextSettingTests(SimpleTestCase):
): ):
template = Template( template = Template(
"{% load component_tags %}{% component_dependencies %}" "{% load component_tags %}{% component_dependencies %}"
"{% component_block 'simple_component' variable %}{% endcomponent_block %}" "{% component 'simple_component' variable %}{% endcomponent %}"
) )
rendered = template.render(Context({"variable": "outer_value"})) rendered = template.render(Context({"variable": "outer_value"}))
self.assertIn("outer_value", rendered, rendered) self.assertIn("outer_value", rendered, rendered)
@ -402,29 +348,29 @@ class IsolatedContextSettingTests(SimpleTestCase):
): ):
template = Template( template = Template(
"{% load component_tags %}{% component_dependencies %}" "{% load component_tags %}{% component_dependencies %}"
"{% component_block 'simple_component' %}{% endcomponent_block %}" "{% component 'simple_component' %}{% endcomponent %}"
) )
rendered = template.render(Context({"variable": "outer_value"})) rendered = template.render(Context({"variable": "outer_value"}))
self.assertNotIn("outer_value", rendered, rendered) self.assertNotIn("outer_value", rendered, rendered)
def test_component_block_includes_variable_with_isolated_context_from_settings( def test_component_includes_variable_with_isolated_context_from_settings(
self, self,
): ):
template = Template( template = Template(
"{% load component_tags %}{% component_dependencies %}" "{% load component_tags %}{% component_dependencies %}"
"{% component_block 'simple_component' variable %}" "{% component 'simple_component' variable %}"
"{% endcomponent_block %}" "{% endcomponent %}"
) )
rendered = template.render(Context({"variable": "outer_value"})) rendered = template.render(Context({"variable": "outer_value"}))
self.assertIn("outer_value", rendered, rendered) self.assertIn("outer_value", rendered, rendered)
def test_component_block_excludes_variable_with_isolated_context_from_settings( def test_component_excludes_variable_with_isolated_context_from_settings(
self, self,
): ):
template = Template( template = Template(
"{% load component_tags %}{% component_dependencies %}" "{% load component_tags %}{% component_dependencies %}"
"{% component_block 'simple_component' %}" "{% component 'simple_component' %}"
"{% endcomponent_block %}" "{% endcomponent %}"
) )
rendered = template.render(Context({"variable": "outer_value"})) rendered = template.render(Context({"variable": "outer_value"}))
self.assertNotIn("outer_value", rendered, rendered) self.assertNotIn("outer_value", rendered, rendered)
@ -434,15 +380,7 @@ class OuterContextPropertyTests(SimpleTestCase):
def test_outer_context_property_with_component(self): def test_outer_context_property_with_component(self):
template = Template( template = Template(
"{% load component_tags %}{% component_dependencies %}" "{% load component_tags %}{% component_dependencies %}"
"{% component_block 'outer_context_component' only %}{% endcomponent_block %}" "{% component 'outer_context_component' only %}{% endcomponent %}"
)
rendered = template.render(Context({"variable": "outer_value"})).strip()
self.assertIn("outer_value", rendered, rendered)
def test_outer_context_property_with_component_block(self):
template = Template(
"{% load component_tags %}{% component_dependencies %}"
"{% component_block 'outer_context_component' only %}{% endcomponent_block %}"
) )
rendered = template.render(Context({"variable": "outer_value"})).strip() rendered = template.render(Context({"variable": "outer_value"})).strip()
self.assertIn("outer_value", rendered, rendered) self.assertIn("outer_value", rendered, rendered)

View file

@ -107,7 +107,7 @@ class ComponentMediaRenderingTests(SimpleTestCase):
template = Template( template = Template(
"{% load component_tags %}{% component_dependencies %}" "{% load component_tags %}{% component_dependencies %}"
"{% component_block 'test' variable='foo' %}{% endcomponent_block %}" "{% component 'test' variable='foo' %}{% endcomponent %}"
) )
rendered = create_and_process_template_response(template) rendered = create_and_process_template_response(template)
self.assertInHTML( self.assertInHTML(
@ -122,7 +122,7 @@ class ComponentMediaRenderingTests(SimpleTestCase):
template = Template( template = Template(
"{% load component_tags %}{% component_dependencies %}" "{% load component_tags %}{% component_dependencies %}"
"{% component_block 'test' variable='foo' %}{% endcomponent_block %}" "{% component 'test' variable='foo' %}{% endcomponent %}"
) )
rendered = create_and_process_template_response(template) rendered = create_and_process_template_response(template)
self.assertInHTML( self.assertInHTML(
@ -137,7 +137,7 @@ class ComponentMediaRenderingTests(SimpleTestCase):
template = Template( template = Template(
"{% load component_tags %}{% component_dependencies preload='test' %}" "{% load component_tags %}{% component_dependencies preload='test' %}"
"{% component_block 'test' variable='foo' %}{% endcomponent_block %}" "{% component 'test' variable='foo' %}{% endcomponent %}"
) )
rendered = create_and_process_template_response(template) rendered = create_and_process_template_response(template)
self.assertInHTML( self.assertInHTML(
@ -152,7 +152,7 @@ class ComponentMediaRenderingTests(SimpleTestCase):
template = Template( template = Template(
"{% load component_tags %}{% component_dependencies %}" "{% load component_tags %}{% component_dependencies %}"
"{% component_block 'test' variable='foo' %}{% endcomponent_block %}" "{% component 'test' variable='foo' %}{% endcomponent %}"
) )
rendered = create_and_process_template_response(template) rendered = create_and_process_template_response(template)
self.assertNotIn("_RENDERED", rendered) self.assertNotIn("_RENDERED", rendered)
@ -169,7 +169,7 @@ class ComponentMediaRenderingTests(SimpleTestCase):
template = Template( template = Template(
"{% load component_tags %}{% component_css_dependencies %}" "{% load component_tags %}{% component_css_dependencies %}"
"{% component_block 'test' variable='foo' %}{% endcomponent_block %}" "{% component 'test' variable='foo' %}{% endcomponent %}"
) )
rendered = create_and_process_template_response(template) rendered = create_and_process_template_response(template)
self.assertInHTML( self.assertInHTML(
@ -183,7 +183,7 @@ class ComponentMediaRenderingTests(SimpleTestCase):
template = Template( template = Template(
"{% load component_tags %}{% component_js_dependencies %}" "{% load component_tags %}{% component_js_dependencies %}"
"{% component_block 'test' variable='foo' %}{% endcomponent_block %}" "{% component 'test' variable='foo' %}{% endcomponent %}"
) )
rendered = create_and_process_template_response(template) rendered = create_and_process_template_response(template)
self.assertInHTML('<script src="script.js">', rendered, count=1) self.assertInHTML('<script src="script.js">', rendered, count=1)
@ -193,7 +193,7 @@ class ComponentMediaRenderingTests(SimpleTestCase):
): ):
component.registry.register(name="test", component=MultistyleComponent) component.registry.register(name="test", component=MultistyleComponent)
template = Template( template = Template(
"{% load component_tags %}{% component_dependencies %}{% component_block 'test' %}{% endcomponent_block %}" "{% load component_tags %}{% component_dependencies %}{% component 'test' %}{% endcomponent %}"
) )
rendered = create_and_process_template_response(template) rendered = create_and_process_template_response(template)
self.assertInHTML('<script src="script.js">', rendered, count=1) self.assertInHTML('<script src="script.js">', rendered, count=1)
@ -216,7 +216,7 @@ class ComponentMediaRenderingTests(SimpleTestCase):
template = Template( template = Template(
""" """
{% load component_tags %}{% component_js_dependencies %} {% load component_tags %}{% component_js_dependencies %}
{% component_block 'test' %}{% endcomponent_block %} {% component 'test' %}{% endcomponent %}
""" """
) )
rendered = create_and_process_template_response(template) rendered = create_and_process_template_response(template)
@ -240,7 +240,7 @@ class ComponentMediaRenderingTests(SimpleTestCase):
template = Template( template = Template(
""" """
{% load component_tags %}{% component_css_dependencies %} {% load component_tags %}{% component_css_dependencies %}
{% component_block 'test' %}{% endcomponent_block %} {% component 'test' %}{% endcomponent %}
""" """
) )
rendered = create_and_process_template_response(template) rendered = create_and_process_template_response(template)
@ -282,7 +282,7 @@ class ComponentMediaRenderingTests(SimpleTestCase):
template = Template( template = Template(
"{% load component_tags %}{% component_css_dependencies %}" "{% load component_tags %}{% component_css_dependencies %}"
"{% component_block 'test1' 'variable' %}{% endcomponent_block %}" "{% component 'test1' 'variable' %}{% endcomponent %}"
) )
rendered = create_and_process_template_response(template) rendered = create_and_process_template_response(template)
self.assertInHTML( self.assertInHTML(
@ -302,7 +302,7 @@ class ComponentMediaRenderingTests(SimpleTestCase):
template = Template( template = Template(
"{% load component_tags %}{% component_js_dependencies %}" "{% load component_tags %}{% component_js_dependencies %}"
"{% component_block 'test1' 'variable' %}{% endcomponent_block %}" "{% component 'test1' 'variable' %}{% endcomponent %}"
) )
rendered = create_and_process_template_response(template) rendered = create_and_process_template_response(template)
self.assertInHTML('<script src="script.js">', rendered, count=1) self.assertInHTML('<script src="script.js">', rendered, count=1)
@ -314,7 +314,7 @@ class ComponentMediaRenderingTests(SimpleTestCase):
template = Template( template = Template(
"{% load component_tags %}{% component_dependencies %}" "{% load component_tags %}{% component_dependencies %}"
"{% component_block 'test2' variable='variable' %}{% endcomponent_block %}" "{% component 'test2' variable='variable' %}{% endcomponent %}"
) )
rendered = create_and_process_template_response(template) rendered = create_and_process_template_response(template)
self.assertInHTML('<script src="script.js">', rendered, count=0) self.assertInHTML('<script src="script.js">', rendered, count=0)
@ -338,9 +338,9 @@ class ComponentMediaRenderingTests(SimpleTestCase):
template = Template( template = Template(
""" """
{% load component_tags %}{% component_dependencies %} {% load component_tags %}{% component_dependencies %}
{% component_block 'test1' variable='variable' %}{% endcomponent_block %} {% component 'test1' variable='variable' %}{% endcomponent %}
{% component_block 'test2' variable='variable' %}{% endcomponent_block %} {% component 'test2' variable='variable' %}{% endcomponent %}
{% component_block 'test1' variable='variable' %}{% endcomponent_block %} {% component 'test1' variable='variable' %}{% endcomponent %}
""" """
) )
rendered = create_and_process_template_response(template) rendered = create_and_process_template_response(template)
@ -365,9 +365,9 @@ class ComponentMediaRenderingTests(SimpleTestCase):
template = Template( template = Template(
""" """
{% load component_tags %}{% component_dependencies %} {% load component_tags %}{% component_dependencies %}
{% component_block 'test1' variable='variable' %}{% endcomponent_block %} {% component 'test1' variable='variable' %}{% endcomponent %}
{% component_block 'test2' variable='variable' %}{% endcomponent_block %} {% component 'test2' variable='variable' %}{% endcomponent %}
{% component_block 'test1' variable='variable' %}{% endcomponent_block %} {% component 'test1' variable='variable' %}{% endcomponent %}
""" """
) )
rendered = create_and_process_template_response(template) rendered = create_and_process_template_response(template)
@ -393,7 +393,7 @@ class ComponentMediaRenderingTests(SimpleTestCase):
"{% load component_tags %}" "{% load component_tags %}"
"{% component_js_dependencies %}" "{% component_js_dependencies %}"
"{% component_css_dependencies %}" "{% component_css_dependencies %}"
f"{{% component_block '{component_name}' variable='value' %}}{{% endcomponent_block %}}" f"{{% component '{component_name}' variable='value' %}}{{% endcomponent %}}"
) )
rendered = create_and_process_template_response(template) rendered = create_and_process_template_response(template)
self.assertHTMLEqual( self.assertHTMLEqual(

View file

@ -92,8 +92,8 @@ class ComponentTemplateTagTest(SimpleTestCase):
def inline_to_block(self, tag): def inline_to_block(self, tag):
return re.sub( return re.sub(
r"({% component_block (.*) %}{% endcomponent_block %})", r"({% component (.*) %}{% endcomponent %})",
r"{% component_block \2 %}{% endcomponent_block %}", r"{% component \2 %}{% endcomponent %}",
tag, tag,
) )
@ -102,7 +102,7 @@ class ComponentTemplateTagTest(SimpleTestCase):
simple_tag_tempate = """ simple_tag_tempate = """
{% load component_tags %} {% load component_tags %}
{% component_block name="test" variable="variable" %}{% endcomponent_block %} {% component name="test" variable="variable" %}{% endcomponent %}
""" """
block_tag_template = self.inline_to_block(simple_tag_tempate) block_tag_template = self.inline_to_block(simple_tag_tempate)
@ -116,7 +116,7 @@ class ComponentTemplateTagTest(SimpleTestCase):
simple_tag_tempate = """ simple_tag_tempate = """
{% load component_tags %} {% load component_tags %}
{% component_block name="test" variable="variable" %}{% endcomponent_block %} {% component name="test" variable="variable" %}{% endcomponent %}
""" """
block_tag_template = self.inline_to_block(simple_tag_tempate) block_tag_template = self.inline_to_block(simple_tag_tempate)
@ -130,7 +130,7 @@ class ComponentTemplateTagTest(SimpleTestCase):
simple_tag_tempate = """ simple_tag_tempate = """
{% load component_tags %} {% load component_tags %}
{% component_block "test" variable="variable" %}{% endcomponent_block %} {% component "test" variable="variable" %}{% endcomponent %}
""" """
block_tag_template = self.inline_to_block(simple_tag_tempate) block_tag_template = self.inline_to_block(simple_tag_tempate)
@ -144,7 +144,7 @@ class ComponentTemplateTagTest(SimpleTestCase):
simple_tag_tempate = """ simple_tag_tempate = """
{% load component_tags %} {% load component_tags %}
{% component_block name="test" variable="variable" variable2="hej" %}{% endcomponent_block %} {% component name="test" variable="variable" variable2="hej" %}{% endcomponent %}
""" """
block_tag_template = self.inline_to_block(simple_tag_tempate) block_tag_template = self.inline_to_block(simple_tag_tempate)
@ -159,7 +159,7 @@ class ComponentTemplateTagTest(SimpleTestCase):
simple_tag_tempate = """ simple_tag_tempate = """
{% load component_tags %} {% load component_tags %}
{% component_block 'test' variable="variable" %}{% endcomponent_block %} {% component 'test' variable="variable" %}{% endcomponent %}
""" """
block_tag_template = self.inline_to_block(simple_tag_tempate) block_tag_template = self.inline_to_block(simple_tag_tempate)
@ -174,7 +174,7 @@ class ComponentTemplateTagTest(SimpleTestCase):
simple_tag_tempate = """ simple_tag_tempate = """
{% load component_tags %} {% load component_tags %}
{% with component_name="test" %} {% with component_name="test" %}
{% component_block component_name variable="variable" %}{% endcomponent_block %} {% component component_name variable="variable" %}{% endcomponent %}
{% endwith %} {% endwith %}
""" """
block_tag_template = self.inline_to_block(simple_tag_tempate) block_tag_template = self.inline_to_block(simple_tag_tempate)
@ -190,7 +190,7 @@ class ComponentTemplateTagTest(SimpleTestCase):
simple_tag_tempate = """ simple_tag_tempate = """
{% load component_tags %} {% load component_tags %}
{% with component_name="BLAHONGA" %} {% with component_name="BLAHONGA" %}
{% component_block component_name variable="variable" %}{% endcomponent_block %} {% component component_name variable="variable" %}{% endcomponent %}
{% endwith %} {% endwith %}
""" """
block_tag_template = self.inline_to_block(simple_tag_tempate) block_tag_template = self.inline_to_block(simple_tag_tempate)
@ -214,14 +214,14 @@ class ComponentSlottedTemplateTagTest(SimpleTestCase):
template = Template( template = Template(
""" """
{% load component_tags %} {% load component_tags %}
{% component_block "test1" %} {% component "test1" %}
{% fill "header" %} {% fill "header" %}
Custom header Custom header
{% endfill %} {% endfill %}
{% fill "main" %} {% fill "main" %}
{% component_block "test2" variable="variable" %}{% endcomponent_block %} {% component "test2" variable="variable" %}{% endcomponent %}
{% endfill %} {% endfill %}
{% endcomponent_block %} {% endcomponent %}
""" """
) )
rendered = template.render(Context({})) rendered = template.render(Context({}))
@ -244,14 +244,14 @@ class ComponentSlottedTemplateTagTest(SimpleTestCase):
""" """
{% load component_tags %} {% load component_tags %}
{% with my_first_variable="test123" %} {% with my_first_variable="test123" %}
{% component_block "test1" variable="test456" %} {% component "test1" variable="test456" %}
{% fill "main" %} {% fill "main" %}
{{ my_first_variable }} - {{ variable }} {{ my_first_variable }} - {{ variable }}
{% endfill %} {% endfill %}
{% fill "footer" %} {% fill "footer" %}
{{ my_second_variable }} {{ my_second_variable }}
{% endfill %} {% endfill %}
{% endcomponent_block %} {% endcomponent %}
{% endwith %} {% endwith %}
""" """
) )
@ -271,7 +271,7 @@ class ComponentSlottedTemplateTagTest(SimpleTestCase):
def test_slotted_template_no_slots_filled(self): def test_slotted_template_no_slots_filled(self):
component.registry.register(name="test", component=SlottedComponent) component.registry.register(name="test", component=SlottedComponent)
template = Template('{% load component_tags %}{% component_block "test" %}{% endcomponent_block %}') template = Template('{% load component_tags %}{% component "test" %}{% endcomponent %}')
rendered = template.render(Context({})) rendered = template.render(Context({}))
self.assertHTMLEqual( self.assertHTMLEqual(
@ -290,7 +290,7 @@ class ComponentSlottedTemplateTagTest(SimpleTestCase):
template = Template( template = Template(
""" """
{% load component_tags %} {% load component_tags %}
{% component_block "test" %}{% endcomponent_block %} {% component "test" %}{% endcomponent %}
""" """
) )
rendered = template.render(Context({})) rendered = template.render(Context({}))
@ -302,7 +302,7 @@ class ComponentSlottedTemplateTagTest(SimpleTestCase):
template = Template( template = Template(
""" """
{% load component_tags %} {% load component_tags %}
{% component_block 'test' %}{% endcomponent_block %} {% component 'test' %}{% endcomponent %}
""" """
) )
rendered = template.render(Context({})) rendered = template.render(Context({}))
@ -315,9 +315,9 @@ class ComponentSlottedTemplateTagTest(SimpleTestCase):
""" """
{% load component_tags %} {% load component_tags %}
{% with slotname="header" %} {% with slotname="header" %}
{% component_block 'test' %} {% component 'test' %}
{% fill slotname %}Hi there!{% endfill %} {% fill slotname %}Hi there!{% endfill %}
{% endcomponent_block %} {% endcomponent %}
{% endwith %} {% endwith %}
""" """
) )
@ -339,8 +339,8 @@ class ComponentSlottedTemplateTagTest(SimpleTestCase):
template = Template( template = Template(
""" """
{% load component_tags %} {% load component_tags %}
{% component_block 'test' %} {% component 'test' %}
{% endcomponent_block %} {% endcomponent %}
""" """
) )
with self.assertRaises(TemplateSyntaxError): with self.assertRaises(TemplateSyntaxError):
@ -352,9 +352,9 @@ class ComponentSlottedTemplateTagTest(SimpleTestCase):
template = Template( template = Template(
""" """
{% load component_tags %} {% load component_tags %}
{% component_block 'test_comp' %} {% component 'test_comp' %}
<p>This fills the 'main' slot.</p> <p>This fills the 'main' slot.</p>
{% endcomponent_block %} {% endcomponent %}
""" """
) )
@ -372,9 +372,9 @@ class ComponentSlottedTemplateTagTest(SimpleTestCase):
template = Template( template = Template(
""" """
{% load component_tags %} {% load component_tags %}
{% component_block 'test_comp' %} {% component 'test_comp' %}
{% fill "main" %}<p>This fills the 'main' slot.</p>{% endfill %} {% fill "main" %}<p>This fills the 'main' slot.</p>{% endfill %}
{% endcomponent_block %} {% endcomponent %}
""" """
) )
expected = """ expected = """
@ -390,14 +390,14 @@ class ComponentSlottedTemplateTagTest(SimpleTestCase):
template = Template( template = Template(
""" """
{% load component_tags %} {% load component_tags %}
{% component_block 'test_comp' %} {% component 'test_comp' %}
{% endcomponent_block %} {% endcomponent %}
""" """
) )
with self.assertRaises(TemplateSyntaxError): with self.assertRaises(TemplateSyntaxError):
template.render(Context({})) template.render(Context({}))
def test_fill_tag_can_occur_within_component_block_nested_in_implicit_fill( def test_fill_tag_can_occur_within_component_nested_in_implicit_fill(
self, self,
): ):
component.registry.register("test_comp", ComponentWithDefaultSlot) component.registry.register("test_comp", ComponentWithDefaultSlot)
@ -406,13 +406,13 @@ class ComponentSlottedTemplateTagTest(SimpleTestCase):
template = Template( template = Template(
""" """
{% load component_tags %} {% load component_tags %}
{% component_block 'test_comp' %} {% component 'test_comp' %}
{% component_block "slotted" %} {% component "slotted" %}
{% fill "header" %}This Is Allowed{% endfill %} {% fill "header" %}This Is Allowed{% endfill %}
{% fill "main" %}{% endfill %} {% fill "main" %}{% endfill %}
{% fill "footer" %}{% endfill %} {% fill "footer" %}{% endfill %}
{% endcomponent_block %} {% endcomponent %}
{% endcomponent_block %} {% endcomponent %}
""" """
) )
expected = """ expected = """
@ -436,10 +436,10 @@ class ComponentSlottedTemplateTagTest(SimpleTestCase):
Template( Template(
""" """
{% load component_tags %} {% load component_tags %}
{% component_block 'test_comp' %} {% component 'test_comp' %}
{% fill "main" %}Main content{% endfill %} {% fill "main" %}Main content{% endfill %}
<p>And add this too!</p> <p>And add this too!</p>
{% endcomponent_block %} {% endcomponent %}
""" """
) )
@ -448,13 +448,13 @@ class ComponentSlottedTemplateTagTest(SimpleTestCase):
Template( Template(
""" """
{% load component_tags %} {% load component_tags %}
{% component_block 'test_comp' %} {% component 'test_comp' %}
<p>Main Content</p> <p>Main Content</p>
{% comment %} {% comment %}
This won't show up in the rendered HTML This won't show up in the rendered HTML
{% endcomment %} {% endcomment %}
{# Nor will this #} {# Nor will this #}
{% endcomponent_block %} {% endcomponent %}
""" """
) )
self.assertTrue(True) self.assertTrue(True)
@ -464,10 +464,10 @@ class ComponentSlottedTemplateTagTest(SimpleTestCase):
template = Template( template = Template(
""" """
{% load component_tags %} {% load component_tags %}
{% component_block 'test_comp' %} {% component 'test_comp' %}
<p>This shouldn't work because the included component doesn't mark <p>This shouldn't work because the included component doesn't mark
any of its slots as 'default'</p> any of its slots as 'default'</p>
{% endcomponent_block %} {% endcomponent %}
""" """
) )
with self.assertRaises(TemplateSyntaxError): with self.assertRaises(TemplateSyntaxError):
@ -496,14 +496,14 @@ class ComponentSlottedTemplateTagTest(SimpleTestCase):
template = Template( template = Template(
""" """
{% load component_tags %} {% load component_tags %}
{% component_block "test1" %} {% component "test1" %}
{% fill "haeder" %} {% fill "haeder" %}
Custom header Custom header
{% endfill %} {% endfill %}
{% fill "main" %} {% fill "main" %}
main content main content
{% endfill %} {% endfill %}
{% endcomponent_block %} {% endcomponent %}
""" """
) )
with self.assertRaises(TemplateSyntaxError): with self.assertRaises(TemplateSyntaxError):
@ -532,7 +532,7 @@ class SlottedTemplateRegressionTests(SimpleTestCase):
template = Template( template = Template(
""" """
{% load component_tags %} {% load component_tags %}
{% component_block 'test' %}{% endcomponent_block %} {% component 'test' %}{% endcomponent %}
""" """
) )
rendered = template.render(Context({})) rendered = template.render(Context({}))
@ -548,14 +548,14 @@ class SlottedTemplateRegressionTests(SimpleTestCase):
""", """,
) )
def test_component_block_accepts_provided_and_default_parameters(self): def test_component_accepts_provided_and_default_parameters(self):
component.registry.register(name="test", component=ComponentWithProvidedAndDefaultParameters) component.registry.register(name="test", component=ComponentWithProvidedAndDefaultParameters)
template = Template( template = Template(
""" """
{% load component_tags %} {% load component_tags %}
{% component_block "test" variable="provided value" %} {% component "test" variable="provided value" %}
{% endcomponent_block %} {% endcomponent %}
""" """
) )
rendered = template.render(Context({})) rendered = template.render(Context({}))
@ -576,10 +576,8 @@ class MultiComponentTests(SimpleTestCase):
def make_template(self, first_component_slot="", second_component_slot=""): def make_template(self, first_component_slot="", second_component_slot=""):
return Template( return Template(
"{% load component_tags %}" "{% load component_tags %}"
"{% component_block 'first_component' %}" + first_component_slot + "{% endcomponent_block %}" "{% component 'first_component' %}" + first_component_slot + "{% endcomponent %}"
"{% component_block 'second_component' variable='xyz' %}" "{% component 'second_component' variable='xyz' %}" + second_component_slot + "{% endcomponent %}"
+ second_component_slot
+ "{% endcomponent_block %}"
) )
def expected_result(self, first_component_slot="", second_component_slot=""): def expected_result(self, first_component_slot="", second_component_slot=""):
@ -663,7 +661,7 @@ class TemplateInstrumentationTest(SimpleTestCase):
template = Template( template = Template(
""" """
{% load component_tags %} {% load component_tags %}
{% component_block 'test_component' %}{% endcomponent_block %} {% component 'test_component' %}{% endcomponent %}
""", """,
name="root", name="root",
) )
@ -674,11 +672,11 @@ class TemplateInstrumentationTest(SimpleTestCase):
template = Template( template = Template(
""" """
{% load component_tags %} {% load component_tags %}
{% component_block 'test_component' %} {% component 'test_component' %}
{% fill "header" %} {% fill "header" %}
{% component_block 'inner_component' variable='foo' %}{% endcomponent_block %} {% component 'inner_component' variable='foo' %}{% endcomponent %}
{% endfill %} {% endfill %}
{% endcomponent_block %} {% endcomponent %}
""", """,
name="root", name="root",
) )
@ -706,7 +704,7 @@ class NestedSlotTests(SimpleTestCase):
template = Template( template = Template(
""" """
{% load component_tags %} {% load component_tags %}
{% component_block 'test' %}{% endcomponent_block %} {% component 'test' %}{% endcomponent %}
""" """
) )
rendered = template.render(Context({})) rendered = template.render(Context({}))
@ -716,7 +714,7 @@ class NestedSlotTests(SimpleTestCase):
template = Template( template = Template(
""" """
{% load component_tags %} {% load component_tags %}
{% component_block 'test' %}{% fill 'inner' %}Override{% endfill %}{% endcomponent_block %} {% component 'test' %}{% fill 'inner' %}Override{% endfill %}{% endcomponent %}
""" """
) )
rendered = template.render(Context({})) rendered = template.render(Context({}))
@ -726,7 +724,7 @@ class NestedSlotTests(SimpleTestCase):
template = Template( template = Template(
""" """
{% load component_tags %} {% load component_tags %}
{% component_block 'test' %}{% fill 'outer' %}<p>Override</p>{% endfill %}{% endcomponent_block %} {% component 'test' %}{% fill 'outer' %}<p>Override</p>{% endfill %}{% endcomponent %}
""" """
) )
rendered = template.render(Context({})) rendered = template.render(Context({}))
@ -736,10 +734,10 @@ class NestedSlotTests(SimpleTestCase):
template = Template( template = Template(
""" """
{% load component_tags %} {% load component_tags %}
{% component_block 'test' %} {% component 'test' %}
{% fill 'outer' %}<p>Override</p>{% endfill %} {% fill 'outer' %}<p>Override</p>{% endfill %}
{% fill 'inner' %}<p>Will not appear</p>{% endfill %} {% fill 'inner' %}<p>Will not appear</p>{% endfill %}
{% endcomponent_block %} {% endcomponent %}
""" """
) )
rendered = template.render(Context({})) rendered = template.render(Context({}))
@ -768,10 +766,10 @@ class ConditionalSlotTests(SimpleTestCase):
template = Template( template = Template(
""" """
{% load component_tags %} {% load component_tags %}
{% component_block 'test' %} {% component 'test' %}
{% fill 'a' %}Override A{% endfill %} {% fill 'a' %}Override A{% endfill %}
{% fill 'b' %}Override B{% endfill %} {% fill 'b' %}Override B{% endfill %}
{% endcomponent_block %} {% endcomponent %}
""" """
) )
rendered = template.render(Context({})) rendered = template.render(Context({}))
@ -781,8 +779,8 @@ class ConditionalSlotTests(SimpleTestCase):
template = Template( template = Template(
""" """
{% load component_tags %} {% load component_tags %}
{% component_block 'test' branch='a' %}{% endcomponent_block %} {% component 'test' branch='a' %}{% endcomponent %}
{% component_block 'test' branch='b' %}{% endcomponent_block %} {% component 'test' branch='b' %}{% endcomponent %}
""" """
) )
rendered = template.render(Context({})) rendered = template.render(Context({}))
@ -792,12 +790,12 @@ class ConditionalSlotTests(SimpleTestCase):
template = Template( template = Template(
""" """
{% load component_tags %} {% load component_tags %}
{% component_block 'test' branch='a' %} {% component 'test' branch='a' %}
{% fill 'b' %}Override B{% endfill %} {% fill 'b' %}Override B{% endfill %}
{% endcomponent_block %} {% endcomponent %}
{% component_block 'test' branch='b' %} {% component 'test' branch='b' %}
{% fill 'b' %}Override B{% endfill %} {% fill 'b' %}Override B{% endfill %}
{% endcomponent_block %} {% endcomponent %}
""" """
) )
rendered = template.render(Context({})) rendered = template.render(Context({}))
@ -807,14 +805,14 @@ class ConditionalSlotTests(SimpleTestCase):
template = Template( template = Template(
""" """
{% load component_tags %} {% load component_tags %}
{% component_block 'test' branch='a' %} {% component 'test' branch='a' %}
{% fill 'a' %}Override A{% endfill %} {% fill 'a' %}Override A{% endfill %}
{% fill 'b' %}Override B{% endfill %} {% fill 'b' %}Override B{% endfill %}
{% endcomponent_block %} {% endcomponent %}
{% component_block 'test' branch='b' %} {% component 'test' branch='b' %}
{% fill 'a' %}Override A{% endfill %} {% fill 'a' %}Override A{% endfill %}
{% fill 'b' %}Override B{% endfill %} {% fill 'b' %}Override B{% endfill %}
{% endcomponent_block %} {% endcomponent %}
""" """
) )
rendered = template.render(Context({})) rendered = template.render(Context({}))
@ -837,11 +835,11 @@ class SlotSuperTests(SimpleTestCase):
template = Template( template = Template(
""" """
{% load component_tags %} {% load component_tags %}
{% component_block "test" %} {% component "test" %}
{% fill "header" as "header" %}Before: {{ header.default }}{% endfill %} {% fill "header" as "header" %}Before: {{ header.default }}{% endfill %}
{% fill "main" as "main" %}{{ main.default }}{% endfill %} {% fill "main" as "main" %}{{ main.default }}{% endfill %}
{% fill "footer" as "footer" %}{{ footer.default }}, after{% endfill %} {% fill "footer" as "footer" %}{{ footer.default }}, after{% endfill %}
{% endcomponent_block %} {% endcomponent %}
""" """
) )
rendered = template.render(Context({})) rendered = template.render(Context({}))
@ -861,9 +859,9 @@ class SlotSuperTests(SimpleTestCase):
template = Template( template = Template(
""" """
{% load component_tags %} {% load component_tags %}
{% component_block "test" %} {% component "test" %}
{% fill "header" as "header" %}First: {{ header.default }}; Second: {{ header.default }}{% endfill %} {% fill "header" as "header" %}First: {{ header.default }}; Second: {{ header.default }}{% endfill %}
{% endcomponent_block %} {% endcomponent %}
""" """
) )
rendered = template.render(Context({})) rendered = template.render(Context({}))
@ -883,7 +881,7 @@ class SlotSuperTests(SimpleTestCase):
template = Template( template = Template(
""" """
{% load component_tags %} {% load component_tags %}
{% component_block "test" %} {% component "test" %}
{% fill "header" as "header" %} {% fill "header" as "header" %}
{% for i in range %} {% for i in range %}
{% if forloop.first %}First {{ header.default }} {% if forloop.first %}First {{ header.default }}
@ -891,7 +889,7 @@ class SlotSuperTests(SimpleTestCase):
{% endif %} {% endif %}
{% endfor %} {% endfor %}
{% endfill %} {% endfill %}
{% endcomponent_block %} {% endcomponent %}
""" """
) )
rendered = template.render(Context({"range": range(3)})) rendered = template.render(Context({"range": range(3)}))
@ -928,9 +926,9 @@ class TemplateSyntaxErrorTests(SimpleTestCase):
Template( Template(
""" """
{% load component_tags %} {% load component_tags %}
{% component_block "test" %} {% component "test" %}
{{ anything }} {{ anything }}
{% endcomponent_block %} {% endcomponent %}
""" """
) )
@ -941,9 +939,9 @@ class TemplateSyntaxErrorTests(SimpleTestCase):
Template( Template(
""" """
{% load component_tags %} {% load component_tags %}
{% component_block "test" %} {% component "test" %}
Text Text
{% endcomponent_block %} {% endcomponent %}
""" """
) )
@ -952,20 +950,20 @@ class TemplateSyntaxErrorTests(SimpleTestCase):
Template( Template(
""" """
{% load component_tags %} {% load component_tags %}
{% component_block "test" %} {% component "test" %}
{% if True %} {% if True %}
{% fill "header" %}{% endfill %} {% fill "header" %}{% endfill %}
{% endif %} {% endif %}
{% endcomponent_block %} {% endcomponent %}
""" """
) )
def test_unclosed_component_block_is_error(self): def test_unclosed_component_is_error(self):
with self.assertRaises(TemplateSyntaxError): with self.assertRaises(TemplateSyntaxError):
Template( Template(
""" """
{% load component_tags %} {% load component_tags %}
{% component_block "test" %} {% component "test" %}
{% fill "header" %}{% endfill %} {% fill "header" %}{% endfill %}
""" """
) )
@ -984,11 +982,11 @@ class TemplateSyntaxErrorTests(SimpleTestCase):
Template( Template(
""" """
{% load component_tags %} {% load component_tags %}
{% component_block "broken_component" %} {% component "broken_component" %}
{% fill "header" %}Custom header {% endfill %} {% fill "header" %}Custom header {% endfill %}
{% fill "main" %}Custom main{% endfill %} {% fill "main" %}Custom main{% endfill %}
{% fill "footer" %}Custom footer{% endfill %} {% fill "footer" %}Custom footer{% endfill %}
{% endcomponent_block %} {% endcomponent %}
""" """
).render(Context({})) ).render(Context({}))
@ -997,10 +995,10 @@ class TemplateSyntaxErrorTests(SimpleTestCase):
Template( Template(
""" """
{% load component_tags %} {% load component_tags %}
{% component_block "broken_component" %} {% component "broken_component" %}
{% fill "header" %}Custom header {% endfill %} {% fill "header" %}Custom header {% endfill %}
{% fill "header" %}Other header{% endfill %} {% fill "header" %}Other header{% endfill %}
{% endcomponent_block %} {% endcomponent %}
""" """
).render(Context({})) ).render(Context({}))
@ -1009,8 +1007,8 @@ class TemplateSyntaxErrorTests(SimpleTestCase):
Template( Template(
""" """
{% load component_tags %} {% load component_tags %}
{% component_block "nonunique_slot_component" %} {% component "nonunique_slot_component" %}
{% endcomponent_block %} {% endcomponent %}
""" """
).render(Context({})) ).render(Context({}))
@ -1031,7 +1029,7 @@ class ComponentNestingTests(SimpleTestCase):
template = Template( template = Template(
""" """
{% load component_tags %} {% load component_tags %}
{% component_block "dashboard" %}{% endcomponent_block %} {% component "dashboard" %}{% endcomponent %}
""" """
) )
rendered = template.render(Context({"items": [1, 2, 3]})) rendered = template.render(Context({"items": [1, 2, 3]}))
@ -1058,9 +1056,9 @@ class ComponentNestingTests(SimpleTestCase):
template = Template( template = Template(
""" """
{% load component_tags %} {% load component_tags %}
{% component_block "dashboard" %} {% component "dashboard" %}
{% fill "header" as "h" %} Hello! {{ h.default }} {% endfill %} {% fill "header" as "h" %} Hello! {{ h.default }} {% endfill %}
{% endcomponent_block %} {% endcomponent %}
""" """
) )
rendered = template.render(Context({"items": [1, 2]})) rendered = template.render(Context({"items": [1, 2]}))
@ -1111,7 +1109,7 @@ class ConditionalIfFilledSlotsTests(SimpleTestCase):
def test_simple_component_with_conditional_slot(self): def test_simple_component_with_conditional_slot(self):
template = """ template = """
{% load component_tags %} {% load component_tags %}
{% component_block "conditional_slots" %}{% endcomponent_block %} {% component "conditional_slots" %}{% endcomponent %}
""" """
expected = """ expected = """
<div class="frontmatter-component"> <div class="frontmatter-component">
@ -1123,12 +1121,12 @@ class ConditionalIfFilledSlotsTests(SimpleTestCase):
rendered = Template(template).render(Context({})) rendered = Template(template).render(Context({}))
self.assertHTMLEqual(rendered, expected) self.assertHTMLEqual(rendered, expected)
def test_component_block_with_filled_conditional_slot(self): def test_component_with_filled_conditional_slot(self):
template = """ template = """
{% load component_tags %} {% load component_tags %}
{% component_block "conditional_slots" %} {% component "conditional_slots" %}
{% fill "subtitle" %} My subtitle {% endfill %} {% fill "subtitle" %} My subtitle {% endfill %}
{% endcomponent_block %} {% endcomponent %}
""" """
expected = """ expected = """
<div class="frontmatter-component"> <div class="frontmatter-component">
@ -1146,9 +1144,9 @@ class ConditionalIfFilledSlotsTests(SimpleTestCase):
def test_elif_of_complex_conditional_slots(self): def test_elif_of_complex_conditional_slots(self):
template = """ template = """
{% load component_tags %} {% load component_tags %}
{% component_block "complex_conditional_slots" %} {% component "complex_conditional_slots" %}
{% fill "alt_subtitle" %} A different subtitle {% endfill %} {% fill "alt_subtitle" %} A different subtitle {% endfill %}
{% endcomponent_block %} {% endcomponent %}
""" """
expected = """ expected = """
<div class="frontmatter-component"> <div class="frontmatter-component">
@ -1166,8 +1164,8 @@ class ConditionalIfFilledSlotsTests(SimpleTestCase):
def test_else_of_complex_conditional_slots(self): def test_else_of_complex_conditional_slots(self):
template = """ template = """
{% load component_tags %} {% load component_tags %}
{% component_block "complex_conditional_slots" %} {% component "complex_conditional_slots" %}
{% endcomponent_block %} {% endcomponent %}
""" """
expected = """ expected = """
<div class="frontmatter-component"> <div class="frontmatter-component">
@ -1180,12 +1178,12 @@ class ConditionalIfFilledSlotsTests(SimpleTestCase):
rendered = Template(template).render(Context({})) rendered = Template(template).render(Context({}))
self.assertHTMLEqual(rendered, expected) self.assertHTMLEqual(rendered, expected)
def test_component_block_with_negated_conditional_slot(self): def test_component_with_negated_conditional_slot(self):
template = """ template = """
{% load component_tags %} {% load component_tags %}
{% component_block "negated_conditional_slot" %} {% component "negated_conditional_slot" %}
{# Whoops! Forgot to fill a slot! #} {# Whoops! Forgot to fill a slot! #}
{% endcomponent_block %} {% endcomponent %}
""" """
expected = """ expected = """
<div class="frontmatter-component"> <div class="frontmatter-component">
@ -1217,13 +1215,13 @@ class RegressionTests(SimpleTestCase):
{% extends "extendable_template_with_blocks.html" %} {% extends "extendable_template_with_blocks.html" %}
{% load component_tags %} {% load component_tags %}
{% block body %} {% block body %}
{% component_block "slotted_component" %} {% component "slotted_component" %}
{% fill "header" %}{% endfill %} {% fill "header" %}{% endfill %}
{% fill "main" %} {% fill "main" %}
TEST TEST
{% endfill %} {% endfill %}
{% fill "footer" %}{% endfill %} {% fill "footer" %}{% endfill %}
{% endcomponent_block %} {% endcomponent %}
{% endblock %} {% endblock %}
""" """
rendered = Template(template).render(Context()) rendered = Template(template).render(Context())
@ -1266,11 +1264,11 @@ class IterationFillTest(SimpleTestCase):
template = Template( template = Template(
""" """
{% load component_tags %} {% load component_tags %}
{% component_block "slot_in_a_loop" objects=objects %} {% component "slot_in_a_loop" objects=objects %}
{% fill "slot_inner" %} {% fill "slot_inner" %}
{{ object }} {{ object }}
{% endfill %} {% endfill %}
{% endcomponent_block %} {% endcomponent %}
""" """
) )
objects = ["OBJECT1", "OBJECT2"] objects = ["OBJECT1", "OBJECT2"]
@ -1290,12 +1288,12 @@ class IterationFillTest(SimpleTestCase):
template = Template( template = Template(
""" """
{% load component_tags %} {% load component_tags %}
{% component_block "slot_in_a_loop" objects=objects %} {% component "slot_in_a_loop" objects=objects %}
{% fill "slot_inner" %} {% fill "slot_inner" %}
{{ outer_scope_variable }} {{ outer_scope_variable }}
{{ object }} {{ object }}
{% endfill %} {% endfill %}
{% endcomponent_block %} {% endcomponent %}
""" """
) )
objects = ["OBJECT1", "OBJECT2"] objects = ["OBJECT1", "OBJECT2"]
@ -1329,15 +1327,15 @@ class IterationFillTest(SimpleTestCase):
template = Template( template = Template(
""" """
{% load component_tags %} {% load component_tags %}
{% component_block "slot_in_a_loop" objects=objects %} {% component "slot_in_a_loop" objects=objects %}
{% fill "slot_inner" %} {% fill "slot_inner" %}
{% component_block "slot_in_a_loop" objects=object.inner %} {% component "slot_in_a_loop" objects=object.inner %}
{% fill "slot_inner" %} {% fill "slot_inner" %}
{{ object }} {{ object }}
{% endfill %} {% endfill %}
{% endcomponent_block %} {% endcomponent %}
{% endfill %} {% endfill %}
{% endcomponent_block %} {% endcomponent %}
""" """
) )
rendered = template.render(Context({"objects": objects})) rendered = template.render(Context({"objects": objects}))
@ -1363,17 +1361,17 @@ class IterationFillTest(SimpleTestCase):
template = Template( template = Template(
""" """
{% load component_tags %} {% load component_tags %}
{% component_block "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 }}
{% component_block "slot_in_a_loop" objects=object.inner %} {% component "slot_in_a_loop" objects=object.inner %}
{% fill "slot_inner" %} {% fill "slot_inner" %}
{{ outer_scope_variable_2 }} {{ outer_scope_variable_2 }}
{{ object }} {{ object }}
{% endfill %} {% endfill %}
{% endcomponent_block %} {% endcomponent %}
{% endfill %} {% endfill %}
{% endcomponent_block %} {% endcomponent %}
""" """
) )
rendered = template.render( rendered = template.render(
@ -1413,15 +1411,15 @@ class IterationFillTest(SimpleTestCase):
template = Template( template = Template(
""" """
{% load component_tags %} {% load component_tags %}
{% component_block "slot_in_a_loop" objects=objects %} {% component "slot_in_a_loop" objects=objects %}
{% fill "slot_inner" %} {% fill "slot_inner" %}
{% component_block "slot_in_a_loop" objects=object.inner %} {% component "slot_in_a_loop" objects=object.inner %}
{% fill "slot_inner" as "super_slot_inner" %} {% fill "slot_inner" as "super_slot_inner" %}
{{ super_slot_inner.default }} {{ super_slot_inner.default }}
{% endfill %} {% endfill %}
{% endcomponent_block %} {% endcomponent %}
{% endfill %} {% endfill %}
{% endcomponent_block %} {% endcomponent %}
""" """
) )
rendered = template.render(Context({"objects": objects})) rendered = template.render(Context({"objects": objects}))
@ -1449,17 +1447,17 @@ class IterationFillTest(SimpleTestCase):
template = Template( template = Template(
""" """
{% load component_tags %} {% load component_tags %}
{% component_block "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 }}
{% component_block "slot_in_a_loop" objects=object.inner %} {% component "slot_in_a_loop" objects=object.inner %}
{% fill "slot_inner" as "super_slot_inner" %} {% fill "slot_inner" as "super_slot_inner" %}
{{ outer_scope_variable_2 }} {{ outer_scope_variable_2 }}
{{ super_slot_inner.default }} {{ super_slot_inner.default }}
{% endfill %} {% endfill %}
{% endcomponent_block %} {% endcomponent %}
{% endfill %} {% endfill %}
{% endcomponent_block %} {% endcomponent %}
""" """
) )
rendered = template.render( rendered = template.render(