Rename namespace for static pygments URL

This commit is contained in:
Jake Howard 2022-07-16 01:13:48 +01:00
parent 78660500a5
commit 1326214c8f
Signed by: jake
GPG key ID: 57AFB45680EDD477
4 changed files with 12 additions and 12 deletions

View file

@ -17,7 +17,7 @@
{% block extra_css %} {% block extra_css %}
<link rel="stylesheet" type="text/css" href="{% static 'css/lite-youtube-embed.css' %}"> <link rel="stylesheet" type="text/css" href="{% static 'css/lite-youtube-embed.css' %}">
<link rel="stylesheet" type="text/css" href="{% static 'contrib/shareon/shareon.min.css' %}"> <link rel="stylesheet" type="text/css" href="{% static 'contrib/shareon/shareon.min.css' %}">
<link rel="stylesheet" type="text/css" href="{% url 'static-pygments:styles' 'default' %}"> <link rel="stylesheet" type="text/css" href="{% url 'code-block:styles' 'default' %}">
{% endblock %} {% endblock %}
{% block extra_js %} {% block extra_js %}

View file

@ -9,21 +9,17 @@ class PygmentsStylesTestCase(TestCase):
def test_accessible(self) -> None: def test_accessible(self) -> None:
for style in get_all_styles(): for style in get_all_styles():
with self.subTest(style=style): with self.subTest(style=style):
response = self.client.get( response = self.client.get(reverse("code-block:styles", args=[style]))
reverse("static-pygments:styles", args=[style])
)
self.assertEqual(response.status_code, 200) self.assertEqual(response.status_code, 200)
self.assertEqual(response["Cache-Control"], "max-age=3600, public") self.assertEqual(response["Cache-Control"], "max-age=3600, public")
self.assertEqual(response["ETag"], f'"{PYGMENTS_VERSION}"') self.assertEqual(response["ETag"], f'"{PYGMENTS_VERSION}"')
def test_unknown_style(self) -> None: def test_unknown_style(self) -> None:
response = self.client.get( response = self.client.get(reverse("code-block:styles", args=["not-a-style"]))
reverse("static-pygments:styles", args=["not-a-style"])
)
self.assertEqual(response.status_code, 404) self.assertEqual(response.status_code, 404)
def test_url_contains_version(self) -> None: def test_url_contains_version(self) -> None:
for style in get_all_styles(): for style in get_all_styles():
with self.subTest(style=style): with self.subTest(style=style):
url = reverse("static-pygments:styles", args=[style]) url = reverse("code-block:styles", args=[style])
self.assertIn(PYGMENTS_VERSION_SLUG, url) self.assertIn(PYGMENTS_VERSION_SLUG, url)

View file

@ -3,9 +3,13 @@ from django.urls import path
from .utils import PYGMENTS_VERSION_SLUG from .utils import PYGMENTS_VERSION_SLUG
from .views import pygments_styles from .views import pygments_styles
app_name = "code_block" app_name = "code-block"
urlpatterns = [ urlpatterns = [
# HACK: Bake the pygments version into the URL, without needing a custom method # HACK: Bake the pygments version into the URL, without needing a custom method
path(f"<slug:name>.{PYGMENTS_VERSION_SLUG}.css", pygments_styles, name="styles") path(
f"pygments-<slug:name>.{PYGMENTS_VERSION_SLUG}.css",
pygments_styles,
name="styles",
)
] ]

View file

@ -14,8 +14,8 @@ urlpatterns = [
path("documents/", include(wagtaildocs_urls)), path("documents/", include(wagtaildocs_urls)),
path("search/", search_views.search, name="search"), path("search/", search_views.search, name="search"),
path( path(
"static-pygments/", "code-block/",
include("website.contrib.code_block.urls", namespace="static-pygments"), include("website.contrib.code_block.urls"),
), ),
re_path( re_path(
r"^images/([^/]*)/(\d*)/([^/]*)/[^/]*$", r"^images/([^/]*)/(\d*)/([^/]*)/[^/]*$",