refactor: prefix component ID with c (#1127)

This commit is contained in:
Juro Oravec 2025-04-14 12:01:16 +02:00 committed by GitHub
parent fc026cbd99
commit c650e7f3a5
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
29 changed files with 786 additions and 746 deletions

View file

@ -4,6 +4,8 @@
#### Refactor
- Component ID is now prefixed with `c`, e.g. `c123456`.
- When typing a Component, you can now specify as few or as many parameters as you want.
```py

View file

@ -51,6 +51,26 @@ multiple times, the ID will be different for each call.
It is available as [`self.id`](../../../reference/api#django_components.Component.id).
The ID is a 7-letter alphanumeric string in the format `cXXXXXX`,
where `XXXXXX` is a random string of 6 alphanumeric characters (case-sensitive).
E.g. `c1a2b3c`.
A single render ID has a chance of collision 1 in 57 billion. However, due to birthday paradox, the chance of collision increases to 1% when approaching ~33K render IDs.
Thus, there is currently a soft-cap of ~30K components rendered on a single page.
If you need to expand this limit, please open an issue on GitHub.
```python
class Table(Component):
def get_context_data(self, *args, **attrs):
# Access component's ID
assert self.id == "djc1A2b3c"
return {}
```
## Component inputs
All the component inputs are captured and available as [`self.input`](../../../reference/api/#django_components.Component.input).

View file

@ -20,7 +20,7 @@ Import as
<a href="https://github.com/django-components/django-components/tree/master/src/django_components/templatetags/component_tags.py#L1064" target="_blank">See source code</a>
<a href="https://github.com/django-components/django-components/tree/master/src/django_components/templatetags/component_tags.py#L1037" target="_blank">See source code</a>
@ -43,7 +43,7 @@ If you insert this tag multiple times, ALL CSS links will be duplicately inserte
<a href="https://github.com/django-components/django-components/tree/master/src/django_components/templatetags/component_tags.py#L1086" target="_blank">See source code</a>
<a href="https://github.com/django-components/django-components/tree/master/src/django_components/templatetags/component_tags.py#L1059" target="_blank">See source code</a>
@ -67,7 +67,7 @@ If you insert this tag multiple times, ALL JS scripts will be duplicately insert
<a href="https://github.com/django-components/django-components/tree/master/src/django_components/templatetags/component_tags.py#L1669" target="_blank">See source code</a>
<a href="https://github.com/django-components/django-components/tree/master/src/django_components/templatetags/component_tags.py#L1655" target="_blank">See source code</a>

View file

@ -39,6 +39,7 @@ from django_components.app_settings import ContextBehavior, app_settings
from django_components.component_media import ComponentMediaInput, ComponentMediaMeta
from django_components.component_registry import ComponentRegistry
from django_components.component_registry import registry as registry_
from django_components.constants import COMP_ID_PREFIX
from django_components.context import _COMPONENT_CONTEXT_KEY, make_isolated_context_copy
from django_components.dependencies import (
RenderType,
@ -721,6 +722,11 @@ class Component(
Raises `RuntimeError` if accessed outside of rendering execution.
The ID is a 7-letter alphanumeric string in the format `cXXXXXX`,
where `XXXXXX` is a random string of 6 alphanumeric characters (case-sensitive).
E.g. `c1A2b3c`.
A single render ID has a chance of collision 1 in 57 billion. However, due to birthday paradox,
the chance of collision increases to 1% when approaching ~33K render IDs.
@ -1076,6 +1082,7 @@ class Component(
use components as Django views with `component.as_view()`.
Inputs:
- `args` - Positional args for the component. This is the same as calling the component
as `{% component "my_comp" arg1 arg2 ... %}`
- `kwargs` - Kwargs for the component. This is the same as calling the component
@ -1146,6 +1153,7 @@ class Component(
Render the component into a string.
Inputs:
- `args` - Positional args for the component. This is the same as calling the component
as `{% component "my_comp" arg1 arg2 ... %}`
- `kwargs` - Kwargs for the component. This is the same as calling the component
@ -1267,7 +1275,7 @@ class Component(
# This is handled as a stack, as users can potentially call `component.render()`
# from within component hooks. Thus, then they do so, `component.id` will be the ID
# of the deepest-most call to `component.render()`.
render_id = gen_id()
render_id = COMP_ID_PREFIX + gen_id()
metadata = MetadataItem(
render_id=render_id,
input=ComponentInput(
@ -1500,7 +1508,7 @@ class Component(
# Thus, the returned renderer function accepts the extra HTML attributes that were passed from parent,
# and returns the updated HTML content.
#
# Because the HTML attributes are all boolean (e.g. `data-djc-id-a1b3c4`), they are passed as a list.
# Because the HTML attributes are all boolean (e.g. `data-djc-id-ca1b3c4`), they are passed as a list.
#
# This whole setup makes it possible for multiple components to resolve to the same HTML element.
# E.g. if CompA renders CompB, and CompB renders a <div>, then the <div> element will have

View file

@ -0,0 +1,3 @@
UID_LENGTH = 6
COMP_ID_PREFIX = "c"
COMP_ID_LENGTH = len(COMP_ID_PREFIX) + UID_LENGTH

View file

@ -32,6 +32,7 @@ from django.utils.safestring import SafeString, mark_safe
from djc_core_html_parser import set_html_attributes
from django_components.cache import get_component_media_cache
from django_components.constants import COMP_ID_LENGTH
from django_components.node import BaseNode
from django_components.util.misc import is_nonempty_str
@ -230,9 +231,9 @@ def set_component_attrs_for_js_and_css(
# These are the attributes that we want to set on the root element.
all_root_attributes = [*root_attributes] if root_attributes else []
# Component ID is used for executing JS script, e.g. `data-djc-id-a1b2c3`
# Component ID is used for executing JS script, e.g. `data-djc-id-ca1b2c3`
#
# NOTE: We use `data-djc-css-a1b2c3` and `data-djc-id-a1b2c3` instead of
# NOTE: We use `data-djc-css-a1b2c3` and `data-djc-id-ca1b2c3` instead of
# `data-djc-css="a1b2c3"` and `data-djc-id="a1b2c3"`, to allow
# multiple values to be associated with the same element, which may happen if
# one component renders another.
@ -350,8 +351,8 @@ COMPONENT_COMMENT_REGEX = re.compile(rb"<!--\s+_RENDERED\s+(?P<data>[\w\-,/]+?)\
SCRIPT_NAME_REGEX = re.compile(
rb"^(?P<comp_cls_id>[\w\-\./]+?),(?P<id>[\w]+?),(?P<js>[0-9a-f]*?),(?P<css>[0-9a-f]*?)$"
)
# E.g. `data-djc-id-a1b2c3`
MAYBE_COMP_ID = r'(?: data-djc-id-\w{6}="")?'
# E.g. `data-djc-id-ca1b2c3`
MAYBE_COMP_ID = r'(?: data-djc-id-\w{{{COMP_ID_LENGTH}}}="")?'.format(COMP_ID_LENGTH=COMP_ID_LENGTH)
# E.g. `data-djc-css-99914b`
MAYBE_COMP_CSS_ID = r'(?: data-djc-css-\w{6}="")?'

View file

@ -4,6 +4,7 @@ from typing import TYPE_CHECKING, Callable, Deque, Dict, List, NamedTuple, Optio
from django.utils.safestring import mark_safe
from django_components.constants import COMP_ID_LENGTH
from django_components.util.exception import component_error_message
if TYPE_CHECKING:
@ -56,11 +57,15 @@ ComponentRenderer = Callable[[Optional[List[str]]], Tuple[str, Dict[str, List[st
component_renderer_cache: Dict[str, Tuple[ComponentRenderer, str]] = {}
child_component_attrs: Dict[str, List[str]] = {}
nested_comp_pattern = re.compile(r'<template [^>]*?djc-render-id="\w{6}"[^>]*?></template>')
render_id_pattern = re.compile(r'djc-render-id="(?P<render_id>\w{6})"')
nested_comp_pattern = re.compile(
r'<template [^>]*?djc-render-id="\w{{{COMP_ID_LENGTH}}}"[^>]*?></template>'.format(COMP_ID_LENGTH=COMP_ID_LENGTH)
)
render_id_pattern = re.compile(
r'djc-render-id="(?P<render_id>\w{{{COMP_ID_LENGTH}}})"'.format(COMP_ID_LENGTH=COMP_ID_LENGTH)
)
# When a component is rendered, we want to apply HTML attributes like `data-djc-id-a1b3cf`
# When a component is rendered, we want to apply HTML attributes like `data-djc-id-ca1b3cf`
# to all root elements. However, we have to approach it smartly, to minimize the HTML parsing.
#
# If we naively first rendered the child components, and then the parent component, then we would
@ -90,8 +95,8 @@ render_id_pattern = re.compile(r'djc-render-id="(?P<render_id>\w{6})"')
# The actual HTML output is stored in `component_renderer_cache`.
# 2. The parent of the child component is rendered normally.
# 3. If the placeholder for the child component is at root of the parent component,
# then the placeholder may be tagged with extra attributes, e.g. `data-djc-id-a1b3cf`.
# `<template djc-render-id="a1b3cf" data-djc-id-a1b3cf></template>`.
# then the placeholder may be tagged with extra attributes, e.g. `data-djc-id-ca1b3cf`.
# `<template djc-render-id="a1b3cf" data-djc-id-ca1b3cf></template>`.
# 4. When the parent is done rendering, we go back to step 1., the parent component
# either returns the actual HTML, or a placeholder.
# 5. Only once we get to the root component, that has no further parents, is when we finally

View file

@ -6,6 +6,7 @@ from itertools import chain
from types import ModuleType
from typing import TYPE_CHECKING, Any, Callable, Iterable, List, Optional, Tuple, Type, TypeVar, Union
from django_components.constants import UID_LENGTH
from django_components.util.nanoid import generate
if TYPE_CHECKING:
@ -24,7 +25,7 @@ def gen_id() -> str:
# See https://zelark.github.io/nano-id-cc/
return generate(
"0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ",
size=6,
size=UID_LENGTH,
)

View file

@ -25,8 +25,8 @@ Components.registerComponentData(
// we can run component's init function
Components.callComponent(
"table", // Component name
12345, // Component ID - An HTML element with corresponding
// attribute (`data-djc-id-12345`) MUST
"c123456", // Component ID - An HTML element with corresponding
// attribute (`data-djc-id-c123456`) MUST
// be present in the DOM.
"3d09cf", // Input ID
);

File diff suppressed because it is too large Load diff

View file

@ -8,7 +8,7 @@
<a
href="https://example.com"
class="py-2 px-4 bg-blue-600 text-white hover:bg-blue-500 focus-visible:outline-blue-600 transition inline-flex w-full text-sm font-semibold sm:mt-0 sm:w-auto focus-visible:outline-2 focus-visible:outline-offset-2 px-3 justify-center rounded-md shadow-sm no-underline"
data-djc-id-a1bc3e="">
data-djc-id-ca1bc3e="">
Click me!

View file

@ -155,7 +155,7 @@ class TestHtmlAttrs:
assertHTMLEqual(
rendered,
"""
<div @click.stop="dispatch('click_event')" x-data="{hello: 'world'}" class="padding-top-8 added_class another-class" data-djc-id-a1bc3f data-id=123>
<div @click.stop="dispatch('click_event')" x-data="{hello: 'world'}" class="padding-top-8 added_class another-class" data-djc-id-ca1bc3f data-id=123>
content
</div>
""", # noqa: E501
@ -208,7 +208,7 @@ class TestHtmlAttrs:
assertHTMLEqual(
rendered,
"""
<div @click.stop="dispatch('click_event')" class="added_class another-class padding-top-8" data-djc-id-a1bc3f data-id="123" x-data="{hello: 'world'}">
<div @click.stop="dispatch('click_event')" class="added_class another-class padding-top-8" data-djc-id-ca1bc3f data-id="123" x-data="{hello: 'world'}">
content
</div>
""", # noqa: E501
@ -236,7 +236,7 @@ class TestHtmlAttrs:
assertHTMLEqual(
rendered,
"""
<div @click.stop="dispatch('click_event')" x-data="{hello: 'world'}" class="padding-top-8 added_class another-class" data-djc-id-a1bc3f data-id=123>
<div @click.stop="dispatch('click_event')" x-data="{hello: 'world'}" class="padding-top-8 added_class another-class" data-djc-id-ca1bc3f data-id=123>
content
</div>
""", # noqa: E501
@ -268,7 +268,7 @@ class TestHtmlAttrs:
assertHTMLEqual(
rendered,
"""
<div @click.stop="dispatch('click_event')" class="added_class another-class padding-top-8" data-djc-id-a1bc3f data-id="123" x-data="{hello: 'world'}">
<div @click.stop="dispatch('click_event')" class="added_class another-class padding-top-8" data-djc-id-ca1bc3f data-id="123" x-data="{hello: 'world'}">
content
</div>
""", # noqa: E501
@ -295,7 +295,7 @@ class TestHtmlAttrs:
assertHTMLEqual(
rendered,
"""
<div class="added_class another-class from_agg_key" data-djc-id-a1bc3f data-id="123" type="submit">
<div class="added_class another-class from_agg_key" data-djc-id-ca1bc3f data-id="123" type="submit">
content
</div>
""", # noqa: E501
@ -375,7 +375,7 @@ class TestHtmlAttrs:
assertHTMLEqual(
rendered,
"""
<div class="added_class another-class override-me" data-djc-id-a1bc3f data-id=123>
<div class="added_class another-class override-me" data-djc-id-ca1bc3f data-id=123>
content
</div>
""",
@ -404,7 +404,7 @@ class TestHtmlAttrs:
assertHTMLEqual(
rendered,
"""
<div @click.stop="dispatch('click_event')" x-data="{hello: 'world'}" class="padding-top-8 added_class another-class" data-djc-id-a1bc3f data-id=123>
<div @click.stop="dispatch('click_event')" x-data="{hello: 'world'}" class="padding-top-8 added_class another-class" data-djc-id-ca1bc3f data-id=123>
content
</div>
""", # noqa: E501
@ -429,7 +429,7 @@ class TestHtmlAttrs:
assertHTMLEqual(
rendered,
"""
<div class="added_class another-class" data-djc-id-a1bc3f data-id="123">
<div class="added_class another-class" data-djc-id-ca1bc3f data-id="123">
content
</div>
""",
@ -457,7 +457,7 @@ class TestHtmlAttrs:
assertHTMLEqual(
rendered,
"""
<div data-djc-id-a1bc3f>
<div data-djc-id-ca1bc3f>
content
</div>
""",
@ -485,7 +485,7 @@ class TestHtmlAttrs:
assertHTMLEqual(
rendered,
"""
<div data-djc-id-a1bc3f>
<div data-djc-id-ca1bc3f>
content
</div>
""",

View file

@ -76,7 +76,7 @@ class TestComponentOldTemplateApi:
assertHTMLEqual(
rendered,
"""
Variable: <strong data-djc-id-a1bc3e>test</strong>
Variable: <strong data-djc-id-ca1bc3e>test</strong>
""",
)
@ -111,7 +111,7 @@ class TestComponent:
assertHTMLEqual(
rendered,
"""
Variable: <strong data-djc-id-a1bc3e>test</strong>
Variable: <strong data-djc-id-ca1bc3e>test</strong>
""",
)
@ -137,7 +137,7 @@ class TestComponent:
assertHTMLEqual(
rendered,
"""
Variable: <strong data-djc-id-a1bc3e>test</strong>
Variable: <strong data-djc-id-ca1bc3e>test</strong>
""",
)
@ -159,7 +159,7 @@ class TestComponent:
assertHTMLEqual(
rendered,
"""
Variable: <strong data-djc-id-a1bc3e>test</strong>
Variable: <strong data-djc-id-ca1bc3e>test</strong>
""",
)
@ -189,7 +189,7 @@ class TestComponent:
assertHTMLEqual(
rendered,
"""
Variable: <strong data-djc-id-a1bc3e>test</strong>
Variable: <strong data-djc-id-ca1bc3e>test</strong>
""",
)
@ -210,7 +210,7 @@ class TestComponent:
assertHTMLEqual(
rendered,
"""
Variable: <strong data-djc-id-a1bc3f>test</strong>
Variable: <strong data-djc-id-ca1bc3f>test</strong>
""",
)
@ -231,13 +231,13 @@ class TestComponent:
assertHTMLEqual(
SvgComponent.render(kwargs={"name": "svg1"}),
"""
<svg data-djc-id-a1bc3e>Dynamic1</svg>
<svg data-djc-id-ca1bc3e>Dynamic1</svg>
""",
)
assertHTMLEqual(
SvgComponent.render(kwargs={"name": "svg2"}),
"""
<svg data-djc-id-a1bc3f>Dynamic2</svg>
<svg data-djc-id-ca1bc3f>Dynamic2</svg>
""",
)
@ -257,7 +257,7 @@ class TestComponent:
assertHTMLEqual(
rendered,
"""
Variable: <strong data-djc-id-a1bc3e>test</strong>
Variable: <strong data-djc-id-ca1bc3e>test</strong>
""",
)
@ -299,7 +299,7 @@ class TestComponent:
assertHTMLEqual(
rendered,
"""
Variable: <strong data-djc-id-a1bc3e>test</strong> MY_SLOT
Variable: <strong data-djc-id-ca1bc3e>test</strong> MY_SLOT
""",
)
@ -746,7 +746,7 @@ class TestComponentRender:
assertHTMLEqual(
rendered,
"""
<custom-template data-djc-id-a1bc3e>
<custom-template data-djc-id-ca1bc3e>
<header>Default header</header>
<main>Default main</main>
<footer>Default footer</footer>
@ -768,7 +768,7 @@ class TestComponentRender:
assertHTMLEqual(
rendered,
"""
<custom-template data-djc-id-a1bc3e>
<custom-template data-djc-id-ca1bc3e>
<header>Default header</header>
<main>Default main</main>
<footer>Default footer</footer>
@ -791,7 +791,7 @@ class TestComponentRender:
assertHTMLEqual(
rendered,
"""
<custom-template data-djc-id-a1bc3e>
<custom-template data-djc-id-ca1bc3e>
<header>Default header</header>
<main>Default main</main>
<footer>Default footer</footer>
@ -843,7 +843,7 @@ class TestComponentRender:
# """
assertInHTML(
"""
<kbd data-djc-id-a1bc3e>
<kbd data-djc-id-ca1bc3e>
Rendered via GET request
</kbd>
""",
@ -939,7 +939,7 @@ class TestComponentRender:
rendered,
"""
<!DOCTYPE html>
<html data-djc-id-a1bc3e lang="en">
<html data-djc-id-ca1bc3e lang="en">
<body>
<main role="main">
<div class='container main-container'>
@ -964,7 +964,7 @@ class TestComponentRender:
rendered = TestComponent.render()
assertHTMLEqual(
rendered,
"Variable: <strong data-djc-id-a1bc3e>a1bc3e</strong>",
"Variable: <strong data-djc-id-ca1bc3e>ca1bc3e</strong>",
)
@djc_test(parametrize=PARAMETRIZE_CONTEXT_BEHAVIOR)
@ -980,7 +980,7 @@ class TestComponentRender:
rendered_resp = TestComponent.render_to_response()
assertHTMLEqual(
rendered_resp.content.decode("utf-8"),
"Variable: <strong data-djc-id-a1bc3e>a1bc3e</strong>",
"Variable: <strong data-djc-id-ca1bc3e>ca1bc3e</strong>",
)
@ -1036,7 +1036,7 @@ class TestComponentHook:
from_on_before: :)
---
Hello from nested
<div data-djc-id-a1bc3e data-djc-id-a1bc40>
<div data-djc-id-ca1bc3e data-djc-id-ca1bc40>
Hello from simple
</div>
---
@ -1099,7 +1099,7 @@ class TestComponentHook:
from_on_after:
---
Hello from nested
<div data-djc-id-a1bc3e data-djc-id-a1bc40>
<div data-djc-id-ca1bc3e data-djc-id-ca1bc40>
Hello from simple
</div>
""",
@ -1113,7 +1113,7 @@ class TestComponentHook:
from_on_after:
---
Hello from nested
<div data-djc-id-a1bc3e data-djc-id-a1bc40>
<div data-djc-id-ca1bc3e data-djc-id-ca1bc40>
Hello from simple
</div>
""",
@ -1170,7 +1170,7 @@ class TestComponentHook:
from_on_before:
---
Hello from nested
<div data-djc-id-a1bc3e data-djc-id-a1bc40>
<div data-djc-id-ca1bc3e data-djc-id-ca1bc40>
Hello from simple
</div>
""",
@ -1185,7 +1185,7 @@ class TestComponentHook:
from_on_before:
---
Hello from nested
<div data-djc-id-a1bc3e data-djc-id-a1bc40>
<div data-djc-id-ca1bc3e data-djc-id-ca1bc40>
Hello from simple
</div>
""",

View file

@ -46,8 +46,8 @@ class TestComponentCache:
# Check if the cache entry is set
cache_key = component.cache.get_cache_key()
assert cache_key == "components:cache:TestComponent_c9770f::"
assert component.cache.get_entry(cache_key) == "<!-- _RENDERED TestComponent_c9770f,a1bc3e,, -->Hello"
assert caches["default"].get(cache_key) == "<!-- _RENDERED TestComponent_c9770f,a1bc3e,, -->Hello"
assert component.cache.get_entry(cache_key) == "<!-- _RENDERED TestComponent_c9770f,ca1bc3e,, -->Hello"
assert caches["default"].get(cache_key) == "<!-- _RENDERED TestComponent_c9770f,ca1bc3e,, -->Hello"
# Second render
did_call_get = False
@ -104,7 +104,7 @@ class TestComponentCache:
cache_instance = component.cache
cache_key = cache_instance.get_cache_key()
assert cache_instance.get_entry(cache_key) == "<!-- _RENDERED TestComponent_42aca9,a1bc3e,, -->Hello"
assert cache_instance.get_entry(cache_key) == "<!-- _RENDERED TestComponent_42aca9,ca1bc3e,, -->Hello"
# Wait for TTL to expire
time.sleep(0.2)
@ -139,7 +139,7 @@ class TestComponentCache:
assert component.cache.get_cache() is caches["custom"]
assert (
component.cache.get_entry("components:cache:TestComponent_90ef7a::")
== "<!-- _RENDERED TestComponent_90ef7a,a1bc3e,, -->Hello"
== "<!-- _RENDERED TestComponent_90ef7a,ca1bc3e,, -->Hello"
) # noqa: E501
def test_cache_by_input(self):
@ -166,11 +166,11 @@ class TestComponentCache:
assert len(cache._cache) == 2
assert (
component.cache.get_entry("components:cache:TestComponent_648b95::input-world")
== "<!-- _RENDERED TestComponent_648b95,a1bc3e,, -->Hello world"
== "<!-- _RENDERED TestComponent_648b95,ca1bc3e,, -->Hello world"
) # noqa: E501
assert (
component.cache.get_entry("components:cache:TestComponent_648b95::input-cake")
== "<!-- _RENDERED TestComponent_648b95,a1bc3f,, -->Hello cake"
== "<!-- _RENDERED TestComponent_648b95,ca1bc3f,, -->Hello cake"
) # noqa: E501
def test_cache_input_hashing(self):

View file

@ -39,7 +39,7 @@ class TestMainMedia:
rendered = TestComponent.render()
assertInHTML(
'<div class="html-css-only" data-djc-id-a1bc3e>Content</div>',
'<div class="html-css-only" data-djc-id-ca1bc3e>Content</div>',
rendered,
)
assertInHTML(
@ -91,7 +91,7 @@ class TestMainMedia:
assertInHTML(
"""
<form data-djc-id-a1bc41 method="post">
<form data-djc-id-ca1bc41 method="post">
<input name="variable" type="text" value="test"/>
<input type="submit"/>
</form>
@ -153,7 +153,7 @@ class TestMainMedia:
).render(Context())
rendered = render_dependencies(rendered_raw)
assert 'Variable: <strong data-djc-id-a1bc41="">test</strong>' in rendered
assert 'Variable: <strong data-djc-id-ca1bc41="">test</strong>' in rendered
assertInHTML(
"<style>/* Used in `MainMediaTest` tests in `test_component_media.py` */\n.html-css-only {\n color: blue;\n}</style>",
rendered,
@ -221,7 +221,7 @@ class TestMainMedia:
context = Context({"variable": "Dynamic Content"})
assertHTMLEqual(
comp.render(context),
'<div class="variable-html" data-djc-id-a1bc3e>Dynamic Content</div>',
'<div class="variable-html" data-djc-id-ca1bc3e>Dynamic Content</div>',
)
def test_html_variable_filtered(self):
@ -241,8 +241,8 @@ class TestMainMedia:
assertHTMLEqual(
rendered,
"""
Var1: <strong data-djc-id-a1bc3e>test1</strong>
Var2 (uppercased): <strong data-djc-id-a1bc3e>TEST2</strong>
Var1: <strong data-djc-id-ca1bc3e>test1</strong>
Var2 (uppercased): <strong data-djc-id-ca1bc3e>TEST2</strong>
""",
)
@ -931,7 +931,7 @@ class TestMediaRelativePath:
assertInHTML(
"""
<form data-djc-id-a1bc41 method="post">
<form data-djc-id-ca1bc41 method="post">
<input type="text" name="variable" value="test">
<input type="submit">
</form>

View file

@ -105,8 +105,8 @@ class TestContext:
template = Template(template_str)
rendered = template.render(Context())
assertInHTML("<h1 data-djc-id-a1bc43>Shadowing variable = override</h1>", rendered)
assertInHTML("<h1 data-djc-id-a1bc44>Shadowing variable = slot_default_override</h1>", rendered)
assertInHTML("<h1 data-djc-id-ca1bc43>Shadowing variable = override</h1>", rendered)
assertInHTML("<h1 data-djc-id-ca1bc44>Shadowing variable = slot_default_override</h1>", rendered)
assert "Shadowing variable = NOT SHADOWED" not in rendered
@djc_test(parametrize=PARAMETRIZE_CONTEXT_BEHAVIOR)
@ -123,9 +123,9 @@ class TestContext:
template = Template(template_str)
rendered = template.render(Context())
assertInHTML("<h1 data-djc-id-a1bc43>Uniquely named variable = unique_val</h1>", rendered)
assertInHTML("<h1 data-djc-id-ca1bc43>Uniquely named variable = unique_val</h1>", rendered)
assertInHTML(
"<h1 data-djc-id-a1bc44>Uniquely named variable = slot_default_unique</h1>",
"<h1 data-djc-id-ca1bc44>Uniquely named variable = slot_default_unique</h1>",
rendered,
)
@ -146,8 +146,8 @@ class TestContext:
template = Template(template_str)
rendered = template.render(Context())
assertInHTML("<h1 data-djc-id-a1bc45>Shadowing variable = override</h1>", rendered)
assertInHTML("<h1 data-djc-id-a1bc46>Shadowing variable = shadow_from_slot</h1>", rendered)
assertInHTML("<h1 data-djc-id-ca1bc45>Shadowing variable = override</h1>", rendered)
assertInHTML("<h1 data-djc-id-ca1bc46>Shadowing variable = shadow_from_slot</h1>", rendered)
assert "Shadowing variable = NOT SHADOWED" not in rendered
@djc_test(parametrize=PARAMETRIZE_CONTEXT_BEHAVIOR)
@ -167,8 +167,8 @@ class TestContext:
template = Template(template_str)
rendered = template.render(Context())
assertInHTML("<h1 data-djc-id-a1bc45>Uniquely named variable = unique_val</h1>", rendered)
assertInHTML("<h1 data-djc-id-a1bc46>Uniquely named variable = unique_from_slot</h1>", rendered)
assertInHTML("<h1 data-djc-id-ca1bc45>Uniquely named variable = unique_val</h1>", rendered)
assertInHTML("<h1 data-djc-id-ca1bc46>Uniquely named variable = unique_from_slot</h1>", rendered)
@djc_test(parametrize=PARAMETRIZE_CONTEXT_BEHAVIOR)
def test_nested_component_context_shadows_outer_context_with_unfilled_slots_and_component_tag(
@ -184,8 +184,8 @@ class TestContext:
template = Template(template_str)
rendered = template.render(Context({"shadowing_variable": "NOT SHADOWED"}))
assertInHTML("<h1 data-djc-id-a1bc43>Shadowing variable = override</h1>", rendered)
assertInHTML("<h1 data-djc-id-a1bc44>Shadowing variable = slot_default_override</h1>", rendered)
assertInHTML("<h1 data-djc-id-ca1bc43>Shadowing variable = override</h1>", rendered)
assertInHTML("<h1 data-djc-id-ca1bc44>Shadowing variable = slot_default_override</h1>", rendered)
assert "Shadowing variable = NOT SHADOWED" not in rendered
@djc_test(parametrize=PARAMETRIZE_CONTEXT_BEHAVIOR)
@ -207,8 +207,8 @@ class TestContext:
template = Template(template_str)
rendered = template.render(Context({"shadowing_variable": "NOT SHADOWED"}))
assertInHTML("<h1 data-djc-id-a1bc45>Shadowing variable = override</h1>", rendered)
assertInHTML("<h1 data-djc-id-a1bc46>Shadowing variable = shadow_from_slot</h1>", rendered)
assertInHTML("<h1 data-djc-id-ca1bc45>Shadowing variable = override</h1>", rendered)
assertInHTML("<h1 data-djc-id-ca1bc46>Shadowing variable = shadow_from_slot</h1>", rendered)
assert "Shadowing variable = NOT SHADOWED" not in rendered
@ -251,15 +251,15 @@ class TestParentArgs:
assertHTMLEqual(
rendered,
"""
<div data-djc-id-a1bc3f>
<div data-djc-id-ca1bc3f>
<h1>Parent content</h1>
<h1 data-djc-id-a1bc43>Shadowing variable = passed_in</h1>
<h1 data-djc-id-a1bc43>Uniquely named variable = unique_val</h1>
<h1 data-djc-id-ca1bc43>Shadowing variable = passed_in</h1>
<h1 data-djc-id-ca1bc43>Uniquely named variable = unique_val</h1>
</div>
<div data-djc-id-a1bc3f>
<div data-djc-id-ca1bc3f>
<h2>Slot content</h2>
<h1 data-djc-id-a1bc44>Shadowing variable = slot_default_override</h1>
<h1 data-djc-id-a1bc44>Uniquely named variable = passed_in</h1>
<h1 data-djc-id-ca1bc44>Shadowing variable = slot_default_override</h1>
<h1 data-djc-id-ca1bc44>Uniquely named variable = passed_in</h1>
</div>
""",
)
@ -277,8 +277,8 @@ class TestParentArgs:
template = Template(template_str)
rendered = template.render(Context())
assertInHTML("<h1 data-djc-id-a1bc43>Shadowing variable = passed_in</h1>", rendered)
assertInHTML("<h1 data-djc-id-a1bc44>Uniquely named variable = passed_in</h1>", rendered)
assertInHTML("<h1 data-djc-id-ca1bc43>Shadowing variable = passed_in</h1>", rendered)
assertInHTML("<h1 data-djc-id-ca1bc44>Uniquely named variable = passed_in</h1>", rendered)
assert "Shadowing variable = NOT SHADOWED" not in rendered
@djc_test(
@ -311,14 +311,14 @@ class TestParentArgs:
assertHTMLEqual(
rendered,
f"""
<div data-djc-id-a1bc41>
<div data-djc-id-ca1bc41>
<h1>Parent content</h1>
<h1 data-djc-id-a1bc45>Shadowing variable = {first_val}</h1>
<h1 data-djc-id-a1bc45>Uniquely named variable = unique_val</h1>
<h1 data-djc-id-ca1bc45>Shadowing variable = {first_val}</h1>
<h1 data-djc-id-ca1bc45>Uniquely named variable = unique_val</h1>
</div>
<div data-djc-id-a1bc41>
<h1 data-djc-id-a1bc46>Shadowing variable = value_from_slot</h1>
<h1 data-djc-id-a1bc46>Uniquely named variable = {second_val}</h1>
<div data-djc-id-ca1bc41>
<h1 data-djc-id-ca1bc46>Shadowing variable = value_from_slot</h1>
<h1 data-djc-id-ca1bc46>Uniquely named variable = {second_val}</h1>
</div>
""",
)
@ -337,7 +337,7 @@ class TestContextCalledOnce:
rendered = template.render(Context()).strip().replace("\n", "")
assertHTMLEqual(
rendered,
'<p class="incrementer" data-djc-id-a1bc3f>value=1;calls=1</p>',
'<p class="incrementer" data-djc-id-ca1bc3f>value=1;calls=1</p>',
)
@djc_test(parametrize=PARAMETRIZE_CONTEXT_BEHAVIOR)
@ -353,7 +353,7 @@ class TestContextCalledOnce:
assertHTMLEqual(
rendered,
"""
<p class="incrementer" data-djc-id-a1bc3f>value=3;calls=1</p>
<p class="incrementer" data-djc-id-ca1bc3f>value=3;calls=1</p>
""",
)
@ -367,7 +367,7 @@ class TestContextCalledOnce:
template = Template(template_str)
rendered = template.render(Context()).strip()
assertHTMLEqual(rendered, '<p class="incrementer" data-djc-id-a1bc3f>value=1;calls=1</p>')
assertHTMLEqual(rendered, '<p class="incrementer" data-djc-id-ca1bc3f>value=1;calls=1</p>')
@djc_test(parametrize=PARAMETRIZE_CONTEXT_BEHAVIOR)
def test_one_context_call_with_component_and_arg(self, components_settings):
@ -379,7 +379,7 @@ class TestContextCalledOnce:
template = Template(template_str)
rendered = template.render(Context()).strip()
assertHTMLEqual(rendered, '<p class="incrementer" data-djc-id-a1bc3f>value=4;calls=1</p>')
assertHTMLEqual(rendered, '<p class="incrementer" data-djc-id-ca1bc3f>value=4;calls=1</p>')
@djc_test(parametrize=PARAMETRIZE_CONTEXT_BEHAVIOR)
def test_one_context_call_with_slot(self, components_settings):
@ -398,8 +398,8 @@ class TestContextCalledOnce:
assertHTMLEqual(
rendered,
"""
<p class="incrementer" data-djc-id-a1bc40>value=1;calls=1</p>
<p data-djc-id-a1bc40>slot</p>
<p class="incrementer" data-djc-id-ca1bc40>value=1;calls=1</p>
<p data-djc-id-ca1bc40>slot</p>
""",
rendered,
)
@ -421,8 +421,8 @@ class TestContextCalledOnce:
assertHTMLEqual(
rendered,
"""
<p class="incrementer" data-djc-id-a1bc40>value=4;calls=1</p>
<p data-djc-id-a1bc40>slot</p>
<p class="incrementer" data-djc-id-ca1bc40>value=4;calls=1</p>
<p data-djc-id-ca1bc40>slot</p>
""",
rendered,
)
@ -451,7 +451,7 @@ class TestComponentsCanAccessOuterContext:
assertHTMLEqual(
rendered,
f"""
Variable: <strong data-djc-id-a1bc3f> {expected_value} </strong>
Variable: <strong data-djc-id-ca1bc3f> {expected_value} </strong>
""",
)
@ -981,7 +981,7 @@ class TestContextVarsIsFilled:
rendered = Template(template).render(Context())
expected = """
<div class="frontmatter-component" data-djc-id-a1bc42>
<div class="frontmatter-component" data-djc-id-ca1bc42>
title: True
my_title: False
my_title_1: False
@ -1003,7 +1003,7 @@ class TestContextVarsIsFilled:
"""
rendered = Template(template).render(Context())
expected = """
<div class="frontmatter-component" data-djc-id-a1bc3f>
<div class="frontmatter-component" data-djc-id-ca1bc3f>
bla bla
title: False
my_title: False
@ -1023,7 +1023,7 @@ class TestContextVarsIsFilled:
{% component "conditional_slots" %}{% endcomponent %}
"""
expected = """
<div class="frontmatter-component" data-djc-id-a1bc3f>
<div class="frontmatter-component" data-djc-id-ca1bc3f>
<div class="title">
Title
</div>
@ -1043,7 +1043,7 @@ class TestContextVarsIsFilled:
{% endcomponent %}
"""
expected = """
<div class="frontmatter-component" data-djc-id-a1bc40>
<div class="frontmatter-component" data-djc-id-ca1bc40>
<div class="title">
Title
</div>
@ -1069,7 +1069,7 @@ class TestContextVarsIsFilled:
{% endcomponent %}
"""
expected = """
<div class="frontmatter-component" data-djc-id-a1bc40>
<div class="frontmatter-component" data-djc-id-ca1bc40>
<div class="title">
Title
</div>
@ -1094,7 +1094,7 @@ class TestContextVarsIsFilled:
{% endcomponent %}
"""
expected = """
<div class="frontmatter-component" data-djc-id-a1bc3f>
<div class="frontmatter-component" data-djc-id-ca1bc3f>
<div class="title">
Title
</div>
@ -1128,7 +1128,7 @@ class TestContextVarsIsFilled:
{% endcomponent %}
"""
expected = """
<div class="frontmatter-component" data-djc-id-a1bc3f>
<div class="frontmatter-component" data-djc-id-ca1bc3f>
<div class="title">
Title
</div>

View file

@ -267,7 +267,7 @@ class TestRenderDependencies:
assertInHTML(
"""
<body>
Variable: <strong data-djc-id-a1bc41>foo</strong>
Variable: <strong data-djc-id-ca1bc41>foo</strong>
<style>.xyz { color: red; }</style>
<link href="style.css" media="all" rel="stylesheet">
@ -423,7 +423,7 @@ class TestRenderDependencies:
<td class="whitespace-nowrap w-fit text-center px-4 w-px"
aria-colindex="1">
1
Variable: <strong data-djc-id-a1bc3f>hi</strong>
Variable: <strong data-djc-id-ca1bc3f>hi</strong>
</td>
</tr>
</tbody>
@ -511,7 +511,7 @@ class TestMiddleware:
)
assert_dependencies(rendered1)
assert rendered1.count('Variable: <strong data-djc-id-a1bc42="" data-djc-id-a1bc41="">value</strong>') == 1
assert rendered1.count('Variable: <strong data-djc-id-ca1bc42="" data-djc-id-ca1bc41="">value</strong>') == 1
rendered2 = create_and_process_template_response(
template,
@ -519,7 +519,7 @@ class TestMiddleware:
)
assert_dependencies(rendered2)
assert rendered2.count('Variable: <strong data-djc-id-a1bc44="" data-djc-id-a1bc43="">value</strong>') == 1
assert rendered2.count('Variable: <strong data-djc-id-ca1bc44="" data-djc-id-ca1bc43="">value</strong>') == 1
rendered3 = create_and_process_template_response(
template,
@ -527,4 +527,4 @@ class TestMiddleware:
)
assert_dependencies(rendered3)
assert rendered3.count('Variable: <strong data-djc-id-a1bc46="" data-djc-id-a1bc45="">value</strong>') == 1
assert rendered3.count('Variable: <strong data-djc-id-ca1bc46="" data-djc-id-ca1bc45="">value</strong>') == 1

View file

@ -218,11 +218,11 @@ class TestCallComponent:
const manager = Components.createComponentsManager();
const compName = 'my_comp';
const compId = '12345';
const compId = 'c12345';
const inputHash = 'input-abc';
// Pretend that this HTML belongs to our component
document.body.insertAdjacentHTML('beforeend', '<div data-djc-id-12345> abc </div>');
document.body.insertAdjacentHTML('beforeend', '<div data-djc-id-c12345> abc </div>');
let captured = null;
manager.registerComponent(compName, (data, ctx) => {
@ -253,8 +253,8 @@ class TestCallComponent:
"hello": "world",
},
"ctx": {
"els": ['<div data-djc-id-12345=""> abc </div>'],
"id": "12345",
"els": ['<div data-djc-id-c12345=""> abc </div>'],
"id": "c12345",
"name": "my_comp",
},
}
@ -269,11 +269,11 @@ class TestCallComponent:
const manager = Components.createComponentsManager();
const compName = 'my_comp';
const compId = '12345';
const compId = 'c12345';
const inputHash = 'input-abc';
// Pretend that this HTML belongs to our component
document.body.insertAdjacentHTML('beforeend', '<div data-djc-id-12345> abc </div>');
document.body.insertAdjacentHTML('beforeend', '<div data-djc-id-c12345> abc </div>');
manager.registerComponent(compName, (data, ctx) => {
return Promise.resolve(123);
@ -309,11 +309,11 @@ class TestCallComponent:
const manager = Components.createComponentsManager();
const compName = 'my_comp';
const compId = '12345';
const compId = 'c12345';
const inputHash = 'input-abc';
// Pretend that this HTML belongs to our component
document.body.insertAdjacentHTML('beforeend', '<div data-djc-id-12345> abc </div>');
document.body.insertAdjacentHTML('beforeend', '<div data-djc-id-c12345> abc </div>');
manager.registerComponent(compName, (data, ctx) => {
throw Error('Oops!');
@ -343,11 +343,11 @@ class TestCallComponent:
const manager = Components.createComponentsManager();
const compName = 'my_comp';
const compId = '12345';
const compId = 'c12345';
const inputHash = 'input-abc';
// Pretend that this HTML belongs to our component
document.body.insertAdjacentHTML('beforeend', '<div data-djc-id-12345> abc </div>');
document.body.insertAdjacentHTML('beforeend', '<div data-djc-id-c12345> abc </div>');
manager.registerComponent(compName, async (data, ctx) => {
throw Error('Oops!');
@ -410,10 +410,10 @@ class TestCallComponent:
const manager = Components.createComponentsManager();
const compName = 'my_comp';
const compId = '12345';
const compId = 'c12345';
const inputHash = 'input-abc';
document.body.insertAdjacentHTML('beforeend', '<div data-djc-id-12345> abc </div>');
document.body.insertAdjacentHTML('beforeend', '<div data-djc-id-c12345> abc </div>');
manager.registerComponent(compName, (data, ctx) => {
return Promise.resolve(123);

View file

@ -512,7 +512,7 @@ class TestDependencyRendering:
template = Template(template_str)
rendered = create_and_process_template_response(template)
assertHTMLEqual(rendered, "Variable: <strong data-djc-id-a1bc3f>foo</strong>")
assertHTMLEqual(rendered, "Variable: <strong data-djc-id-ca1bc3f>foo</strong>")
def test_adds_component_id_html_attr_single_multiroot(self):
class SimpleMultiroot(SimpleComponent):
@ -534,9 +534,9 @@ class TestDependencyRendering:
assertHTMLEqual(
rendered,
"""
Variable: <strong data-djc-id-a1bc3f>foo</strong>
Variable2: <div data-djc-id-a1bc3f>foo</div>
Variable3: <span data-djc-id-a1bc3f>foo</span>
Variable: <strong data-djc-id-ca1bc3f>foo</strong>
Variable2: <div data-djc-id-ca1bc3f>foo</div>
Variable3: <span data-djc-id-ca1bc3f>foo</span>
""",
)
@ -570,10 +570,10 @@ class TestDependencyRendering:
assertHTMLEqual(
rendered,
"""
Variable: <strong data-djc-id-a1bc3f data-djc-id-a1bc41>foo</strong>
Variable2: <div data-djc-id-a1bc3f data-djc-id-a1bc41>foo</div>
Variable3: <span data-djc-id-a1bc3f data-djc-id-a1bc41>foo</span>
<div data-djc-id-a1bc3f>Another</div>
Variable: <strong data-djc-id-ca1bc3f data-djc-id-ca1bc41>foo</strong>
Variable2: <div data-djc-id-ca1bc3f data-djc-id-ca1bc41>foo</div>
Variable3: <span data-djc-id-ca1bc3f data-djc-id-ca1bc41>foo</span>
<div data-djc-id-ca1bc3f>Another</div>
""",
)
@ -613,19 +613,19 @@ class TestDependencyRendering:
assertHTMLEqual(
rendered,
"""
Variable: <strong data-djc-id-a1bc3f data-djc-id-a1bc41>foo</strong>
Variable2: <div data-djc-id-a1bc3f data-djc-id-a1bc41>foo</div>
Variable3: <span data-djc-id-a1bc3f data-djc-id-a1bc41>foo</span>
<div data-djc-id-a1bc3f>Another</div>
Variable: <strong data-djc-id-ca1bc3f data-djc-id-ca1bc41>foo</strong>
Variable2: <div data-djc-id-ca1bc3f data-djc-id-ca1bc41>foo</div>
Variable3: <span data-djc-id-ca1bc3f data-djc-id-ca1bc41>foo</span>
<div data-djc-id-ca1bc3f>Another</div>
Variable: <strong data-djc-id-a1bc42 data-djc-id-a1bc43>foo</strong>
Variable2: <div data-djc-id-a1bc42 data-djc-id-a1bc43>foo</div>
Variable3: <span data-djc-id-a1bc42 data-djc-id-a1bc43>foo</span>
<div data-djc-id-a1bc42>Another</div>
Variable: <strong data-djc-id-ca1bc42 data-djc-id-ca1bc43>foo</strong>
Variable2: <div data-djc-id-ca1bc42 data-djc-id-ca1bc43>foo</div>
Variable3: <span data-djc-id-ca1bc42 data-djc-id-ca1bc43>foo</span>
<div data-djc-id-ca1bc42>Another</div>
Variable: <strong data-djc-id-a1bc44 data-djc-id-a1bc45>foo</strong>
Variable2: <div data-djc-id-a1bc44 data-djc-id-a1bc45>foo</div>
Variable3: <span data-djc-id-a1bc44 data-djc-id-a1bc45>foo</span>
<div data-djc-id-a1bc44>Another</div>
Variable: <strong data-djc-id-ca1bc44 data-djc-id-ca1bc45>foo</strong>
Variable2: <div data-djc-id-ca1bc44 data-djc-id-ca1bc45>foo</div>
Variable3: <span data-djc-id-ca1bc44 data-djc-id-ca1bc45>foo</span>
<div data-djc-id-ca1bc44>Another</div>
""",
)

View file

@ -49,7 +49,7 @@ class TestE2eDependencyRendering:
# Check that the actual HTML content was loaded
assert re.compile(
r'Variable: <strong class="inner" data-djc-id-\w{6}="">foo</strong>'
r'Variable: <strong class="inner" data-djc-id-\w{7}="">foo</strong>'
).search(data["bodyHTML"]) is not None
assertInHTML('<div class="my-style"> 123 </div>', data["bodyHTML"], count=1)
assertInHTML('<div class="my-style2"> xyz </div>', data["bodyHTML"], count=1)
@ -113,25 +113,25 @@ class TestE2eDependencyRendering:
# Check that the actual HTML content was loaded
assert re.compile(
# <div class="outer" data-djc-id-10uLMD>
# <div class="outer" data-djc-id-c10uLMD>
# Variable:
# <strong class="inner" data-djc-id-DZEnUC>
# <strong class="inner" data-djc-id-cDZEnUC>
# variable
# </strong>
# XYZ:
# <strong class="other" data-djc-id-IYirHK>
# <strong class="other" data-djc-id-cIYirHK>
# variable_inner
# </strong>
# </div>
# <div class="my-style">123</div>
# <div class="my-style2">xyz</div>
r'<div class="outer" data-djc-id-\w{6}="">\s*'
r'<div class="outer" data-djc-id-\w{7}="">\s*'
r"Variable:\s*"
r'<strong class="inner" data-djc-id-\w{6}="">\s*'
r'<strong class="inner" data-djc-id-\w{7}="">\s*'
r"variable\s*"
r"<\/strong>\s*"
r"XYZ:\s*"
r'<strong class="other" data-djc-id-\w{6}="">\s*'
r'<strong class="other" data-djc-id-\w{7}="">\s*'
r"variable_inner\s*"
r"<\/strong>\s*"
r"<\/div>\s*"
@ -204,26 +204,26 @@ class TestE2eDependencyRendering:
# Check that the actual HTML content was loaded
#
# <div class="outer" data-djc-id-10uLMD>
# <div class="outer" data-djc-id-c10uLMD>
# Variable:
# <strong class="inner" data-djc-id-DZEnUC>
# <strong class="inner" data-djc-id-cDZEnUC>
# variable
# </strong>
# XYZ:
# <strong data-djc-id-IYirHK class="other">
# <strong data-djc-id-cIYirHK class="other">
# variable_inner
# </strong>
# </div>
# <div class="my-style">123</div>
# <div class="my-style2">xyz</div>
assert re.compile(
r'<div class="outer" data-djc-id-\w{6}="">\s*'
r'<div class="outer" data-djc-id-\w{7}="">\s*'
r"Variable:\s*"
r'<strong class="inner" data-djc-id-\w{6}="">\s*'
r'<strong class="inner" data-djc-id-\w{7}="">\s*'
r"variable\s*"
r"<\/strong>\s*"
r"XYZ:\s*"
r'<strong class="other" data-djc-id-\w{6}="">\s*'
r'<strong class="other" data-djc-id-\w{7}="">\s*'
r"variable_inner\s*"
r"<\/strong>\s*"
r"<\/div>\s*"
@ -378,7 +378,7 @@ class TestE2eDependencyRendering:
assert data["targetHtml"] is None
assert re.compile(
r'<div class="frag" data-djc-id-\w{6}="">\s*' r"123\s*" r'<span id="frag-text">xxx</span>\s*' r"</div>"
r'<div class="frag" data-djc-id-\w{7}="">\s*' r"123\s*" r'<span id="frag-text">xxx</span>\s*' r"</div>"
).search(data["fragHtml"]) is not None
assert "rgb(0, 0, 255)" in data["fragBg"] # AKA 'background: blue'
@ -428,7 +428,7 @@ class TestE2eDependencyRendering:
assert data["targetHtml"] is None
assert re.compile(
r'<div class="frag" data-djc-id-\w{6}="">\s*' r"123\s*" r'<span id="frag-text">xxx</span>\s*' r"</div>"
r'<div class="frag" data-djc-id-\w{7}="">\s*' r"123\s*" r'<span id="frag-text">xxx</span>\s*' r"</div>"
).search(data["fragHtml"]) is not None
assert "rgb(0, 0, 255)" in data["fragBg"] # AKA 'background: blue'
@ -481,7 +481,7 @@ class TestE2eDependencyRendering:
# NOTE: Unlike the vanilla JS tests, for the Alpine test we don't remove the targetHtml,
# but only change its contents.
assert re.compile(
r'<div class="frag" data-djc-id-\w{6}="">\s*' r"123\s*" r'<span id="frag-text">xxx</span>\s*' r"</div>"
r'<div class="frag" data-djc-id-\w{7}="">\s*' r"123\s*" r'<span id="frag-text">xxx</span>\s*' r"</div>"
).search(data["targetHtml"]) is not None
assert "rgb(0, 0, 255)" in data["fragBg"] # AKA 'background: blue'

View file

@ -121,10 +121,10 @@ class TestDynamicExpr:
assertHTMLEqual(
rendered,
"""
<!-- _RENDERED SimpleComponent_5b8d97,a1bc3f,, -->
<div data-djc-id-a1bc3f>lorem</div>
<div data-djc-id-a1bc3f>True</div>
<div data-djc-id-a1bc3f>[{'a': 1}, {'a': 2}]</div>
<!-- _RENDERED SimpleComponent_5b8d97,ca1bc3f,, -->
<div data-djc-id-ca1bc3f>lorem</div>
<div data-djc-id-ca1bc3f>True</div>
<div data-djc-id-ca1bc3f>[{'a': 1}, {'a': 2}]</div>
""",
)
@ -194,11 +194,11 @@ class TestDynamicExpr:
assertHTMLEqual(
rendered,
"""
<!-- _RENDERED SimpleComponent_743413,a1bc3f,, -->
<div data-djc-id-a1bc3f>lorem ipsum dolor</div>
<div data-djc-id-a1bc3f>True</div>
<div data-djc-id-a1bc3f>[{'a': 1}, {'a': 2}]</div>
<div data-djc-id-a1bc3f>{'a': 3}</div>
<!-- _RENDERED SimpleComponent_743413,ca1bc3f,, -->
<div data-djc-id-ca1bc3f>lorem ipsum dolor</div>
<div data-djc-id-ca1bc3f>True</div>
<div data-djc-id-ca1bc3f>[{'a': 1}, {'a': 2}]</div>
<div data-djc-id-ca1bc3f>{'a': 3}</div>
""",
)
@ -267,11 +267,11 @@ class TestDynamicExpr:
# NOTE: This is whitespace-sensitive test, so we check exact output
assert rendered.strip() == (
"<!-- _RENDERED SimpleComponent_6f07b3,a1bc3f,, -->\n"
' <div data-djc-id-a1bc3f=""></div>\n'
' <div data-djc-id-a1bc3f=""> abc</div>\n'
' <div data-djc-id-a1bc3f=""></div>\n'
' <div data-djc-id-a1bc3f=""> </div>'
"<!-- _RENDERED SimpleComponent_6f07b3,ca1bc3f,, -->\n"
' <div data-djc-id-ca1bc3f=""></div>\n'
' <div data-djc-id-ca1bc3f=""> abc</div>\n'
' <div data-djc-id-ca1bc3f=""></div>\n'
' <div data-djc-id-ca1bc3f=""> </div>'
)
@djc_test(parametrize=PARAMETRIZE_CONTEXT_BEHAVIOR)
@ -343,12 +343,12 @@ class TestDynamicExpr:
# NOTE: This is whitespace-sensitive test, so we check exact output
assert rendered.strip() == (
"<!-- _RENDERED SimpleComponent_85c7eb,a1bc3f,, -->\n"
' <div data-djc-id-a1bc3f=""> lorem ipsum dolor </div>\n'
' <div data-djc-id-a1bc3f=""> lorem ipsum dolor [{\'a\': 1}] </div>\n'
' <div data-djc-id-a1bc3f=""> True </div>\n'
' <div data-djc-id-a1bc3f=""> [{\'a\': 1}, {\'a\': 2}] </div>\n'
' <div data-djc-id-a1bc3f=""> {\'a\': 3} </div>'
"<!-- _RENDERED SimpleComponent_85c7eb,ca1bc3f,, -->\n"
' <div data-djc-id-ca1bc3f=""> lorem ipsum dolor </div>\n'
' <div data-djc-id-ca1bc3f=""> lorem ipsum dolor [{\'a\': 1}] </div>\n'
' <div data-djc-id-ca1bc3f=""> True </div>\n'
' <div data-djc-id-ca1bc3f=""> [{\'a\': 1}, {\'a\': 2}] </div>\n'
' <div data-djc-id-ca1bc3f=""> {\'a\': 3} </div>'
)
@djc_test(parametrize=PARAMETRIZE_CONTEXT_BEHAVIOR)
@ -391,10 +391,10 @@ class TestDynamicExpr:
assertHTMLEqual(
rendered,
"""
<!-- _RENDERED SimpleComponent_c7a5c3,a1bc3f,, -->
<div data-djc-id-a1bc3f>"</div>
<div data-djc-id-a1bc3f>{%}</div>
<div data-djc-id-a1bc3f>True</div>
<!-- _RENDERED SimpleComponent_c7a5c3,ca1bc3f,, -->
<div data-djc-id-ca1bc3f>"</div>
<div data-djc-id-ca1bc3f>{%}</div>
<div data-djc-id-ca1bc3f>True</div>
""",
)
@ -443,14 +443,14 @@ class TestDynamicExpr:
assertHTMLEqual(
rendered,
"""
<!-- _RENDERED SimpleComponent_5c8766,a1bc41,, -->
<div data-djc-id-a1bc41>
<!-- _RENDERED SimpleComponent_5c8766,a1bc40,, -->
<div data-djc-id-a1bc40>3</div>
<div data-djc-id-a1bc40>True</div>
<!-- _RENDERED SimpleComponent_5c8766,ca1bc41,, -->
<div data-djc-id-ca1bc41>
<!-- _RENDERED SimpleComponent_5c8766,ca1bc40,, -->
<div data-djc-id-ca1bc40>3</div>
<div data-djc-id-ca1bc40>True</div>
</div>
<div data-djc-id-a1bc41>True</div>
"""
<div data-djc-id-ca1bc41>True</div>
""",
)
@ -519,11 +519,11 @@ class TestSpreadOperator:
assertHTMLEqual(
rendered,
"""
<div data-djc-id-a1bc3f>LoREM</div>
<div data-djc-id-a1bc3f>{'@click': '() =&gt; {}', 'style': 'height: 20px'}</div>
<div data-djc-id-a1bc3f>[1, 2, 3]</div>
<div data-djc-id-a1bc3f>1</div>
<div data-djc-id-a1bc3f>123</div>
<div data-djc-id-ca1bc3f>LoREM</div>
<div data-djc-id-ca1bc3f>{'@click': '() =&gt; {}', 'style': 'height: 20px'}</div>
<div data-djc-id-ca1bc3f>[1, 2, 3]</div>
<div data-djc-id-ca1bc3f>1</div>
<div data-djc-id-ca1bc3f>123</div>
""",
)
@ -656,9 +656,9 @@ class TestSpreadOperator:
assertHTMLEqual(
rendered,
"""
<div data-djc-id-a1bc41>{'@click': '() =&gt; {}', 'style': 'height: 20px'}</div>
<div data-djc-id-a1bc41>[1, 2, 3]</div>
<div data-djc-id-a1bc41>1</div>
<div data-djc-id-ca1bc41>{'@click': '() =&gt; {}', 'style': 'height: 20px'}</div>
<div data-djc-id-ca1bc41>[1, 2, 3]</div>
<div data-djc-id-ca1bc41>1</div>
""",
)
@ -760,10 +760,10 @@ class TestSpreadOperator:
assertHTMLEqual(
rendered2,
"""
<div data-djc-id-a1bc40>{'@click': '() =&gt; {}', 'style': 'OVERWRITTEN'}</div>
<div data-djc-id-a1bc40>[1, 2, 3]</div>
<div data-djc-id-a1bc40>1</div>
<div data-djc-id-a1bc40>OVERWRITTEN_X</div>
<div data-djc-id-ca1bc40>{'@click': '() =&gt; {}', 'style': 'OVERWRITTEN'}</div>
<div data-djc-id-ca1bc40>[1, 2, 3]</div>
<div data-djc-id-ca1bc40>1</div>
<div data-djc-id-ca1bc40>OVERWRITTEN_X</div>
""",
)

View file

@ -205,11 +205,11 @@ class TestMultipleComponentRegistries:
assertHTMLEqual(
rendered,
"""
Variable: <strong data-djc-id-a1bc40>123</strong>
Variable: <strong data-djc-id-ca1bc40>123</strong>
Slot:
SLOT 123
Variable: <strong data-djc-id-a1bc42>123</strong>
Variable: <strong data-djc-id-ca1bc42>123</strong>
Slot:
SLOT ABC
""",

View file

@ -73,7 +73,7 @@ class TestComponentTag:
rendered,
"""
hello1
<div data-djc-id-a1bc3f>
<div data-djc-id-ca1bc3f>
SLOT_DEFAULT
</div>
hello2
@ -106,7 +106,7 @@ class TestComponentTag:
rendered,
"""
hello1
<div data-djc-id-a1bc3f>
<div data-djc-id-ca1bc3f>
OVERRIDEN!
</div>
hello2
@ -142,7 +142,7 @@ class TestComponentTag:
rendered,
"""
hello1
<div data-djc-id-a1bc3f>
<div data-djc-id-ca1bc3f>
SLOT_DEFAULT
</div>
hello2
@ -180,7 +180,7 @@ class TestComponentTag:
rendered,
"""
hello1
<div data-djc-id-a1bc3f>
<div data-djc-id-ca1bc3f>
OVERRIDEN!
</div>
hello2
@ -216,7 +216,7 @@ class TestComponentTag:
rendered,
"""
hello1
<div data-djc-id-a1bc3f>
<div data-djc-id-ca1bc3f>
SLOT_DEFAULT
</div>
hello2
@ -254,7 +254,7 @@ class TestComponentTag:
rendered,
"""
hello1
<div data-djc-id-a1bc3f>
<div data-djc-id-ca1bc3f>
OVERRIDEN!
</div>
hello2
@ -292,7 +292,7 @@ class TestComponentTag:
rendered,
"""
hello1
<div data-djc-id-a1bc3f>
<div data-djc-id-ca1bc3f>
OVERRIDEN!
</div>
hello2
@ -327,7 +327,7 @@ class TestComponentTag:
assertHTMLEqual(
rendered,
"""
<div data-djc-id-a1bc3f>
<div data-djc-id-ca1bc3f>
OVERRIDEN!
</div>
""",
@ -408,7 +408,7 @@ class TestComponentTag:
rendered,
"""
hello1
<div data-djc-id-a1bc3f>
<div data-djc-id-ca1bc3f>
SLOT_DEFAULT
</div>
hello2
@ -428,7 +428,7 @@ class TestComponentTag:
rendered,
"""
hello1
<div data-djc-id-a1bc42>
<div data-djc-id-ca1bc42>
OVERRIDEN!
</div>
hello2

View file

@ -46,7 +46,7 @@ class TestMultilineTags:
"""
rendered = Template(template).render(Context())
expected = """
Variable: <strong data-djc-id-a1bc3f>123</strong>
Variable: <strong data-djc-id-ca1bc3f>123</strong>
"""
assertHTMLEqual(rendered, expected)
@ -74,7 +74,7 @@ class TestNestedTags:
"""
rendered = Template(template).render(Context())
expected = """
Variable: <strong data-djc-id-a1bc3f>lorem</strong>
Variable: <strong data-djc-id-ca1bc3f>lorem</strong>
"""
assertHTMLEqual(rendered, expected)
@ -88,7 +88,7 @@ class TestNestedTags:
"""
rendered = Template(template).render(Context())
expected = """
Variable: <strong data-djc-id-a1bc3f>organisation&#x27;s</strong>
Variable: <strong data-djc-id-ca1bc3f>organisation&#x27;s</strong>
"""
assertHTMLEqual(rendered, expected)
@ -102,7 +102,7 @@ class TestNestedTags:
"""
rendered = Template(template).render(Context())
expected = """
Variable: <strong data-djc-id-a1bc3f>organisation&#x27;s</strong>
Variable: <strong data-djc-id-ca1bc3f>organisation&#x27;s</strong>
"""
assertHTMLEqual(rendered, expected)
@ -116,7 +116,7 @@ class TestNestedTags:
"""
rendered = Template(template).render(Context())
expected = """
Variable: <strong data-djc-id-a1bc3f>organisation"s</strong>
Variable: <strong data-djc-id-ca1bc3f>organisation"s</strong>
"""
assertHTMLEqual(rendered, expected)
@ -130,6 +130,6 @@ class TestNestedTags:
"""
rendered = Template(template).render(Context())
expected = """
Variable: <strong data-djc-id-a1bc3f>organisation"s</strong>
Variable: <strong data-djc-id-ca1bc3f>organisation"s</strong>
"""
assertHTMLEqual(rendered, expected)

View file

@ -62,7 +62,7 @@ class TestComponentTemplateTag:
template = Template(simple_tag_template)
rendered = template.render(Context({}))
assertHTMLEqual(rendered, "Variable: <strong data-djc-id-a1bc3f>variable</strong>\n")
assertHTMLEqual(rendered, "Variable: <strong data-djc-id-ca1bc3f>variable</strong>\n")
@djc_test(parametrize=PARAMETRIZE_CONTEXT_BEHAVIOR)
def test_single_component_self_closing(self, components_settings):
@ -75,7 +75,7 @@ class TestComponentTemplateTag:
template = Template(simple_tag_template)
rendered = template.render(Context({}))
assertHTMLEqual(rendered, "Variable: <strong data-djc-id-a1bc3f>variable</strong>\n")
assertHTMLEqual(rendered, "Variable: <strong data-djc-id-ca1bc3f>variable</strong>\n")
@djc_test(parametrize=PARAMETRIZE_CONTEXT_BEHAVIOR)
def test_call_with_invalid_name(self, components_settings):
@ -101,7 +101,7 @@ class TestComponentTemplateTag:
template = Template(simple_tag_template)
rendered = template.render(Context({}))
assertHTMLEqual(rendered, "Variable: <strong data-djc-id-a1bc3f>variable</strong>\n")
assertHTMLEqual(rendered, "Variable: <strong data-djc-id-ca1bc3f>variable</strong>\n")
@djc_test(parametrize=PARAMETRIZE_CONTEXT_BEHAVIOR)
def test_call_component_with_two_variables(self, components_settings):
@ -134,8 +134,8 @@ class TestComponentTemplateTag:
assertHTMLEqual(
rendered,
"""
Variable: <strong data-djc-id-a1bc3f>variable</strong>
Variable2: <strong data-djc-id-a1bc3f>hej</strong>
Variable: <strong data-djc-id-ca1bc3f>variable</strong>
Variable2: <strong data-djc-id-ca1bc3f>hej</strong>
""",
)
@ -150,7 +150,7 @@ class TestComponentTemplateTag:
template = Template(simple_tag_template)
rendered = template.render(Context({}))
assertHTMLEqual(rendered, "Variable: <strong data-djc-id-a1bc3f>variable</strong>\n")
assertHTMLEqual(rendered, "Variable: <strong data-djc-id-ca1bc3f>variable</strong>\n")
@djc_test(parametrize=PARAMETRIZE_CONTEXT_BEHAVIOR)
def test_raises_on_component_called_with_variable_as_name(self, components_settings):
@ -191,8 +191,8 @@ class TestComponentTemplateTag:
assertHTMLEqual(
rendered,
"""
Provided variable: <strong data-djc-id-a1bc3f>provided value</strong>
Default: <p data-djc-id-a1bc3f>default text</p>
Provided variable: <strong data-djc-id-ca1bc3f>provided value</strong>
Default: <p data-djc-id-ca1bc3f>default text</p>
""",
)
@ -227,7 +227,7 @@ class TestDynamicComponentTemplateTag:
rendered = template.render(Context({}))
assertHTMLEqual(
rendered,
"Variable: <strong data-djc-id-a1bc3f data-djc-id-a1bc40>variable</strong>",
"Variable: <strong data-djc-id-ca1bc3f data-djc-id-ca1bc40>variable</strong>",
)
@djc_test(parametrize=PARAMETRIZE_CONTEXT_BEHAVIOR)
@ -258,7 +258,7 @@ class TestDynamicComponentTemplateTag:
rendered = template.render(Context({}))
assertHTMLEqual(
rendered,
"Variable: <strong data-djc-id-a1bc3f data-djc-id-a1bc40>variable</strong>",
"Variable: <strong data-djc-id-ca1bc3f data-djc-id-ca1bc40>variable</strong>",
)
@djc_test(parametrize=PARAMETRIZE_CONTEXT_BEHAVIOR)
@ -283,7 +283,7 @@ class TestDynamicComponentTemplateTag:
)
assertHTMLEqual(
rendered,
"Variable: <strong data-djc-id-a1bc3f data-djc-id-a1bc40>variable</strong>",
"Variable: <strong data-djc-id-ca1bc3f data-djc-id-ca1bc40>variable</strong>",
)
@djc_test(parametrize=PARAMETRIZE_CONTEXT_BEHAVIOR)
@ -305,7 +305,7 @@ class TestDynamicComponentTemplateTag:
)
assertHTMLEqual(
rendered,
"Variable: <strong data-djc-id-a1bc3f data-djc-id-a1bc40>variable</strong>",
"Variable: <strong data-djc-id-ca1bc3f data-djc-id-ca1bc40>variable</strong>",
)
@djc_test(
@ -329,7 +329,7 @@ class TestDynamicComponentTemplateTag:
template = Template(simple_tag_template)
rendered = template.render(Context({}))
assertHTMLEqual(rendered, "Variable: <strong data-djc-id-a1bc3f data-djc-id-a1bc40>variable</strong>\n")
assertHTMLEqual(rendered, "Variable: <strong data-djc-id-ca1bc3f data-djc-id-ca1bc40>variable</strong>\n")
@djc_test(
parametrize=PARAMETRIZE_CONTEXT_BEHAVIOR,
@ -355,7 +355,7 @@ class TestDynamicComponentTemplateTag:
rendered = template.render(Context({}))
assertHTMLEqual(
rendered,
"Variable: <strong data-djc-id-a1bc3f data-djc-id-a1bc40>variable</strong>",
"Variable: <strong data-djc-id-ca1bc3f data-djc-id-ca1bc40>variable</strong>",
)
@djc_test(parametrize=PARAMETRIZE_CONTEXT_BEHAVIOR)
@ -397,7 +397,7 @@ class TestDynamicComponentTemplateTag:
assertHTMLEqual(
rendered,
"""
Variable: <strong data-djc-id-a1bc3f data-djc-id-a1bc40>variable</strong>
Variable: <strong data-djc-id-ca1bc3f data-djc-id-ca1bc40>variable</strong>
Slot: HELLO_FROM_SLOT
""",
)
@ -439,7 +439,7 @@ class TestDynamicComponentTemplateTag:
assertHTMLEqual(
rendered,
"""
Variable: <strong data-djc-id-a1bc41 data-djc-id-a1bc42>variable</strong>
Variable: <strong data-djc-id-ca1bc41 data-djc-id-ca1bc42>variable</strong>
Slot 1: HELLO_FROM_SLOT_1
Slot 2: HELLO_FROM_SLOT_2
""",
@ -482,7 +482,7 @@ class TestDynamicComponentTemplateTag:
assertHTMLEqual(
rendered,
"""
Variable: <strong data-djc-id-a1bc41 data-djc-id-a1bc42>variable</strong>
Variable: <strong data-djc-id-ca1bc41 data-djc-id-ca1bc42>variable</strong>
Slot 1: HELLO_FROM_SLOT_1
Slot 2:
""",
@ -527,14 +527,14 @@ class TestMultiComponent:
assertHTMLEqual(
rendered,
"""
<custom-template data-djc-id-a1bc40>
<custom-template data-djc-id-ca1bc40>
<header>
Default header
</header>
<main>Default main</main>
<footer>Default footer</footer>
</custom-template>
<custom-template data-djc-id-a1bc47>
<custom-template data-djc-id-ca1bc47>
<header>
Default header
</header>
@ -564,14 +564,14 @@ class TestMultiComponent:
assertHTMLEqual(
rendered,
"""
<custom-template data-djc-id-a1bc42>
<custom-template data-djc-id-ca1bc42>
<header>
<p>Slot #1</p>
</header>
<main>Default main</main>
<footer>Default footer</footer>
</custom-template>
<custom-template data-djc-id-a1bc49>
<custom-template data-djc-id-ca1bc49>
<header>
<div>Slot #2</div>
</header>
@ -600,14 +600,14 @@ class TestMultiComponent:
assertHTMLEqual(
rendered,
"""
<custom-template data-djc-id-a1bc41>
<custom-template data-djc-id-ca1bc41>
<header>
<p>Slot #1</p>
</header>
<main>Default main</main>
<footer>Default footer</footer>
</custom-template>
<custom-template data-djc-id-a1bc48>
<custom-template data-djc-id-ca1bc48>
<header>
Default header
</header>
@ -636,14 +636,14 @@ class TestMultiComponent:
assertHTMLEqual(
rendered,
"""
<custom-template data-djc-id-a1bc41>
<custom-template data-djc-id-ca1bc41>
<header>
Default header
</header>
<main>Default main</main>
<footer>Default footer</footer>
</custom-template>
<custom-template data-djc-id-a1bc48>
<custom-template data-djc-id-ca1bc48>
<header>
<div>Slot #2</div>
</header>
@ -689,17 +689,17 @@ class TestComponentIsolation:
assertHTMLEqual(
rendered,
"""
<custom-template data-djc-id-a1bc4a>
<custom-template data-djc-id-ca1bc4a>
<header>Override header</header>
<main>Default main</main>
<footer>Default footer</footer>
</custom-template>
<custom-template data-djc-id-a1bc4b>
<custom-template data-djc-id-ca1bc4b>
<header>Default header</header>
<main>Override main</main>
<footer>Default footer</footer>
</custom-template>
<custom-template data-djc-id-a1bc4c>
<custom-template data-djc-id-ca1bc4c>
<header>Default header</header>
<main>Default main</main>
<footer>Override footer</footer>
@ -735,7 +735,7 @@ class TestAggregateInput:
assertHTMLEqual(
rendered,
"""
<div data-djc-id-a1bc3f>
<div data-djc-id-ca1bc3f>
attrs: {'@click.stop': "dispatch('click_event')", 'x-data': "{hello: 'world'}", 'class': 'padding-top-8'}
my_dict: {'one': 2}
</div>

View file

@ -67,8 +67,8 @@ class TestExtendsCompat:
<body>
<main role="main">
<div class='container main-container'>
<div data-djc-id-a1bc40>BLOCK OVERRIDEN</div>
<custom-template data-djc-id-a1bc40>
<div data-djc-id-ca1bc40>BLOCK OVERRIDEN</div>
<custom-template data-djc-id-ca1bc40>
<header>SLOT OVERRIDEN</header>
<main>Default main</main>
<footer>Default footer</footer>
@ -117,14 +117,14 @@ class TestExtendsCompat:
<body>
<main role="main">
<div class='container main-container'>
<div data-djc-id-a1bc42>BLOCK OVERRIDEN</div>
<custom-template data-djc-id-a1bc42>
<div data-djc-id-ca1bc42>BLOCK OVERRIDEN</div>
<custom-template data-djc-id-ca1bc42>
<header>SLOT OVERRIDEN</header>
<main>Default main</main>
<footer>Default footer</footer>
</custom-template>
<div data-djc-id-a1bc46>BLOCK OVERRIDEN</div>
<custom-template data-djc-id-a1bc46>
<div data-djc-id-ca1bc46>BLOCK OVERRIDEN</div>
<custom-template data-djc-id-ca1bc46>
<header>SLOT OVERRIDEN 2</header>
<main>Default main</main>
<footer>Default footer</footer>
@ -184,14 +184,14 @@ class TestExtendsCompat:
<body>
<main role="main">
<div class='container main-container'>
<div data-djc-id-a1bc42>BLOCK OVERRIDEN</div>
<custom-template data-djc-id-a1bc42>
<div data-djc-id-ca1bc42>BLOCK OVERRIDEN</div>
<custom-template data-djc-id-ca1bc42>
<header>SLOT OVERRIDEN</header>
<main>Default main</main>
<footer>Default footer</footer>
</custom-template>
<div data-djc-id-a1bc46>BLOCK OVERRIDEN</div>
<custom-template data-djc-id-a1bc46>
<div data-djc-id-ca1bc46>BLOCK OVERRIDEN</div>
<custom-template data-djc-id-ca1bc46>
<header>SLOT OVERRIDEN 2</header>
<main>Default main</main>
<footer>Default footer</footer>
@ -250,14 +250,14 @@ class TestExtendsCompat:
<body>
<main role="main">
<div class='container main-container'>
<div data-djc-id-a1bc42>BLOCK OVERRIDEN</div>
<custom-template data-djc-id-a1bc42>
<div data-djc-id-ca1bc42>BLOCK OVERRIDEN</div>
<custom-template data-djc-id-ca1bc42>
<header>SLOT OVERRIDEN</header>
<main>Default main</main>
<footer>Default footer</footer>
</custom-template>
<div data-djc-id-a1bc46>BLOCK OVERRIDEN</div>
<custom-template data-djc-id-a1bc46>
<div data-djc-id-ca1bc46>BLOCK OVERRIDEN</div>
<custom-template data-djc-id-ca1bc46>
<header>SLOT OVERRIDEN 2</header>
<main>Default main</main>
<footer>Default footer</footer>
@ -301,8 +301,8 @@ class TestExtendsCompat:
<!DOCTYPE html>
<html lang="en">
<body>
<div data-djc-id-a1bc40>BLOCK OVERRIDEN</div>
<custom-template data-djc-id-a1bc40>
<div data-djc-id-ca1bc40>BLOCK OVERRIDEN</div>
<custom-template data-djc-id-ca1bc40>
<header>SLOT OVERRIDEN</header>
<main>Default main</main>
<footer>Default footer</footer>
@ -349,14 +349,14 @@ class TestExtendsCompat:
<!DOCTYPE html>
<html lang="en">
<body>
<div data-djc-id-a1bc42>BLOCK OVERRIDEN</div>
<custom-template data-djc-id-a1bc42>
<div data-djc-id-ca1bc42>BLOCK OVERRIDEN</div>
<custom-template data-djc-id-ca1bc42>
<header>SLOT OVERRIDEN</header>
<main>Default main</main>
<footer>Default footer</footer>
</custom-template>
<div data-djc-id-a1bc46>BLOCK OVERRIDEN</div>
<custom-template data-djc-id-a1bc46>
<div data-djc-id-ca1bc46>BLOCK OVERRIDEN</div>
<custom-template data-djc-id-ca1bc46>
<header>SLOT OVERRIDEN 2</header>
<main>Default main</main>
<footer>Default footer</footer>
@ -403,11 +403,11 @@ class TestExtendsCompat:
<body>
<main role="main">
<div class='container main-container'>
<custom-template data-djc-id-a1bc42>
<custom-template data-djc-id-ca1bc42>
<header>Default header</header>
<main>
<div data-djc-id-a1bc49>BLOCK OVERRIDEN</div>
<custom-template data-djc-id-a1bc49>
<div data-djc-id-ca1bc49>BLOCK OVERRIDEN</div>
<custom-template data-djc-id-ca1bc49>
<header>SLOT OVERRIDEN</header>
<main>Default main</main>
<footer>Default footer</footer>
@ -449,7 +449,7 @@ class TestExtendsCompat:
<main role="main">
<div class='container main-container'>
Variable: <strong></strong>
Variable: <strong data-djc-id-a1bc3f></strong>
Variable: <strong data-djc-id-ca1bc3f></strong>
</div>
</main>
</body>
@ -459,7 +459,7 @@ class TestExtendsCompat:
# second rendering after cache built
rendered_2 = Template(template).render(Context())
expected_2 = expected.replace("data-djc-id-a1bc3f", "data-djc-id-a1bc41")
expected_2 = expected.replace("data-djc-id-ca1bc3f", "data-djc-id-ca1bc41")
assertHTMLEqual(rendered_2, expected_2)
@djc_test(parametrize=PARAMETRIZE_CONTEXT_BEHAVIOR)
@ -483,9 +483,9 @@ class TestExtendsCompat:
rendered = Template(template).render(Context())
expected = """
<!DOCTYPE html>
<html data-djc-id-a1bc40 lang="en">
<html data-djc-id-ca1bc40 lang="en">
<body>
<custom-template data-djc-id-a1bc45>
<custom-template data-djc-id-ca1bc45>
<header></header>
<main>BODY_FROM_FILL</main>
<footer>Default footer</footer>
@ -516,9 +516,9 @@ class TestExtendsCompat:
rendered = Template(template).render(Context())
expected = """
<!DOCTYPE html>
<html data-djc-id-a1bc40 lang="en">
<html data-djc-id-ca1bc40 lang="en">
<body>
<custom-template data-djc-id-a1bc45>
<custom-template data-djc-id-ca1bc45>
<header></header>
<main>BODY_FROM_FILL</main>
<footer>Default footer</footer>
@ -551,7 +551,7 @@ class TestExtendsCompat:
<body>
<main role="main">
<div class='container main-container'>
<custom-template data-djc-id-a1bc42>
<custom-template data-djc-id-ca1bc42>
<header></header>
<main>TEST</main>
<footer></footer>
@ -580,7 +580,7 @@ class TestExtendsCompat:
<!DOCTYPE html>
<html lang="en">
<body>
<custom-template data-djc-id-a1bc41>
<custom-template data-djc-id-ca1bc41>
<header></header>
<main>
<div> 58 giraffes and 2 pantaloons </div>
@ -607,9 +607,9 @@ class TestExtendsCompat:
rendered = Template(template).render(Context())
expected = """
<!DOCTYPE html>
<html data-djc-id-a1bc3f lang="en">
<html data-djc-id-ca1bc3f lang="en">
<body>
<custom-template data-djc-id-a1bc43>
<custom-template data-djc-id-ca1bc43>
<header></header>
<main>
<div> 58 giraffes and 2 pantaloons </div>
@ -647,9 +647,9 @@ class TestExtendsCompat:
rendered = Template(template).render(Context())
expected = """
<!DOCTYPE html>
<html data-djc-id-a1bc40 lang="en">
<html data-djc-id-ca1bc40 lang="en">
<body>
<custom-template data-djc-id-a1bc49>
<custom-template data-djc-id-ca1bc49>
<header></header>
<main>BODY_FROM_FILL</main>
<footer>Default footer</footer>
@ -677,9 +677,9 @@ class TestExtendsCompat:
rendered = Template(template).render(Context())
expected = """
<!DOCTYPE html>
<html data-djc-id-a1bc3f lang="en">
<html data-djc-id-ca1bc3f lang="en">
<body>
<custom-template data-djc-id-a1bc44>
<custom-template data-djc-id-ca1bc44>
<header></header>
<main>
Helloodiddoo
@ -713,9 +713,9 @@ class TestExtendsCompat:
rendered = Template(template).render(Context())
expected = """
<!DOCTYPE html>
<html data-djc-id-a1bc3f lang="en">
<html data-djc-id-ca1bc3f lang="en">
<body>
<custom-template data-djc-id-a1bc44>
<custom-template data-djc-id-ca1bc44>
<header></header>
<main>
Helloodiddoo
@ -749,9 +749,9 @@ class TestExtendsCompat:
rendered = Template(template).render(Context())
expected = """
<!DOCTYPE html>
<html data-djc-id-a1bc40 lang="en">
<html data-djc-id-ca1bc40 lang="en">
<body>
<custom-template data-djc-id-a1bc45>
<custom-template data-djc-id-ca1bc45>
<header></header>
<main>
Helloodiddoo
@ -795,9 +795,9 @@ class TestExtendsCompat:
rendered = Template(template).render(Context())
expected = """
<!DOCTYPE html>
<html data-djc-id-a1bc41 lang="en">
<html data-djc-id-ca1bc41 lang="en">
<body>
<custom-template data-djc-id-a1bc47>
<custom-template data-djc-id-ca1bc47>
<header></header>
<main>
Helloodiddoo
@ -837,10 +837,10 @@ class TestExtendsCompat:
<!DOCTYPE html>
<html lang="en">
<body>
<custom-template data-djc-id-a1bc44>
<custom-template data-djc-id-ca1bc44>
<header></header>
<main>
<div data-djc-id-a1bc4b> injected: DepInject(hello='from_block') </div>
<div data-djc-id-ca1bc4b> injected: DepInject(hello='from_block') </div>
</main>
<footer>Default footer</footer>
</custom-template>
@ -860,7 +860,7 @@ class TestExtendsCompat:
rendered = Template(template).render(Context())
expected = """
<!DOCTYPE html>
<html data-djc-id-a1bc3f="" lang="en">
<html data-djc-id-ca1bc3f="" lang="en">
<body>
<main role="main">
<div class='container main-container'>
@ -883,7 +883,7 @@ class TestExtendsCompat:
rendered = Template(template).render(Context())
expected = """
<!DOCTYPE html>
<html data-djc-id-a1bc3f="" lang="en">
<html data-djc-id-ca1bc3f="" lang="en">
<body>
<main role="main">
<div class='container main-container'>

View file

@ -46,7 +46,7 @@ class TestProvideTemplateTag:
assertHTMLEqual(
rendered,
"""
<div data-djc-id-a1bc41> injected: DepInject(key='hi', another=1) </div>
<div data-djc-id-ca1bc41> injected: DepInject(key='hi', another=1) </div>
""",
)
self._assert_clear_cache()
@ -99,8 +99,8 @@ class TestProvideTemplateTag:
assertHTMLEqual(
rendered,
"""
<div data-djc-id-a1bc41> key: hi </div>
<div data-djc-id-a1bc41> another: 3 </div>
<div data-djc-id-ca1bc41> key: hi </div>
<div data-djc-id-ca1bc41> another: 3 </div>
""",
)
self._assert_clear_cache()
@ -133,8 +133,8 @@ class TestProvideTemplateTag:
assertHTMLEqual(
rendered,
"""
<div data-djc-id-a1bc41> key: hi </div>
<div data-djc-id-a1bc41> another: 4 </div>
<div data-djc-id-ca1bc41> key: hi </div>
<div data-djc-id-ca1bc41> another: 4 </div>
""",
)
self._assert_clear_cache()
@ -164,7 +164,7 @@ class TestProvideTemplateTag:
assertHTMLEqual(
rendered,
"""
<div data-djc-id-a1bc41> injected: default </div>
<div data-djc-id-ca1bc41> injected: default </div>
""",
)
self._assert_clear_cache()
@ -198,8 +198,8 @@ class TestProvideTemplateTag:
assertHTMLEqual(
rendered,
"""
<div data-djc-id-a1bc42> injected: DepInject() </div>
<div data-djc-id-a1bc43> injected: default </div>
<div data-djc-id-ca1bc42> injected: DepInject() </div>
<div data-djc-id-ca1bc43> injected: default </div>
""",
)
self._assert_clear_cache()
@ -232,8 +232,8 @@ class TestProvideTemplateTag:
assertHTMLEqual(
rendered,
"""
<div data-djc-id-a1bc42></div>
<div data-djc-id-a1bc43></div>
<div data-djc-id-ca1bc42></div>
<div data-djc-id-ca1bc43></div>
""",
)
self._assert_clear_cache()
@ -265,8 +265,8 @@ class TestProvideTemplateTag:
assertHTMLEqual(
rendered,
"""
<div data-djc-id-a1bc42> injected: DepInject(key='hi', another=7) </div>
<div data-djc-id-a1bc43> injected: default </div>
<div data-djc-id-ca1bc42> injected: DepInject(key='hi', another=7) </div>
<div data-djc-id-ca1bc43> injected: default </div>
""",
)
self._assert_clear_cache()
@ -304,8 +304,8 @@ class TestProvideTemplateTag:
assertHTMLEqual(
rendered,
"""
<div data-djc-id-a1bc42> injected: DepInject(key='hi', another=8) </div>
<div data-djc-id-a1bc43> injected: default </div>
<div data-djc-id-ca1bc42> injected: DepInject(key='hi', another=8) </div>
<div data-djc-id-ca1bc43> injected: default </div>
""",
)
self._assert_clear_cache()
@ -347,8 +347,8 @@ class TestProvideTemplateTag:
assertHTMLEqual(
rendered,
"""
<div data-djc-id-a1bc42> injected: DepInject(key='hi', another=9) </div>
<div data-djc-id-a1bc43> injected: default </div>
<div data-djc-id-ca1bc42> injected: DepInject(key='hi', another=9) </div>
<div data-djc-id-ca1bc43> injected: default </div>
""",
)
self._assert_clear_cache()
@ -463,7 +463,7 @@ class TestProvideTemplateTag:
assertHTMLEqual(
rendered,
"""
<div data-djc-id-a1bc41> injected: DepInject(var1={'key': 'hi', 'another': 13}, var2={'x': 'y'}) </div>
<div data-djc-id-ca1bc41> injected: DepInject(var1={'key': 'hi', 'another': 13}, var2={'x': 'y'}) </div>
""",
)
self._assert_clear_cache()
@ -539,9 +539,9 @@ class TestProvideTemplateTag:
assertHTMLEqual(
rendered,
"""
<div data-djc-id-a1bc45> injected: DepInject(key='hi1', another=16, new=3) </div>
<div data-djc-id-a1bc46> injected: DepInject(key='hi', another=15, lost=0) </div>
<div data-djc-id-a1bc47> injected: default </div>
<div data-djc-id-ca1bc45> injected: DepInject(key='hi1', another=16, new=3) </div>
<div data-djc-id-ca1bc46> injected: DepInject(key='hi', another=15, lost=0) </div>
<div data-djc-id-ca1bc47> injected: default </div>
""",
)
@ -581,8 +581,8 @@ class TestProvideTemplateTag:
assertHTMLEqual(
rendered,
"""
<div data-djc-id-a1bc43> first_provide: DepInject(key='hi', another=17, lost=0) </div>
<div data-djc-id-a1bc43> second_provide: DepInject(key='hi1', another=18, new=3) </div>
<div data-djc-id-ca1bc43> first_provide: DepInject(key='hi', another=17, lost=0) </div>
<div data-djc-id-ca1bc43> second_provide: DepInject(key='hi1', another=18, new=3) </div>
""",
)
self._assert_clear_cache()
@ -612,7 +612,7 @@ class TestProvideTemplateTag:
rendered,
"""
<div>
<div data-djc-id-a1bc41> injected: DepInject(key='hi', another=19) </div>
<div data-djc-id-ca1bc41> injected: DepInject(key='hi', another=19) </div>
</div>
""",
)
@ -651,7 +651,7 @@ class TestProvideTemplateTag:
assertHTMLEqual(
rendered,
"""
<div data-djc-id-a1bc40 data-djc-id-a1bc44>
<div data-djc-id-ca1bc40 data-djc-id-ca1bc44>
injected: DepInject(key='hi', another=20)
</div>
""",
@ -691,7 +691,7 @@ class TestInject:
assertHTMLEqual(
rendered,
"""
<div data-djc-id-a1bc41> injected: DepInject(key='hi', another=21) </div>
<div data-djc-id-ca1bc41> injected: DepInject(key='hi', another=21) </div>
""",
)
self._assert_clear_cache()
@ -742,7 +742,7 @@ class TestInject:
assertHTMLEqual(
rendered,
"""
<div data-djc-id-a1bc3f> injected: default </div>
<div data-djc-id-ca1bc3f> injected: default </div>
""",
)
self._assert_clear_cache()
@ -852,10 +852,10 @@ class TestInject:
assertHTMLEqual(
rendered,
"""
<div data-djc-id-a1bc3e data-djc-id-a1bc41 data-djc-id-a1bc45 data-djc-id-a1bc49>
<div data-djc-id-ca1bc3e data-djc-id-ca1bc41 data-djc-id-ca1bc45 data-djc-id-ca1bc49>
injected: DepInject(key='hi', data=123)
</div>
<main data-djc-id-a1bc3e data-djc-id-a1bc41 data-djc-id-a1bc45 data-djc-id-a1bc49>
<main data-djc-id-ca1bc3e data-djc-id-ca1bc41 data-djc-id-ca1bc45 data-djc-id-ca1bc49>
456
</main>
""",
@ -917,10 +917,10 @@ class TestInject:
assertHTMLEqual(
rendered,
"""
<div data-djc-id-a1bc3e data-djc-id-a1bc41 data-djc-id-a1bc44 data-djc-id-a1bc48>
<div data-djc-id-ca1bc3e data-djc-id-ca1bc41 data-djc-id-ca1bc44 data-djc-id-ca1bc48>
injected: DepInject(key='hi', data=123)
</div>
<main data-djc-id-a1bc3e data-djc-id-a1bc41 data-djc-id-a1bc44 data-djc-id-a1bc48>
<main data-djc-id-ca1bc3e data-djc-id-ca1bc41 data-djc-id-ca1bc44 data-djc-id-ca1bc48>
</main>
""",
)
@ -972,10 +972,10 @@ class TestProvideCache:
assertHTMLEqual(
rendered,
"""
<div data-djc-id-a1bc41>
<div data-djc-id-ca1bc41>
injected: DepInject(key='hi', another=23)
</div>
<div data-djc-id-a1bc41>
<div data-djc-id-ca1bc41>
Ran: True
</div>
""",
@ -1044,10 +1044,10 @@ class TestProvideCache:
assertHTMLEqual(
rendered,
"""
<div data-djc-id-a1bc3e data-djc-id-a1bc42>
<div data-djc-id-ca1bc3e data-djc-id-ca1bc42>
injected: DepInject(key='hi', another=25)
</div>
<div data-djc-id-a1bc3e data-djc-id-a1bc42>
<div data-djc-id-ca1bc3e data-djc-id-ca1bc42>
Ran: True
</div>
""",

View file

@ -67,10 +67,10 @@ class TestComponentSlot:
assertHTMLEqual(
rendered,
"""
<custom-template data-djc-id-a1bc42>
<custom-template data-djc-id-ca1bc42>
<header>Custom header</header>
<main>
Variable: <strong data-djc-id-a1bc46>variable</strong>
Variable: <strong data-djc-id-ca1bc46>variable</strong>
</main>
<footer>Default footer</footer>
</custom-template>
@ -119,9 +119,9 @@ class TestComponentSlot:
assertHTMLEqual(
rendered,
"""
<custom-template data-djc-id-a1bc43>
<custom-template data-djc-id-ca1bc43>
<header>
Variable: <strong data-djc-id-a1bc47>variable</strong>
Variable: <strong data-djc-id-ca1bc47>variable</strong>
</header>
<main></main>
<footer></footer>
@ -174,7 +174,7 @@ class TestComponentSlot:
assertHTMLEqual(
rendered,
f"""
<custom-template data-djc-id-a1bc41>
<custom-template data-djc-id-ca1bc41>
<header>Default header</header>
<main>test123 - {expected} </main>
<footer>test321</footer>
@ -196,7 +196,7 @@ class TestComponentSlot:
assertHTMLEqual(
rendered,
"""
<custom-template data-djc-id-a1bc3f>
<custom-template data-djc-id-ca1bc3f>
<header>Default header</header>
<main>Default main</main>
<footer>Default footer</footer>
@ -219,7 +219,7 @@ class TestComponentSlot:
template = Template(template_str)
rendered = template.render(Context({}))
assertHTMLEqual(rendered, "<custom-template data-djc-id-a1bc3f></custom-template>")
assertHTMLEqual(rendered, "<custom-template data-djc-id-ca1bc3f></custom-template>")
@djc_test(parametrize=PARAMETRIZE_CONTEXT_BEHAVIOR)
def test_slotted_template_without_slots_and_single_quotes(self, components_settings):
@ -236,7 +236,7 @@ class TestComponentSlot:
template = Template(template_str)
rendered = template.render(Context({}))
assertHTMLEqual(rendered, "<custom-template data-djc-id-a1bc3f></custom-template>")
assertHTMLEqual(rendered, "<custom-template data-djc-id-ca1bc3f></custom-template>")
@djc_test(parametrize=PARAMETRIZE_CONTEXT_BEHAVIOR)
def test_variable_fill_name(self, components_settings):
@ -252,7 +252,7 @@ class TestComponentSlot:
template = Template(template_str)
rendered = template.render(Context({}))
expected = """
<custom-template data-djc-id-a1bc40>
<custom-template data-djc-id-ca1bc40>
<header>Hi there!</header>
<main>Default main</main>
<footer>Default footer</footer>
@ -321,7 +321,7 @@ class TestComponentSlot:
rendered,
"""
<body>
<div data-djc-id-a1bc3f>
<div data-djc-id-ca1bc3f>
<main> ABC: carl var </main>
</div>
</body>
@ -352,7 +352,7 @@ class TestComponentSlot:
assertHTMLEqual(
rendered,
"""
<div data-djc-id-a1bc40>
<div data-djc-id-ca1bc40>
<h1> Custom title </h1>
<h2> Default subtitle </h2>
</div>
@ -482,8 +482,8 @@ class TestComponentSlot:
render_dependencies=False,
)
assertHTMLEqual(rendered1, "<div data-djc-id-a1bc3e><div>MAIN</div></div>")
assertHTMLEqual(rendered2, "<div data-djc-id-a1bc41><div>MAIN</div></div>")
assertHTMLEqual(rendered1, "<div data-djc-id-ca1bc3e><div>MAIN</div></div>")
assertHTMLEqual(rendered2, "<div data-djc-id-ca1bc41><div>MAIN</div></div>")
# 3. Specify the required slot by its name
rendered3 = TestComp.render(
@ -493,7 +493,7 @@ class TestComponentSlot:
},
render_dependencies=False,
)
assertHTMLEqual(rendered3, "<div data-djc-id-a1bc42><main>MAIN</main><div>MAIN</div></div>")
assertHTMLEqual(rendered3, "<div data-djc-id-ca1bc42><main>MAIN</main><div>MAIN</div></div>")
# 4. RAISES: Specify the required slot by the "default" name
# This raises because the slot that is marked as 'required' is NOT marked as 'default'.
@ -530,7 +530,7 @@ class TestComponentSlot:
rendered = Template(template_str).render(Context({}))
expected = """
<custom-template data-djc-id-a1bc42>
<custom-template data-djc-id-ca1bc42>
<header>Custom header</header>
<main>Custom main</main>
<footer>Custom footer</footer>
@ -585,7 +585,7 @@ class TestComponentSlotDefault:
template = Template(template_str)
expected = """
<div data-djc-id-a1bc3f>
<div data-djc-id-ca1bc3f>
<main>
<p>This fills the 'main' slot.</p>
</main>
@ -613,7 +613,7 @@ class TestComponentSlotDefault:
"""
template = Template(template_str)
expected = """
<div data-djc-id-a1bc40>
<div data-djc-id-ca1bc40>
<main>
<p>This fills the 'main' slot.</p>
</main>
@ -642,7 +642,7 @@ class TestComponentSlotDefault:
"""
template = Template(template_str)
expected = """
<div data-djc-id-a1bc40>
<div data-djc-id-ca1bc40>
<main><p>This fills the 'main' slot.</p></main>
<div><p>This fills the 'main' slot.</p></div>
</div>
@ -728,9 +728,9 @@ class TestComponentSlotDefault:
"""
template = Template(template_str)
expected = """
<div data-djc-id-a1bc43>
<div data-djc-id-ca1bc43>
<main>
<custom-template data-djc-id-a1bc45>
<custom-template data-djc-id-ca1bc45>
<header>This Is Allowed</header>
<main></main>
<footer></footer>
@ -792,7 +792,7 @@ class TestComponentSlotDefault:
assertHTMLEqual(
rendered,
"""
<div data-djc-id-a1bc3f>
<div data-djc-id-ca1bc3f>
<main><p>Main Content</p></main>
</div>
""",
@ -812,7 +812,7 @@ class TestComponentSlotDefault:
assertHTMLEqual(
rendered,
"""
<custom-template data-djc-id-a1bc3f>
<custom-template data-djc-id-ca1bc3f>
<header>Default header</header>
<main>Default main</main>
<footer>Default footer</footer>
@ -850,7 +850,7 @@ class TestComponentSlotDefault:
assertHTMLEqual(
rendered_truthy,
"""
<custom-template data-djc-id-a1bc3f>
<custom-template data-djc-id-ca1bc3f>
<header>123</header>
<main>Default main</main>
<footer>Default footer</footer>
@ -862,7 +862,7 @@ class TestComponentSlotDefault:
assertHTMLEqual(
rendered_falsy,
"""
<custom-template data-djc-id-a1bc43>
<custom-template data-djc-id-ca1bc43>
<main>Default main</main>
<footer>Default footer</footer>
</custom-template>
@ -914,7 +914,7 @@ class TestPassthroughSlots:
assertHTMLEqual(
rendered,
"""
<custom-template data-djc-id-a1bc41>
<custom-template data-djc-id-ca1bc41>
<header>
OVERRIDEN_SLOT "header" - INDEX 0 - ORIGINAL "Default header"
</header>
@ -962,7 +962,7 @@ class TestPassthroughSlots:
assertHTMLEqual(
rendered,
"""
<custom-template data-djc-id-a1bc40>
<custom-template data-djc-id-ca1bc40>
<header>
OVERRIDEN_SLOT "header" - ORIGINAL "Default header"
</header>
@ -1052,9 +1052,9 @@ class TestPassthroughSlots:
rendered = template.render(Context())
expected = """
<div data-djc-id-a1bc41>CUSTOM HEADER</div>
<div data-djc-id-a1bc41>CUSTOM MAIN</div>
<div data-djc-id-a1bc41>footer</div>
<div data-djc-id-ca1bc41>CUSTOM HEADER</div>
<div data-djc-id-ca1bc41>CUSTOM MAIN</div>
<div data-djc-id-ca1bc41>footer</div>
"""
assertHTMLEqual(rendered, expected)
@ -1097,8 +1097,8 @@ class TestPassthroughSlots:
rendered = template.render(Context())
expected = """
<div data-djc-id-a1bc41>
<custom-template data-djc-id-a1bc45>
<div data-djc-id-ca1bc41>
<custom-template data-djc-id-ca1bc45>
<header>CUSTOM HEADER</header>
<main>CUSTOM MAIN</main>
<footer>Default footer</footer>
@ -1148,8 +1148,8 @@ class TestPassthroughSlots:
rendered = template.render(Context())
expected = """
<div data-djc-id-a1bc41>
<custom-template data-djc-id-a1bc45>
<div data-djc-id-ca1bc41>
<custom-template data-djc-id-ca1bc45>
<header>Default header</header>
<main>CUSTOM MAIN</main>
<footer>Default footer</footer>
@ -1200,7 +1200,7 @@ class TestNestedSlots:
rendered = Template(template_str).render(Context())
expected = """
<div data-djc-id-a1bc3f>
<div data-djc-id-ca1bc3f>
Wrapper Default
<div>
Parent1 Default
@ -1231,7 +1231,7 @@ class TestNestedSlots:
rendered = Template(template_str).render(Context())
expected = """
<div data-djc-id-a1bc40>
<div data-djc-id-ca1bc40>
Entire Wrapper Replaced
</div>
"""
@ -1253,7 +1253,7 @@ class TestNestedSlots:
rendered = Template(template_str).render(Context())
expected = """
<div data-djc-id-a1bc40>
<div data-djc-id-ca1bc40>
Wrapper Default
<div>
Parent1 Replaced
@ -1281,7 +1281,7 @@ class TestNestedSlots:
rendered = Template(template_str).render(Context())
expected = """
<div data-djc-id-a1bc40>
<div data-djc-id-ca1bc40>
Wrapper Default
<div>
Parent1 Default
@ -1322,7 +1322,7 @@ class TestNestedSlots:
rendered = Template(template_str).render(Context())
expected = """
<div data-djc-id-a1bc42>
<div data-djc-id-ca1bc42>
Entire Wrapper Replaced
</div>
"""
@ -1355,7 +1355,7 @@ class TestSlottedTemplateRegression:
assertHTMLEqual(
rendered,
"""
<custom-template data-djc-id-a1bc3f>
<custom-template data-djc-id-ca1bc3f>
<header>Default header</header>
<main>Default main</main>
<footer>Default footer</footer>
@ -1383,7 +1383,7 @@ class TestSlotDefault:
assertHTMLEqual(
rendered,
"""
<custom-template data-djc-id-a1bc42>
<custom-template data-djc-id-ca1bc42>
<header>Before: Default header</header>
<main>Default main</main>
<footer>Default footer, after</footer>
@ -1409,7 +1409,7 @@ class TestSlotDefault:
assertHTMLEqual(
rendered,
"""
<custom-template data-djc-id-a1bc40>
<custom-template data-djc-id-ca1bc40>
<header>First: Default header; Second: Default header</header>
<main>Default main</main>
<footer>Default footer</footer>
@ -1440,7 +1440,7 @@ class TestSlotDefault:
assertHTMLEqual(
rendered,
"""
<custom-template data-djc-id-a1bc40>
<custom-template data-djc-id-ca1bc40>
<header>First Default header Later Default header Later Default header</header>
<main>Default main</main>
<footer>Default footer</footer>
@ -1475,10 +1475,10 @@ class TestSlotDefault:
assertHTMLEqual(
rendered,
"""
<custom-template data-djc-id-a1bc43>
<custom-template data-djc-id-ca1bc43>
<header>
header1_in_header1: Default header
<custom-template data-djc-id-a1bc47>
<custom-template data-djc-id-ca1bc47>
<header>
header1_in_header2: Default header
header2_in_header2: Default header
@ -1527,7 +1527,7 @@ class TestScopedSlot:
"""
rendered = Template(template).render(Context())
expected = """
<div data-djc-id-a1bc40>
<div data-djc-id-ca1bc40>
def
456
</div>
@ -1562,7 +1562,7 @@ class TestScopedSlot:
"""
rendered = Template(template).render(Context())
expected = """
<div data-djc-id-a1bc40>
<div data-djc-id-ca1bc40>
def
456
</div>
@ -1598,7 +1598,7 @@ class TestScopedSlot:
"""
rendered = Template(template).render(Context())
expected = """
<div data-djc-id-a1bc40>
<div data-djc-id-ca1bc40>
Default text
def
456
@ -1635,7 +1635,7 @@ class TestScopedSlot:
"""
rendered = Template(template).render(Context())
expected = """
<div data-djc-id-a1bc40>
<div data-djc-id-ca1bc40>
def
456
</div>
@ -1673,7 +1673,7 @@ class TestScopedSlot:
"""
rendered = Template(template).render(Context())
expected = """
<div data-djc-id-a1bc40>
<div data-djc-id-ca1bc40>
def
456
</div>
@ -1710,7 +1710,7 @@ class TestScopedSlot:
"""
rendered = Template(template).render(Context())
expected = """
<div data-djc-id-a1bc40>
<div data-djc-id-ca1bc40>
<b>Default text A</b>
<b>xyz Default text B 456</b>
</div>
@ -1774,7 +1774,7 @@ class TestScopedSlot:
{% endcomponent %}
"""
rendered = Template(template).render(Context())
expected = "<div data-djc-id-a1bc40> overriden </div>"
expected = "<div data-djc-id-ca1bc40> overriden </div>"
assertHTMLEqual(rendered, expected)
@djc_test(parametrize=PARAMETRIZE_CONTEXT_BEHAVIOR)
@ -1797,7 +1797,7 @@ class TestScopedSlot:
{% endcomponent %}
"""
rendered = Template(template).render(Context())
expected = "<div data-djc-id-a1bc40> {} </div>"
expected = "<div data-djc-id-ca1bc40> {} </div>"
assertHTMLEqual(rendered, expected)
@djc_test(parametrize=PARAMETRIZE_CONTEXT_BEHAVIOR)
@ -1823,7 +1823,7 @@ class TestScopedSlot:
{% endcomponent %}
"""
rendered = Template(template).render(Context())
expected = "<div data-djc-id-a1bc3f> Default text </div>"
expected = "<div data-djc-id-ca1bc3f> Default text </div>"
assertHTMLEqual(rendered, expected)
@djc_test(parametrize=PARAMETRIZE_CONTEXT_BEHAVIOR)
@ -1862,7 +1862,7 @@ class TestScopedSlot:
)
expected = """
<div data-djc-id-a1bc40>
<div data-djc-id-ca1bc40>
def
456
</div>
@ -1907,7 +1907,7 @@ class TestScopedSlot:
)
expected = """
<div data-djc-id-a1bc40>
<div data-djc-id-ca1bc40>
def
456
</div>
@ -1951,9 +1951,9 @@ class TestScopedSlot:
assertHTMLEqual(
rendered,
"""
<div data-djc-id-a1bc42>
<div data-djc-id-ca1bc42>
data1_in_slot1: {'abc': 'def', 'input': 1}
<div data-djc-id-a1bc44>
<div data-djc-id-ca1bc44>
data1_in_slot2: {'abc': 'def', 'input': 1}
data2_in_slot2: {'abc': 'def', 'input': 2}
</div>
@ -2060,9 +2060,9 @@ class TestDuplicateSlot:
assertHTMLEqual(
rendered,
"""
<header data-djc-id-a1bc41>Name: Jannete</header>
<main data-djc-id-a1bc41>Name: Jannete</main>
<footer data-djc-id-a1bc41>Hello</footer>
<header data-djc-id-ca1bc41>Name: Jannete</header>
<main data-djc-id-ca1bc41>Name: Jannete</main>
<footer data-djc-id-ca1bc41>Hello</footer>
""",
)
@ -2083,9 +2083,9 @@ class TestDuplicateSlot:
assertHTMLEqual(
rendered,
"""
<header data-djc-id-a1bc3f>Default header</header>
<main data-djc-id-a1bc3f>Default main header</main>
<footer data-djc-id-a1bc3f>Default footer</footer>
<header data-djc-id-ca1bc3f>Default header</header>
<main data-djc-id-ca1bc3f>Default main header</main>
<footer data-djc-id-ca1bc3f>Default footer</footer>
""",
)
@ -2110,8 +2110,8 @@ class TestDuplicateSlot:
rendered,
"""
OVERRIDDEN!
<div class="dashboard-component" data-djc-id-a1bc40>
<div class="calendar-component" data-djc-id-a1bc47>
<div class="dashboard-component" data-djc-id-ca1bc40>
<div class="calendar-component" data-djc-id-ca1bc47>
<h1>
OVERRIDDEN!
</h1>
@ -2150,8 +2150,8 @@ class TestDuplicateSlot:
rendered,
"""
START
<div class="dashboard-component" data-djc-id-a1bc3f>
<div class="calendar-component" data-djc-id-a1bc46>
<div class="dashboard-component" data-djc-id-ca1bc3f>
<div class="calendar-component" data-djc-id-ca1bc46>
<h1>
NESTED
</h1>
@ -2281,11 +2281,11 @@ class TestSlotBehavior:
assertHTMLEqual(
rendered,
"""
<custom-template data-djc-id-a1bc45>
<custom-template data-djc-id-ca1bc45>
<header>Name: Igor</header>
<main>Day: Monday</main>
<footer>
<custom-template data-djc-id-a1bc49>
<custom-template data-djc-id-ca1bc49>
<header>Name2: Joe2</header>
<main>Day2: Monday</main>
<footer>Default footer</footer>
@ -2300,11 +2300,11 @@ class TestSlotBehavior:
assertHTMLEqual(
rendered2,
"""
<custom-template data-djc-id-a1bc4a>
<custom-template data-djc-id-ca1bc4a>
<header>Name: Igor</header>
<main>Day: Monday</main>
<footer>
<custom-template data-djc-id-a1bc4b>
<custom-template data-djc-id-ca1bc4b>
<header>Name2: Joe2</header>
<main>Day2: Monday</main>
<footer>Default footer</footer>
@ -2322,11 +2322,11 @@ class TestSlotBehavior:
assertHTMLEqual(
rendered,
"""
<custom-template data-djc-id-a1bc45>
<custom-template data-djc-id-ca1bc45>
<header>Name: Jannete</header>
<main>Day: Monday</main>
<footer>
<custom-template data-djc-id-a1bc49>
<custom-template data-djc-id-ca1bc49>
<header>Name2: Jannete</header>
<main>Day2: Monday</main>
<footer>Default footer</footer>
@ -2341,11 +2341,11 @@ class TestSlotBehavior:
assertHTMLEqual(
rendered2,
"""
<custom-template data-djc-id-a1bc4a>
<custom-template data-djc-id-ca1bc4a>
<header>Name: </header>
<main>Day: Monday</main>
<footer>
<custom-template data-djc-id-a1bc4b>
<custom-template data-djc-id-ca1bc4b>
<header>Name2: </header>
<main>Day2: Monday</main>
<footer>Default footer</footer>

View file

@ -36,7 +36,7 @@ class TestNestedSlot:
"""
template = Template(template_str)
rendered = template.render(Context({}))
assertHTMLEqual(rendered, '<div id="outer" data-djc-id-a1bc3f>Default</div>')
assertHTMLEqual(rendered, '<div id="outer" data-djc-id-ca1bc3f>Default</div>')
@djc_test(parametrize=PARAMETRIZE_CONTEXT_BEHAVIOR)
def test_inner_slot_overriden(self, components_settings):
@ -50,7 +50,7 @@ class TestNestedSlot:
"""
template = Template(template_str)
rendered = template.render(Context({}))
assertHTMLEqual(rendered, '<div id="outer" data-djc-id-a1bc40>Override</div>')
assertHTMLEqual(rendered, '<div id="outer" data-djc-id-ca1bc40>Override</div>')
@djc_test(parametrize=PARAMETRIZE_CONTEXT_BEHAVIOR)
def test_outer_slot_overriden(self, components_settings):
@ -62,7 +62,7 @@ class TestNestedSlot:
"""
template = Template(template_str)
rendered = template.render(Context({}))
assertHTMLEqual(rendered, "<p data-djc-id-a1bc40>Override</p>")
assertHTMLEqual(rendered, "<p data-djc-id-ca1bc40>Override</p>")
@djc_test(parametrize=PARAMETRIZE_CONTEXT_BEHAVIOR)
def test_both_overriden_and_inner_removed(self, components_settings):
@ -77,7 +77,7 @@ class TestNestedSlot:
"""
template = Template(template_str)
rendered = template.render(Context({}))
assertHTMLEqual(rendered, "<p data-djc-id-a1bc41>Override</p>")
assertHTMLEqual(rendered, "<p data-djc-id-ca1bc41>Override</p>")
# NOTE: Second arg in tuple is expected name in nested fill. In "django" mode,
# the value should be overridden by the component, while in "isolated" it should
@ -138,9 +138,9 @@ class TestNestedSlot:
assertHTMLEqual(
rendered,
f"""
<custom-template data-djc-id-a1bc45>
<custom-template data-djc-id-ca1bc45>
<header>
<custom-template data-djc-id-a1bc49>
<custom-template data-djc-id-ca1bc49>
<header>Name2: {expected}</header>
<main>Day2: Monday</main>
<footer>XYZ</footer>
@ -200,8 +200,8 @@ class TestConditionalSlot:
assertHTMLEqual(
rendered,
"""
<p id="a" data-djc-id-a1bc40>Default A</p>
<p id="b" data-djc-id-a1bc43>Default B</p>
<p id="a" data-djc-id-ca1bc40>Default A</p>
<p id="b" data-djc-id-ca1bc43>Default B</p>
""",
)
@ -222,8 +222,8 @@ class TestConditionalSlot:
assertHTMLEqual(
rendered,
"""
<p id="a" data-djc-id-a1bc42>Default A</p>
<p id="b" data-djc-id-a1bc45>Override B</p>
<p id="a" data-djc-id-ca1bc42>Default A</p>
<p id="b" data-djc-id-ca1bc45>Override B</p>
""",
)
@ -246,8 +246,8 @@ class TestConditionalSlot:
assertHTMLEqual(
rendered,
"""
<p id="a" data-djc-id-a1bc44>Override A</p>
<p id="b" data-djc-id-a1bc47>Override B</p>
<p id="a" data-djc-id-ca1bc44>Override A</p>
<p id="b" data-djc-id-ca1bc47>Override B</p>
""",
)
@ -696,11 +696,11 @@ class TestComponentNesting:
assertHTMLEqual(
rendered,
f"""
<custom-template data-djc-id-a1bc45>
<custom-template data-djc-id-ca1bc45>
<header>Name: {first_name}</header>
<main>Day: Monday</main>
<footer>
<custom-template data-djc-id-a1bc49>
<custom-template data-djc-id-ca1bc49>
<header>Name2: {second_name}</header>
<main>Day2: Monday</main>
<footer>Default footer</footer>
@ -732,8 +732,8 @@ class TestComponentNesting:
template = Template(template_str)
rendered = template.render(Context({"items": [1, 2, 3]}))
expected = f"""
<div class="dashboard-component" data-djc-id-a1bc3f>
<div class="calendar-component" data-djc-id-a1bc44>
<div class="dashboard-component" data-djc-id-ca1bc3f>
<div class="calendar-component" data-djc-id-ca1bc44>
<h1>
Welcome to your dashboard!
</h1>
@ -774,8 +774,8 @@ class TestComponentNesting:
template = Template(template_str)
rendered = template.render(Context({"items": [1, 2, 3]}))
expected = f"""
<div class="dashboard-component" data-djc-id-a1bc40>
<div class="calendar-component" data-djc-id-a1bc45>
<div class="dashboard-component" data-djc-id-ca1bc40>
<div class="calendar-component" data-djc-id-ca1bc45>
<h1>
Whoa!
</h1>
@ -830,14 +830,14 @@ class TestComponentNesting:
expected = """
ITEMS: [{'value': 1}, {'value': 2}, {'value': 3}]
<li data-djc-id-a1bc3f>
<div data-djc-id-a1bc41> 1 </div>
<li data-djc-id-ca1bc3f>
<div data-djc-id-ca1bc41> 1 </div>
</li>
<li data-djc-id-a1bc3f>
<div data-djc-id-a1bc43> 2 </div>
<li data-djc-id-ca1bc3f>
<div data-djc-id-ca1bc43> 2 </div>
</li>
<li data-djc-id-a1bc3f>
<div data-djc-id-a1bc44> 3 </div>
<li data-djc-id-ca1bc3f>
<div data-djc-id-ca1bc44> 3 </div>
</li>
"""
assertHTMLEqual(rendered, expected)
@ -917,7 +917,7 @@ class TestComponentNesting:
expected = """
<!DOCTYPE html>
<html lang="en" data-djc-id-a1bc3e data-djc-id-a1bc43 data-djc-id-a1bc47><head>
<html lang="en" data-djc-id-ca1bc3e data-djc-id-ca1bc43 data-djc-id-ca1bc47><head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
@ -974,8 +974,8 @@ class TestComponentNesting:
template = Template(template_str)
rendered = template.render(Context({"items": [1, 2]}))
expected = f"""
<div class="dashboard-component" data-djc-id-a1bc40>
<div class="calendar-component" data-djc-id-a1bc45>
<div class="dashboard-component" data-djc-id-ca1bc40>
<div class="calendar-component" data-djc-id-ca1bc45>
<h1>
Hello! Welcome to your dashboard!
</h1>