From 824dcc7950f39f8bbd84109afc798c32b11544d0 Mon Sep 17 00:00:00 2001
From: Archmonger <16909269+Archmonger@users.noreply.github.com>
Date: Sat, 24 Jun 2023 21:05:18 -0700
Subject: [PATCH 01/14] Write `
` into raw HTML
---
tests/test_app/components.py | 68 ++++---------------
tests/test_app/templates/base.html | 34 +++++++++-
.../test_app/templates/view_to_component.html | 2 +-
3 files changed, 48 insertions(+), 56 deletions(-)
diff --git a/tests/test_app/components.py b/tests/test_app/components.py
index 6dddefaf..433bd9e4 100644
--- a/tests/test_app/components.py
+++ b/tests/test_app/components.py
@@ -26,7 +26,7 @@
@component
def hello_world():
- return html._(html.div({"id": "hello-world"}, "Hello World!"), html.hr())
+ return html._(html.div({"id": "hello-world"}, "Hello World!"))
@component
@@ -42,8 +42,7 @@ def button():
html.p(
{"id": "counter-num", "data-count": count}, f"Current count is: {count}"
),
- ),
- html.hr(),
+ )
)
@@ -54,8 +53,7 @@ def parameterized_component(x, y):
html.div(
{"id": "parametrized-component", "data-value": total},
f"parameterized_component: {total}",
- ),
- html.hr(),
+ )
)
@@ -66,8 +64,7 @@ def object_in_templatetag(my_object: TestObject):
return html._(
html.div(
{"id": co_name, "data-success": success}, f"{co_name}: ", str(my_object)
- ),
- html.hr(),
+ )
)
@@ -82,11 +79,7 @@ def object_in_templatetag(my_object: TestObject):
@component
def simple_button():
- return html._(
- "simple_button:",
- SimpleButton({"id": "simple-button"}),
- html.hr(),
- )
+ return html._("simple_button:", SimpleButton({"id": "simple-button"}))
@component
@@ -100,9 +93,7 @@ def use_connection():
and getattr(ws.carrier, "dotted_path", None)
)
return html.div(
- {"id": "use-connection", "data-success": success},
- f"use_connection: {ws}",
- html.hr(),
+ {"id": "use-connection", "data-success": success}, f"use_connection: {ws}"
)
@@ -110,9 +101,7 @@ def use_connection():
def use_scope():
scope = reactpy_django.hooks.use_scope()
success = len(scope) >= 10 and scope["type"] == "websocket"
- return html.div(
- {"id": "use-scope", "data-success": success}, f"use_scope: {scope}", html.hr()
- )
+ return html.div({"id": "use-scope", "data-success": success}, f"use_scope: {scope}")
@component
@@ -120,9 +109,7 @@ def use_location():
location = reactpy_django.hooks.use_location()
success = bool(location)
return html.div(
- {"id": "use-location", "data-success": success},
- f"use_location: {location}",
- html.hr(),
+ {"id": "use-location", "data-success": success}, f"use_location: {location}"
)
@@ -131,9 +118,7 @@ def use_origin():
origin = reactpy_django.hooks.use_origin()
success = bool(origin)
return html.div(
- {"id": "use-origin", "data-success": success},
- f"use_origin: {origin}",
- html.hr(),
+ {"id": "use-origin", "data-success": success}, f"use_origin: {origin}"
)
@@ -144,7 +129,6 @@ def django_css():
reactpy_django.components.django_css("django-css-test.css", key="test"),
html.div({"style": {"display": "inline"}}, "django_css: "),
html.button("This text should be blue."),
- html.hr(),
)
@@ -156,42 +140,27 @@ def django_js():
{"id": "django-js", "data-success": success},
f"django_js: {success}",
reactpy_django.components.django_js("django-js-test.js", key="test"),
- ),
- html.hr(),
+ )
)
@component
@reactpy_django.decorators.auth_required(
fallback=html.div(
- {"id": "unauthorized-user-fallback"},
- "unauthorized_user: Success",
- html.hr(),
+ {"id": "unauthorized-user-fallback"}, "unauthorized_user: Success"
)
)
def unauthorized_user():
- return html.div(
- {"id": "unauthorized-user"},
- "unauthorized_user: Fail",
- html.hr(),
- )
+ return html.div({"id": "unauthorized-user"}, "unauthorized_user: Fail")
@component
@reactpy_django.decorators.auth_required(
auth_attribute="is_anonymous",
- fallback=html.div(
- {"id": "authorized-user-fallback"},
- "authorized_user: Fail",
- html.hr(),
- ),
+ fallback=html.div({"id": "authorized-user-fallback"}, "authorized_user: Fail"),
)
def authorized_user():
- return html.div(
- {"id": "authorized-user"},
- "authorized_user: Success",
- html.hr(),
- )
+ return html.div({"id": "authorized-user"}, "authorized_user: Success")
def create_relational_parent() -> RelationalParent:
@@ -242,7 +211,6 @@ def relational_query():
html.div(f"Relational Parent One To One: {oto}"),
html.div(f"Relational Parent Many to One: {mto}"),
html.div(f"Relational Child Foreign Key: {fk}"),
- html.hr(),
)
@@ -304,7 +272,6 @@ def async_relational_query():
html.div(f"Relational Parent One To One: {oto}"),
html.div(f"Relational Parent Many to One: {mto}"),
html.div(f"Relational Child Foreign Key: {fk}"),
- html.hr(),
)
@@ -400,7 +367,6 @@ def on_change(event):
),
mutation_status,
rendered_items,
- html.hr(),
)
@@ -476,7 +442,6 @@ async def on_change(event):
),
mutation_status,
rendered_items,
- html.hr(),
)
@@ -513,7 +478,6 @@ def view_to_component_sync_func_compatibility():
return html.div(
{"id": inspect.currentframe().f_code.co_name}, # type: ignore
_view_to_component_sync_func_compatibility(key="test"),
- html.hr(),
)
@@ -522,7 +486,6 @@ def view_to_component_async_func_compatibility():
return html.div(
{"id": inspect.currentframe().f_code.co_name}, # type: ignore
_view_to_component_async_func_compatibility(),
- html.hr(),
)
@@ -531,7 +494,6 @@ def view_to_component_sync_class_compatibility():
return html.div(
{"id": inspect.currentframe().f_code.co_name}, # type: ignore
_view_to_component_sync_class_compatibility(),
- html.hr(),
)
@@ -540,7 +502,6 @@ def view_to_component_async_class_compatibility():
return html.div(
{"id": inspect.currentframe().f_code.co_name}, # type: ignore
_view_to_component_async_class_compatibility(),
- html.hr(),
)
@@ -549,7 +510,6 @@ def view_to_component_template_view_class_compatibility():
return html.div(
{"id": inspect.currentframe().f_code.co_name}, # type: ignore
_view_to_component_template_view_class_compatibility(),
- html.hr(),
)
diff --git a/tests/test_app/templates/base.html b/tests/test_app/templates/base.html
index ba69185c..80d1ab32 100644
--- a/tests/test_app/templates/base.html
+++ b/tests/test_app/templates/base.html
@@ -17,42 +17,74 @@ ReactPy Test Page
width: 100%;
height: 45px;
}
-
{% component "test_app.components.hello_world" class="hello-world" %}
+
{% component "test_app.components.button" class="button" %}
+
{% component "test_app.components.parameterized_component" class="parametarized-component" x=123 y=456 %}
+
{% component "test_app.components.object_in_templatetag" my_object %}
+
{% component "test_app.components.simple_button" %}
+
{% component "test_app.components.use_connection" %}
+
{% component "test_app.components.use_scope" %}
+
{% component "test_app.components.use_location" %}
+
{% component "test_app.components.use_origin" %}
+
{% component "test_app.components.django_css" %}
+
{% component "test_app.components.django_js" %}
+
{% component "test_app.components.unauthorized_user" %}
+
{% component "test_app.components.authorized_user" %}
+
{% component "test_app.components.relational_query" %}
+
{% component "test_app.components.async_relational_query" %}
+
{% component "test_app.components.todo_list" %}
+
{% component "test_app.components.async_todo_list" %}
+
{% component "test_app.components.view_to_component_sync_func" %}
+
{% component "test_app.components.view_to_component_async_func" %}
+
{% component "test_app.components.view_to_component_sync_class" %}
+
{% component "test_app.components.view_to_component_async_class" %}
+
{% component "test_app.components.view_to_component_template_view_class" %}
+
{% component "test_app.components.view_to_component_script" %}
+
{% component "test_app.components.view_to_component_request" %}
+
{% component "test_app.components.view_to_component_args" %}
+
{% component "test_app.components.view_to_component_kwargs" %}
+
{% component "test_app.components.view_to_component_sync_func_compatibility" %}
+
{% component "test_app.components.view_to_component_async_func_compatibility" %}
+
{% component "test_app.components.view_to_component_sync_class_compatibility" %}
+
{% component "test_app.components.view_to_component_async_class_compatibility" %}
+
{% component "test_app.components.view_to_component_template_view_class_compatibility" %}
+
{% component "test_app.components.view_to_component_decorator" %}
+
{% component "test_app.components.view_to_component_decorator_args" %}
+