Deployed c66bd212 to 0.142.3 with MkDocs 1.6.1 and mike 2.1.3

This commit is contained in:
github-actions 2025-10-17 09:18:07 +00:00
parent b1b1e8e855
commit c949bd5afa
458 changed files with 47021 additions and 3 deletions

View file

@ -0,0 +1,34 @@
from typing import NamedTuple
from django_components import Component, register, types
DESCRIPTION = "100 nested components? Not a problem! Handle recursive rendering out of the box."
@register("recursion")
class Recursion(Component):
class Kwargs(NamedTuple):
current_depth: int = 0
def get_template_data(self, args, kwargs: Kwargs, slots, context):
current_depth = kwargs.current_depth
return {
"current_depth": current_depth,
"next_depth": current_depth + 1,
}
template: types.django_html = """
{% load component_tags %}
<div class="py-4 border-l-2 border-gray-300 ml-1">
{% if current_depth < 100 %}
<p class="text-sm text-gray-600">
Recursion depth: {{ current_depth }}
</p>
{% component "recursion" current_depth=next_depth / %}
{% else %}
<p class="text-sm font-semibold text-green-600">
Reached maximum recursion depth!
</p>
{% endif %}
</div>
"""

Binary file not shown.

After

Width:  |  Height:  |  Size: 85 KiB

File diff suppressed because one or more lines are too long

View file

@ -0,0 +1,35 @@
from django.http import HttpRequest, HttpResponse
from django.utils.safestring import mark_safe
from django_components import Component, types
class RecursionPage(Component):
class Media:
js = (
mark_safe(
'<script src="https://cdn.tailwindcss.com?plugins=forms,typography,aspect-ratio,line-clamp,container-queries"></script>'
),
)
template: types.django_html = """
{% load component_tags %}
<html>
<head>
<title>Recursion Example</title>
</head>
<body class="bg-gray-100 p-8">
<div class="max-w-4xl mx-auto bg-white p-6 rounded-lg shadow-md">
<h1 class="text-2xl font-bold mb-4">Recursion</h1>
<p class="text-gray-600 mb-6">
Django components easily handles even deeply nested components.
</p>
{% component "recursion" / %}
</div>
</body>
</html>
"""
class View:
def get(self, request: HttpRequest) -> HttpResponse:
return RecursionPage.render_to_response(request=request)

View file

@ -0,0 +1,29 @@
import pytest
from django.template import Context, Template
from django_components import registry, types
from django_components.testing import djc_test
def _import_components():
from docs.examples.recursion.component import Recursion # noqa: PLC0415
registry.register("recursion", Recursion)
@pytest.mark.django_db
@djc_test
class TestRecursion:
def test_renders_recursively(self):
_import_components()
template_str: types.django_html = """
{% load component_tags %}
{% component "recursion" / %}
"""
template = Template(template_str)
rendered = template.render(Context({}))
# Expect 101 levels of depth (0 to 100)
assert rendered.count("Recursion depth:") == 100
assert "Reached maximum recursion depth!" in rendered