Skip to content

Allow adding class to a template tag div #10

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 13 commits into from
Sep 9, 2021
Merged
5 changes: 1 addition & 4 deletions requirements/test-env.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
django
selenium

# required due issue with channels:
# https://github.com/django/channels/issues/1639#issuecomment-817994671
twisted<21
twisted
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{% load static %}
<div id="{{ idom_mount_uuid }}"></div>
<div id="{{ idom_mount_uuid }}" class="{{ class }}"></div>
<script type="module" crossorigin="anonymous">
import { mountViewToElement } from "{% static 'js/django-idom-client.js' %}";
const mountPoint = document.getElementById("{{ idom_mount_uuid }}");
Expand Down
4 changes: 3 additions & 1 deletion src/django_idom/templatetags/idom.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,15 @@
register = template.Library()


@register.inclusion_tag("idom/view.html")
@register.inclusion_tag("idom/component.html")
def idom_component(_component_id_, **kwargs):
_register_component(_component_id_)

class_ = kwargs.pop("class", "")
json_kwargs = json.dumps(kwargs, separators=(",", ":"))

return {
"class": class_,
"idom_websocket_url": IDOM_WEBSOCKET_URL,
"idom_web_modules_url": IDOM_WEB_MODULES_URL,
"idom_mount_uuid": uuid4().hex,
Expand Down
8 changes: 4 additions & 4 deletions tests/test_app/templates/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@

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