Skip to content

Commit ee97a8c

Browse files
feat: Add constants referencing base JS and CSS asset to allow import in client code
1 parent e519eb0 commit ee97a8c

File tree

4 files changed

+17
-7
lines changed

4 files changed

+17
-7
lines changed

dsfr/constants.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,3 +101,11 @@
101101
("fr-ratio-4x3", "4x3"),
102102
("fr-ratio-1x1", "1x1"),
103103
]
104+
105+
106+
class DsfrStaticAssets:
107+
DSFR_MODULE_JS = "dsfr/dist/dsfr/dsfr.module.min.js"
108+
DSFR_NOMODULE_JS = "dsfr/dist/dsfr/dsfr.nomodule.min.js"
109+
DSFR_CSS = "dsfr/dist/dsfr/dsfr.min.css"
110+
DSFR_UTILITY_CSS = "dsfr/dist/utility/utility.min.css"
111+
DSFR_OVERRIDES_CSS = "css/dsfr-django-overrides.css"
Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
{% load static %}
22
<link rel="stylesheet"
3-
href="{% static 'dsfr/dist/dsfr/dsfr.min.css' %}"
3+
href="{% static DsfrStaticAssets.DSFR_CSS %}"
44
{% if self.USE_INTEGRITY_CHECKSUMS %}integrity="{{ self.INTEGRITY_CSS }}"{% endif %}>
55
<link rel="stylesheet"
6-
href="{% static 'dsfr/dist/utility/utility.min.css' %}"
6+
href="{% static DsfrStaticAssets.DSFR_UTILITY_CSS %}"
77
{% if self.USE_INTEGRITY_CHECKSUMS %}integrity="{{ self.INTEGRITY_UTILITY_CSS }}"{% endif %}>
8-
<link rel="stylesheet" href="{% static 'css/dsfr-django-overrides.css' %}">
8+
<link rel="stylesheet"
9+
href="{% static DsfrStaticAssets.DSFR_OVERRIDES_CSS %}">
910

1011
<meta name="theme-color" content="#000091">
1112
<!-- Définit la couleur de thème du navigateur (Safari/Android) -->

dsfr/templates/dsfr/global_js.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
{% load static %}
22
<script type="module"
3-
src="{% static 'dsfr/dist/dsfr/dsfr.module.min.js' %}"
3+
src="{% static DsfrStaticAssets.DSFR_MODULE_JS %}"
44
{% if self.USE_INTEGRITY_CHECKSUMS %}integrity="{{ self.INTEGRITY_JS_MODULE }}"{% endif %}
55
{% if self.nonce %} nonce="{{self.nonce}}"{% endif %}></script>
66
<script nomodule
7-
src="{% static 'dsfr/dist/dsfr/dsfr.nomodule.min.js' %}"
7+
src="{% static DsfrStaticAssets.DSFR_NOMODULE_JS %}"
88
{% if self.USE_INTEGRITY_CHECKSUMS %}integrity="{{ self.INTEGRITY_JS_NOMODULE }}"{% endif %}
99
{% if self.nonce %} nonce="{{self.nonce}}"{% endif %}></script>

dsfr/templatetags/dsfr_tags.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
INTEGRITY_JS_MODULE,
1616
INTEGRITY_JS_NOMODULE,
1717
)
18+
from dsfr.constants import DsfrStaticAssets
1819
from dsfr.utils import (
1920
find_active_menu_items,
2021
generate_random_id,
@@ -63,7 +64,7 @@ def dsfr_css() -> dict:
6364
):
6465
tag_data["USE_INTEGRITY_CHECKSUMS"] = False
6566

66-
return {"self": tag_data}
67+
return {"self": tag_data, "DsfrStaticAssets": DsfrStaticAssets}
6768

6869

6970
@register.inclusion_tag("dsfr/global_js.html", takes_context=True)
@@ -93,7 +94,7 @@ def dsfr_js(context, *args, **kwargs) -> dict:
9394
):
9495
tag_data["USE_INTEGRITY_CHECKSUMS"] = False
9596

96-
return {"self": tag_data}
97+
return {"self": tag_data, "DsfrStaticAssets": DsfrStaticAssets}
9798

9899

99100
@register.inclusion_tag("dsfr/favicon.html")

0 commit comments

Comments
 (0)