Skip to content

Commit ca994a5

Browse files
committed
refactor the snippet so it can check for nested streamfields and add it to the base page
1 parent c54c388 commit ca994a5

File tree

7 files changed

+28
-59
lines changed

7 files changed

+28
-59
lines changed

tbx/core/templatetags/util_tags.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,15 @@ def has_gist_block(value):
9797
return False
9898

9999
for block in value._raw_data:
100+
# special case for work page section block as the streamfields are nested within sections
101+
if block["type"] == "section":
102+
for sub_block in block["value"]["content"]:
103+
if (
104+
sub_block["type"] == "raw_html"
105+
and "https://gist.github.com" in sub_block["value"]
106+
):
107+
return True
108+
100109
if block["type"] == "raw_html" and "https://gist.github.com" in block["value"]:
101110
return True
102111
return False
@@ -108,5 +117,10 @@ def has_markdown_block(value):
108117
return False
109118

110119
for block in value._raw_data:
120+
# special case for work page section block as the streamfields are nested within sections
121+
if block["type"] == "section":
122+
for sub_block in block["value"]["content"]:
123+
if sub_block["type"] == "markdown":
124+
return True
111125
if block["type"] == "markdown":
112126
return True

tbx/project_styleguide/templates/patterns/base.html

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,16 @@
3131

3232
<link rel="stylesheet" type="text/css" href="{% static 'css/main.css' %}">
3333

34+
{# Add syntax highlighting for gists if a gist exists within a raw html streamfield #}
35+
{% if page.body|has_gist_block %}
36+
<link rel="stylesheet" type="text/css" href="{% static 'css/gist.css' %}">
37+
{% endif %}
38+
39+
{# Add syntax highlighting for code snippets within a code block streamfield (aka markdown block) #}
40+
{% if page.body|has_markdown_block %}
41+
<link rel="stylesheet" type="text/css" href="{% static 'css/codehilite.css' %}">
42+
{% endif %}
43+
3444
{% block extra_css %}{% endblock %}
3545
</head>
3646

tbx/project_styleguide/templates/patterns/pages/blog/blog_detail.html

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,6 @@
11
{% extends "patterns/base_page.html" %}
22
{% load wagtailcore_tags wagtailimages_tags util_tags static %}
33

4-
{% block extra_css %}
5-
{{ block.super }}
6-
{% if page.body|has_gist_block %}
7-
<link rel="stylesheet" type="text/css" href="{% static 'css/gist.css' %}">
8-
{% endif %}
9-
10-
{% if page.body|has_markdown_block %}
11-
<link rel="stylesheet" type="text/css" href="{% static 'css/codehilite.css' %}">
12-
{% endif %}
13-
{% endblock %}
14-
154
{% block meta_tags %}
165
<script>
176
window.dataLayer = window.dataLayer || [];

tbx/project_styleguide/templates/patterns/pages/impact_reports/impact_report_page.html

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,5 @@
11
{% extends "patterns/base_page.html" %}
2-
{% load wagtailcore_tags wagtailimages_tags util_tags static %}
3-
4-
{% block extra_css %}
5-
{{ block.super }}
6-
{% if page.body|has_gist_block %}
7-
<link rel="stylesheet" type="text/css" href="{% static 'css/gist.css' %}">
8-
{% endif %}
9-
10-
{% if page.body|has_markdown_block %}
11-
<link rel="stylesheet" type="text/css" href="{% static 'css/codehilite.css' %}">
12-
{% endif %}
13-
{% endblock %}
2+
{% load wagtailcore_tags wagtailimages_tags %}
143

154
{% block content %}
165
<div class="grid mt-spacerMedium lg:mt-spacerLarge">

tbx/project_styleguide/templates/patterns/pages/service/service_page.html

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,5 @@
11
{% extends "patterns/base_page.html" %}
2-
{% load wagtailcore_tags wagtailimages_tags util_tags static %}
3-
4-
{% block extra_css %}
5-
{{ block.super }}
6-
{% if page.body|has_gist_block %}
7-
<link rel="stylesheet" type="text/css" href="{% static 'css/gist.css' %}">
8-
{% endif %}
9-
10-
{% if page.body|has_markdown_block %}
11-
<link rel="stylesheet" type="text/css" href="{% static 'css/codehilite.css' %}">
12-
{% endif %}
13-
{% endblock %}
2+
{% load wagtailcore_tags wagtailimages_tags %}
143

154
{% block content %}
165
<div class="grid grid--spacer-large streamfield">

tbx/project_styleguide/templates/patterns/pages/standard/standard_page.html

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,5 @@
11
{% extends "patterns/base_page.html" %}
2-
{% load wagtailcore_tags wagtailimages_tags util_tags static %}
3-
4-
{% block extra_css %}
5-
{{ block.super }}
6-
{% if page.body|has_gist_block %}
7-
<link rel="stylesheet" type="text/css" href="{% static 'css/gist.css' %}">
8-
{% endif %}
9-
10-
{% if page.body|has_markdown_block %}
11-
<link rel="stylesheet" type="text/css" href="{% static 'css/codehilite.css' %}">
12-
{% endif %}
13-
{% endblock %}
2+
{% load wagtailcore_tags wagtailimages_tags %}
143

154
{% block content %}
165
<div class="grid grid--spacer-large streamfield">

tbx/project_styleguide/templates/patterns/pages/work/historical_work_page.html

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,5 @@
11
{% extends "patterns/pages/work/work_page_base.html" %}
2-
{% load wagtailcore_tags wagtailimages_tags util_tags static %}
3-
4-
{% block extra_css %}
5-
{{ block.super }}
6-
{% if page.body|has_gist_block %}
7-
<link rel="stylesheet" type="text/css" href="{% static 'css/gist.css' %}">
8-
{% endif %}
9-
10-
{% if page.body|has_markdown_block %}
11-
<link rel="stylesheet" type="text/css" href="{% static 'css/codehilite.css' %}">
12-
{% endif %}
13-
{% endblock %}
2+
{% load wagtailcore_tags wagtailimages_tags %}
143

154
{# The historical work pages did not have a separate intro - so we just loop over the body streamfield to find the intro block(s) #}
165
{% block intro %}

0 commit comments

Comments
 (0)