Skip to content

Commit 24deb2c

Browse files
authored
Allow adding class to a template tag div (#10)
* rename view.html -> component.html * remove pinned twisted version * add class as a component param * pin idom to 0.31
1 parent 1e575b0 commit 24deb2c

File tree

4 files changed

+9
-10
lines changed

4 files changed

+9
-10
lines changed

requirements/test-env.txt

+1-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
11
django
22
selenium
3-
4-
# required due issue with channels:
5-
# https://github.com/django/channels/issues/1639#issuecomment-817994671
6-
twisted<21
3+
twisted

src/django_idom/templates/idom/view.html renamed to src/django_idom/templates/idom/component.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{% load static %}
2-
<div id="{{ idom_mount_uuid }}"></div>
2+
<div id="{{ idom_mount_uuid }}" class="{{ class }}"></div>
33
<script type="module" crossorigin="anonymous">
44
import { mountViewToElement } from "{% static 'js/django-idom-client.js' %}";
55
const mountPoint = document.getElementById("{{ idom_mount_uuid }}");

src/django_idom/templatetags/idom.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,15 @@
1616
register = template.Library()
1717

1818

19-
@register.inclusion_tag("idom/view.html")
19+
@register.inclusion_tag("idom/component.html")
2020
def idom_component(_component_id_, **kwargs):
2121
_register_component(_component_id_)
2222

23+
class_ = kwargs.pop("class", "")
2324
json_kwargs = json.dumps(kwargs, separators=(",", ":"))
2425

2526
return {
27+
"class": class_,
2628
"idom_websocket_url": IDOM_WEBSOCKET_URL,
2729
"idom_web_modules_url": IDOM_WEB_MODULES_URL,
2830
"idom_mount_uuid": uuid4().hex,

tests/test_app/templates/base.html

+4-4
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@
1515

1616
<body>
1717
<h1>IDOM Test Page</h1>
18-
<div>{% idom_component "test_app.components.HelloWorld" %}</div>
19-
<div>{% idom_component "test_app.components.Button" %}</div>
20-
<div>{% idom_component "test_app.components.ParametrizedComponent" x=123 y=456 %}</div>
21-
<div>{% idom_component "test_app.components.SimpleBarChart" %}</div>
18+
<div>{% idom_component "test_app.components.HelloWorld" class="hello-world" %}</div>
19+
<div>{% idom_component "test_app.components.Button" class="button" %}</div>
20+
<div>{% idom_component "test_app.components.ParametrizedComponent" class="parametarized-component" x=123 y=456 %}</div>
21+
<div>{% idom_component "test_app.components.SimpleBarChart" class="simple-bar-chart" %}</div>
2222
</body>
2323
</html>

0 commit comments

Comments
 (0)