django-components 0.110__tar.gz → 0.112__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {django_components-0.110/src/django_components.egg-info → django_components-0.112}/PKG-INFO +2 -2
- {django_components-0.110 → django_components-0.112}/README.md +1 -1
- {django_components-0.110 → django_components-0.112}/pyproject.toml +1 -1
- {django_components-0.110 → django_components-0.112}/src/django_components/component.py +6 -4
- {django_components-0.110 → django_components-0.112}/src/django_components/slots.py +26 -39
- {django_components-0.110 → django_components-0.112/src/django_components.egg-info}/PKG-INFO +2 -2
- {django_components-0.110 → django_components-0.112}/LICENSE +0 -0
- {django_components-0.110 → django_components-0.112}/MANIFEST.in +0 -0
- {django_components-0.110 → django_components-0.112}/setup.cfg +0 -0
- {django_components-0.110 → django_components-0.112}/src/django_components/__init__.py +0 -0
- {django_components-0.110 → django_components-0.112}/src/django_components/app_settings.py +0 -0
- {django_components-0.110 → django_components-0.112}/src/django_components/apps.py +0 -0
- {django_components-0.110 → django_components-0.112}/src/django_components/attributes.py +0 -0
- {django_components-0.110 → django_components-0.112}/src/django_components/autodiscovery.py +0 -0
- {django_components-0.110 → django_components-0.112}/src/django_components/component_media.py +0 -0
- {django_components-0.110 → django_components-0.112}/src/django_components/component_registry.py +0 -0
- {django_components-0.110 → django_components-0.112}/src/django_components/components/__init__.py +0 -0
- {django_components-0.110 → django_components-0.112}/src/django_components/components/dynamic.py +0 -0
- {django_components-0.110 → django_components-0.112}/src/django_components/context.py +0 -0
- {django_components-0.110 → django_components-0.112}/src/django_components/dependencies.py +0 -0
- {django_components-0.110 → django_components-0.112}/src/django_components/expression.py +0 -0
- {django_components-0.110 → django_components-0.112}/src/django_components/finders.py +0 -0
- {django_components-0.110 → django_components-0.112}/src/django_components/library.py +0 -0
- {django_components-0.110 → django_components-0.112}/src/django_components/management/__init__.py +0 -0
- {django_components-0.110 → django_components-0.112}/src/django_components/management/commands/__init__.py +0 -0
- {django_components-0.110 → django_components-0.112}/src/django_components/management/commands/startcomponent.py +0 -0
- {django_components-0.110 → django_components-0.112}/src/django_components/management/commands/upgradecomponent.py +0 -0
- {django_components-0.110 → django_components-0.112}/src/django_components/middleware.py +0 -0
- {django_components-0.110 → django_components-0.112}/src/django_components/node.py +0 -0
- {django_components-0.110 → django_components-0.112}/src/django_components/provide.py +0 -0
- {django_components-0.110 → django_components-0.112}/src/django_components/py.typed +0 -0
- {django_components-0.110 → django_components-0.112}/src/django_components/static/django_components/django_components.min.js +0 -0
- {django_components-0.110 → django_components-0.112}/src/django_components/tag_formatter.py +0 -0
- {django_components-0.110 → django_components-0.112}/src/django_components/template.py +0 -0
- {django_components-0.110 → django_components-0.112}/src/django_components/template_loader.py +0 -0
- {django_components-0.110 → django_components-0.112}/src/django_components/template_parser.py +0 -0
- {django_components-0.110 → django_components-0.112}/src/django_components/templatetags/__init__.py +0 -0
- {django_components-0.110 → django_components-0.112}/src/django_components/templatetags/component_tags.py +0 -0
- {django_components-0.110 → django_components-0.112}/src/django_components/types.py +0 -0
- {django_components-0.110 → django_components-0.112}/src/django_components/urls.py +0 -0
- {django_components-0.110 → django_components-0.112}/src/django_components/util/__init__.py +0 -0
- {django_components-0.110 → django_components-0.112}/src/django_components/util/cache.py +0 -0
- {django_components-0.110 → django_components-0.112}/src/django_components/util/html.py +0 -0
- {django_components-0.110 → django_components-0.112}/src/django_components/util/loader.py +0 -0
- {django_components-0.110 → django_components-0.112}/src/django_components/util/logger.py +0 -0
- {django_components-0.110 → django_components-0.112}/src/django_components/util/misc.py +0 -0
- {django_components-0.110 → django_components-0.112}/src/django_components/util/nanoid.py +0 -0
- {django_components-0.110 → django_components-0.112}/src/django_components/util/tag_parser.py +0 -0
- {django_components-0.110 → django_components-0.112}/src/django_components/util/types.py +0 -0
- {django_components-0.110 → django_components-0.112}/src/django_components/util/validation.py +0 -0
- {django_components-0.110 → django_components-0.112}/src/django_components.egg-info/SOURCES.txt +0 -0
- {django_components-0.110 → django_components-0.112}/src/django_components.egg-info/dependency_links.txt +0 -0
- {django_components-0.110 → django_components-0.112}/src/django_components.egg-info/requires.txt +0 -0
- {django_components-0.110 → django_components-0.112}/src/django_components.egg-info/top_level.txt +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: django_components
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.112
|
|
4
4
|
Summary: A way to create simple reusable template components in Django.
|
|
5
5
|
Author-email: Emil Stenström <emil@emilstenstrom.se>
|
|
6
6
|
License: MIT
|
|
@@ -1336,7 +1336,7 @@ tags:
|
|
|
1336
1336
|
{% endcomponent %}
|
|
1337
1337
|
```
|
|
1338
1338
|
|
|
1339
|
-
You can also use `{% for %}`, `{% with %}`, or other tags (even `{% include %}`)
|
|
1339
|
+
You can also use `{% for %}`, `{% with %}`, or other non-component tags (even `{% include %}`)
|
|
1340
1340
|
to construct the `{% fill %}` tags, **as long as these other tags do not leave any text behind!**
|
|
1341
1341
|
|
|
1342
1342
|
```django
|
|
@@ -1311,7 +1311,7 @@ tags:
|
|
|
1311
1311
|
{% endcomponent %}
|
|
1312
1312
|
```
|
|
1313
1313
|
|
|
1314
|
-
You can also use `{% for %}`, `{% with %}`, or other tags (even `{% include %}`)
|
|
1314
|
+
You can also use `{% for %}`, `{% with %}`, or other non-component tags (even `{% include %}`)
|
|
1315
1315
|
to construct the `{% fill %}` tags, **as long as these other tags do not leave any text behind!**
|
|
1316
1316
|
|
|
1317
1317
|
```django
|
|
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "django_components"
|
|
7
|
-
version = "0.
|
|
7
|
+
version = "0.112"
|
|
8
8
|
requires-python = ">=3.8, <4.0"
|
|
9
9
|
description = "A way to create simple reusable template components in Django."
|
|
10
10
|
keywords = ["django", "components", "css", "js", "html"]
|
|
@@ -57,6 +57,7 @@ from django_components.slots import (
|
|
|
57
57
|
SlotName,
|
|
58
58
|
SlotRef,
|
|
59
59
|
SlotResult,
|
|
60
|
+
_is_extracting_fill,
|
|
60
61
|
_nodelist_to_slot_render_func,
|
|
61
62
|
resolve_fills,
|
|
62
63
|
)
|
|
@@ -705,10 +706,6 @@ class Component(
|
|
|
705
706
|
# Get the component's HTML
|
|
706
707
|
html_content = template.render(context)
|
|
707
708
|
|
|
708
|
-
# After we've rendered the contents, we now know what slots were there,
|
|
709
|
-
# and thus we can validate that.
|
|
710
|
-
component_slot_ctx.post_render_validation()
|
|
711
|
-
|
|
712
709
|
# Allow to optionally override/modify the rendered content
|
|
713
710
|
new_output = self.on_render_after(context, template, html_content)
|
|
714
711
|
html_content = new_output if new_output is not None else html_content
|
|
@@ -884,6 +881,11 @@ class ComponentNode(BaseNode):
|
|
|
884
881
|
def render(self, context: Context) -> str:
|
|
885
882
|
trace_msg("RENDR", "COMP", self.name, self.node_id)
|
|
886
883
|
|
|
884
|
+
# Do not render nested `{% component %}` tags in other `{% component %}` tags
|
|
885
|
+
# at the stage when we are determining if the latter has named fills or not.
|
|
886
|
+
if _is_extracting_fill(context):
|
|
887
|
+
return ""
|
|
888
|
+
|
|
887
889
|
component_cls: Type[Component] = self.registry.get(self.name)
|
|
888
890
|
|
|
889
891
|
# Resolve FilterExpressions and Variables that were passed as args to the
|
|
@@ -148,41 +148,6 @@ class ComponentSlotContext:
|
|
|
148
148
|
default_slot: Optional[str]
|
|
149
149
|
fills: Dict[SlotName, Slot]
|
|
150
150
|
|
|
151
|
-
def post_render_validation(self) -> None:
|
|
152
|
-
if self.is_dynamic_component:
|
|
153
|
-
return
|
|
154
|
-
|
|
155
|
-
default_fill = self.fills.get(DEFAULT_SLOT_KEY, None)
|
|
156
|
-
|
|
157
|
-
# Check: Only component templates that include a 'default' slot
|
|
158
|
-
# can be invoked with implicit filling.
|
|
159
|
-
if default_fill and not self.default_slot:
|
|
160
|
-
raise TemplateSyntaxError(
|
|
161
|
-
f"Component '{self.component_name}' passed default fill content "
|
|
162
|
-
f"(i.e. without explicit 'name' kwarg), "
|
|
163
|
-
f"even though none of its slots is marked as 'default'."
|
|
164
|
-
)
|
|
165
|
-
|
|
166
|
-
# NOTE:
|
|
167
|
-
# In the current implementation, the slots are resolved only at the render time.
|
|
168
|
-
# So when we are rendering Django's Nodes, and we come across a SlotNode, only
|
|
169
|
-
# at that point we check if we have the fill for it.
|
|
170
|
-
#
|
|
171
|
-
# That means that we can use variables, and we can place slots in loops.
|
|
172
|
-
#
|
|
173
|
-
# However, because the slot names are dynamic, we cannot know all the slot names
|
|
174
|
-
# that will be rendered ahead of the time.
|
|
175
|
-
#
|
|
176
|
-
# Moreover, user may define a slot whose default content has more slots inside it.
|
|
177
|
-
#
|
|
178
|
-
# Previously, there was an error raised if there were unfilled slots or extra fills.
|
|
179
|
-
#
|
|
180
|
-
# But now this is only a message. Because:
|
|
181
|
-
# 1. We don't know about ALL slots, just about the rendered ones, so we CANNOT check
|
|
182
|
-
# for unfilled slots (rendered slots WILL raise an error if the fill is missing).
|
|
183
|
-
# 2. User may provide extra fills, but these may belong to slots we haven't
|
|
184
|
-
# encountered in this render run. So we CANNOT say which ones are extra.
|
|
185
|
-
|
|
186
151
|
|
|
187
152
|
class SlotNode(BaseNode):
|
|
188
153
|
"""Node corresponding to `{% slot %}`"""
|
|
@@ -214,6 +179,27 @@ class SlotNode(BaseNode):
|
|
|
214
179
|
def __repr__(self) -> str:
|
|
215
180
|
return f"<Slot Node: {self.node_id}. Contents: {repr(self.nodelist)}. Options: {self.active_flags}>"
|
|
216
181
|
|
|
182
|
+
# NOTE:
|
|
183
|
+
# In the current implementation, the slots are resolved only at the render time.
|
|
184
|
+
# So when we are rendering Django's Nodes, and we come across a SlotNode, only
|
|
185
|
+
# at that point we check if we have the fill for it.
|
|
186
|
+
#
|
|
187
|
+
# That means that we can use variables, and we can place slots in loops.
|
|
188
|
+
#
|
|
189
|
+
# However, because the slot names are dynamic, we cannot know all the slot names
|
|
190
|
+
# that will be rendered ahead of the time.
|
|
191
|
+
#
|
|
192
|
+
# Moreover, user may define a `{% slot %}` whose default content has more nested
|
|
193
|
+
# `{% slot %}` tags inside of it.
|
|
194
|
+
#
|
|
195
|
+
# Previously, there was an error raised if there were unfilled slots or extra fills,
|
|
196
|
+
# or if there was an extra fill for a default slot.
|
|
197
|
+
#
|
|
198
|
+
# But we don't raise those anymore, because:
|
|
199
|
+
# 1. We don't know about ALL slots, just about the rendered ones, so we CANNOT check
|
|
200
|
+
# for unfilled slots (rendered slots WILL raise an error if the fill is missing).
|
|
201
|
+
# 2. User may provide extra fills, but these may belong to slots we haven't
|
|
202
|
+
# encountered in this render run. So we CANNOT say which ones are extra.
|
|
217
203
|
def render(self, context: Context) -> SafeString:
|
|
218
204
|
trace_msg("RENDR", "SLOT", self.trace_id, self.node_id)
|
|
219
205
|
|
|
@@ -399,7 +385,7 @@ class FillNode(BaseNode):
|
|
|
399
385
|
self.trace_id = trace_id
|
|
400
386
|
|
|
401
387
|
def render(self, context: Context) -> str:
|
|
402
|
-
if
|
|
388
|
+
if _is_extracting_fill(context):
|
|
403
389
|
self._extract_fill(context)
|
|
404
390
|
return ""
|
|
405
391
|
|
|
@@ -459,9 +445,6 @@ class FillNode(BaseNode):
|
|
|
459
445
|
|
|
460
446
|
return value
|
|
461
447
|
|
|
462
|
-
def _is_extracting_fill(self, context: Context) -> bool:
|
|
463
|
-
return context.get(FILL_GEN_CONTEXT_KEY, None) is not None
|
|
464
|
-
|
|
465
448
|
def _extract_fill(self, context: Context) -> None:
|
|
466
449
|
# `FILL_GEN_CONTEXT_KEY` is only ever set when we are rendering content between the
|
|
467
450
|
# `{% component %}...{% endcomponent %}` tags. This is done in order to collect all fill tags.
|
|
@@ -775,3 +758,7 @@ def _nodelist_to_slot_render_func(
|
|
|
775
758
|
return rendered
|
|
776
759
|
|
|
777
760
|
return Slot(content_func=cast(SlotFunc, render_func))
|
|
761
|
+
|
|
762
|
+
|
|
763
|
+
def _is_extracting_fill(context: Context) -> bool:
|
|
764
|
+
return context.get(FILL_GEN_CONTEXT_KEY, None) is not None
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: django_components
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.112
|
|
4
4
|
Summary: A way to create simple reusable template components in Django.
|
|
5
5
|
Author-email: Emil Stenström <emil@emilstenstrom.se>
|
|
6
6
|
License: MIT
|
|
@@ -1336,7 +1336,7 @@ tags:
|
|
|
1336
1336
|
{% endcomponent %}
|
|
1337
1337
|
```
|
|
1338
1338
|
|
|
1339
|
-
You can also use `{% for %}`, `{% with %}`, or other tags (even `{% include %}`)
|
|
1339
|
+
You can also use `{% for %}`, `{% with %}`, or other non-component tags (even `{% include %}`)
|
|
1340
1340
|
to construct the `{% fill %}` tags, **as long as these other tags do not leave any text behind!**
|
|
1341
1341
|
|
|
1342
1342
|
```django
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{django_components-0.110 → django_components-0.112}/src/django_components/component_media.py
RENAMED
|
File without changes
|
{django_components-0.110 → django_components-0.112}/src/django_components/component_registry.py
RENAMED
|
File without changes
|
{django_components-0.110 → django_components-0.112}/src/django_components/components/__init__.py
RENAMED
|
File without changes
|
{django_components-0.110 → django_components-0.112}/src/django_components/components/dynamic.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{django_components-0.110 → django_components-0.112}/src/django_components/management/__init__.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{django_components-0.110 → django_components-0.112}/src/django_components/template_loader.py
RENAMED
|
File without changes
|
{django_components-0.110 → django_components-0.112}/src/django_components/template_parser.py
RENAMED
|
File without changes
|
{django_components-0.110 → django_components-0.112}/src/django_components/templatetags/__init__.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{django_components-0.110 → django_components-0.112}/src/django_components/util/tag_parser.py
RENAMED
|
File without changes
|
|
File without changes
|
{django_components-0.110 → django_components-0.112}/src/django_components/util/validation.py
RENAMED
|
File without changes
|
{django_components-0.110 → django_components-0.112}/src/django_components.egg-info/SOURCES.txt
RENAMED
|
File without changes
|
|
File without changes
|
{django_components-0.110 → django_components-0.112}/src/django_components.egg-info/requires.txt
RENAMED
|
File without changes
|
{django_components-0.110 → django_components-0.112}/src/django_components.egg-info/top_level.txt
RENAMED
|
File without changes
|