Skip to content

Commit 0ccf64d

Browse files
committed
Add byline support to Text Introductions
This commit adds support for bylines to the Text Introduction block in the same way that Item Introduction blocks support them. To avoid duplication, the common byline functionality has been pulled out into a new byline template (although not into a new Wagtail block). All three of the affected templates (byline, item introduction, text introduction) can be previewed using this repository's template debug functionality at these URLs: - http://localhost:8000/admin/template_debug/v1/byline/ - http://localhost:8000/admin/template_debug/v1/item_introduction/ - http://localhost:8000/admin/template_debug/v1/text_introduction/ Like Item Introduction bylines, Text Introduction bylines can have zero or more authors and an optional date. This commit also includes some minor cleanup around the way that item introduction blocks have been manually rendered on various page types. As far as I can tell this special handling is no longer needed, if it ever was. Affected page types and example pages to verify this: - BlogPage: http://localhost:8000/about-us/blog/why-were-modernizing-how-we-collect-credit-card-data/ - DocumentDetailPage: http://localhost:8000/compliance/supervisory-guidance/bulletin-phone-pay-fees/ - EnforcementActionPage: http://localhost:8000/enforcement/actions/capital-one-bank/ - LearnPage: http://localhost:8000/enforcement/information-industry-whistleblowers/privacy-act-statement/ - NewsroomPage: http://localhost:8000/about-us/newsroom/cfpb-issues-guidance-to-address-shoddy-investigation-practices-by-consumer-reporting-companies/ - HMDAHistoricDataPage: http://localhost:8000/data-research/hmda/historic-data/ This commit also adds a few new Python unit tests to validate the intended template rendering.
1 parent 340834e commit 0ccf64d

19 files changed

Lines changed: 379 additions & 167 deletions

File tree

cfgov/hmda/jinja2/hmda/hmda-explorer.html

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
{% import 'hmda-explorer-controls.html' as controls with context %}
44
{% import 'hmda-explorer-results.html' as results with context %}
55
{% import 'hmda-explorer-institutions.html' as institutions with context %}
6-
{% import 'organisms/item-introduction.html' as item_introduction with context %}
76
{% import 'templates/render_block.html' as render_block with context %}
87
{% import 'templates/streamfield-sidefoot.html' as streamfield_sidefoot with context %}
98

@@ -13,11 +12,7 @@
1312

1413
{% block content_main %}
1514
{% for block in page.header -%}
16-
{% if block.block_type == 'item_introduction' %}
17-
{{ item_introduction.render(block.value) }}
18-
{% else %}
19-
{{ render_block.render(block, loop.index) }}
20-
{% endif %}
15+
{{ render_block.render(block, loop.index) }}
2116
{%- endfor %}
2217

2318
<div class="hmda-historic-data" style="margin-top: -20px">

cfgov/jinja2/v1/_includes/article.html

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -38,21 +38,20 @@
3838

3939
<article class="post">
4040
<header>
41-
{% set data = {
42-
'category': page.categories.all(),
41+
{% with value = {
4342
'heading': page.title,
4443
'date': page.date_published,
45-
'has_social': True,
44+
'has_social': true,
4645
'social_options': { 'is_printable': true }
4746
} %}
47+
{% for block in page.header -%}
48+
{% if block.block_type == 'article_subheader' %}
49+
{% do value.update( { 'paragraph': block.value } ) %}
50+
{% endif %}
51+
{% endfor %}
4852

49-
{% for block in page.header -%}
50-
{% if block.block_type == 'article_subheader' %}
51-
{% do data.update({'paragraph': block.value}) %}
52-
{% endif %}
53-
{% endfor %}
54-
55-
{{ item_introduction.render(data) }}
53+
{% include 'organisms/item-introduction.html' with context %}
54+
{% endwith %}
5655
</header>
5756

5857
<div class="post_body">
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
{# ==========================================================================
2+
3+
Create a byline when given:
4+
5+
value.authors: List of author names.
6+
7+
value.date: Publication date.
8+
9+
========================================================================== #}
10+
11+
{%- macro render( value ) %}
12+
{%- if value.authors or value.date -%}
13+
<div class="a-byline">
14+
{% if value.authors %}
15+
<span class="byline">
16+
{%- for author in value.authors -%}
17+
{% if loop.first %}By {% elif loop.last %} and {% endif -%}
18+
{{ author }}
19+
{%- if loop.length > 2 and loop.index < loop.length %}, {% endif %}
20+
{%- endfor -%}
21+
</span>
22+
{% endif -%}
23+
24+
{% if value.authors and value.date -%}
25+
&ndash;
26+
{%- endif %}
27+
28+
{%- if value.date %}
29+
<span class="a-date">
30+
{% import 'macros/time.html' as time %}
31+
{{ time.render( value.date, { 'date': true } ) }}
32+
</span>
33+
{% endif %}
34+
</div>
35+
{%- endif %}
36+
{%- endmacro %}
37+
38+
39+
{%- if value %}
40+
41+
{% if page and not "authors" in value %}
42+
{% do value.update(
43+
{ "authors": page.authors.values_list( "name", flat=True ) }
44+
) %}
45+
{% endif %}
46+
47+
{{- render( value ) -}}
48+
49+
{% endif -%}

cfgov/jinja2/v1/_includes/macros/category-slug.html

Lines changed: 15 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -9,45 +9,35 @@
99

1010
Render a category slug when given:
1111

12-
category: A string.
12+
category: A category slug, e.g. "press-release".
1313

14-
href (optional): If present creates a link with
15-
a path to which the category filter applies.
16-
For example, if the slug is used on a blog article
17-
then path should be '/about-us/blog/'.
18-
Remember to leverage vars.path instead of
19-
using the literal string '/about-us/blog/'.
20-
Path is used to create the filtered URL:
21-
{{ href }}?category={{ category }}
14+
href (optional): If present creates a link with
15+
a path to which the category filter applies.
16+
For example, if the slug is used on a blog article
17+
then path should be '/about-us/blog/'.
18+
Path is used to create the filtered URL:
19+
{{ href }}?categories={{ category }}
2220

2321
classes (optional): Space separated list of class names.
2422

25-
use_blog_category (optional): Whether to use the blog category filter or not.
26-
Defaults to false.
27-
2823
========================================================================== #}
2924

30-
{% macro render(category, href, classes='', use_blog_category=false) %}
25+
{% macro render( category, href, classes='' ) %}
3126
{% import 'macros/category-icon.html' as category_icon %}
3227

3328
{% if href %}
34-
{# TODO: Remove use_blog_category parameter when this element becomes atomic. #}
35-
{% if use_blog_category %}
36-
{% set href = href + '?blog_category=' + category | urlencode | replace('%20', '+') %}
37-
{% else %}
38-
{% set href = href + '?categories=' + category | urlencode | replace('%20', '+') %}
39-
{% endif %}
29+
{% set href = href + '?categories=' + category | urlencode %}
4030
{% endif %}
4131

42-
{% call _category_link(href, classes) %}
43-
{% set cat = category_label(category) or category %}
44-
{{ category_icon.render(cat) }}
32+
{% call _category_link( href, classes ) -%}
33+
{% set category_name = category_label( category ) or category %}
34+
{{- category_icon.render( category_name ) }}
4535
<span class="u-visually-hidden">Category:</span>
46-
{{ cat | safe }}
47-
{% endcall %}
36+
{{ category_name }}
37+
{%- endcall %}
4838
{% endmacro %}
4939

50-
{% macro _category_link(href, classes) %}
40+
{% macro _category_link( href, classes ) %}
5141
{% if href %}
5242
<a href="{{ href }}"
5343
class="a-heading a-heading__icon {{ classes }}">

cfgov/jinja2/v1/_includes/molecules/text-introduction.html

Lines changed: 17 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -4,79 +4,56 @@
44

55
=========================================================================
66

7-
Description:
8-
97
Create a Text Introduction molecule.
10-
See [GHE]/flapjack/Modules-V1/wiki/Text-Introduction
118

12-
value: Object defined from a StreamField block.
9+
https://cfpb.github.io/design-system/patterns/text-introductions
1310

1411
value.eyebrow: (Optional) Text to display above heading.
1512

1613
value.heading: (Optional) String for heading text.
1714

18-
value.intro: (Optional) String for body introduction text.
15+
value.authors: (Optional) A list of author names to be included
16+
on a byline.
17+
18+
value.date: (Optional) A date to be included on a byline.
1919

20-
value.intro.source: TODO: add type and description.
20+
value.intro: (Optional) String for body introduction text.
2121

2222
value.body: (Optional) String for body text.
2323

24-
value.links: A tuple to create a list of links, containing:
24+
value.links: A list of links, containing:
2525

26-
value.links[i].text: (Optional) A string for the text of the link.
26+
value.links[i].text: A string for the text of the link.
2727

2828
value.links[i].url: A string for the URL of the link.
2929

3030
value.links[i].aria_label: (Optional) An aria-label for the link.
3131

32-
value.date: (Optional) A date to be included on a byline.
33-
3432
value.has_rule: Whether or not to render a rule line
3533
(border-bottom) at the bottom of the molecule.
3634

3735
========================================================================== #}
38-
{% set published_date = value.date %}
39-
{% set has_authors = page.authors.exists() %}
4036

41-
{% if value.eyebrow %}
37+
{% if value.eyebrow -%}
4238
<div class="eyebrow">{{ value.eyebrow }}</div>
43-
{% endif %}
44-
{% if value.heading %}
39+
{%- endif %}
40+
41+
{% if value.heading -%}
4542
<h1>{{ value.heading }}</h1>
46-
{% endif %}
43+
{%- endif %}
4744

48-
{% if published_date or has_authors %}
49-
<div class="meta">
50-
{% endif %}
51-
{% if has_authors %}
52-
<span class="byline">
53-
{%- for author in page.get_authors() -%}
54-
{% if loop.first %}By {% elif loop.last %}and {% endif %}
55-
{{ author.name }}
56-
{%- if loop.length > 2 and loop.index < loop.length %}, {% endif %}
57-
{% endfor %}
58-
&ndash;
59-
</span>
60-
{% endif %}
61-
{% if published_date %}
62-
<span class="a-date">
63-
{% import 'macros/time.html' as time %}
64-
{{ time.render(published_date, {'date':true}) }}
65-
</span>
66-
{% endif %}
67-
{% if published_date or has_authors %}
68-
</div>
69-
{% endif %}
45+
{% include 'atoms/byline.html' with context %}
7046

71-
{% if value.intro.source %}
47+
{% if value.intro -%}
7248
<div class="lead-paragraph">
7349
{{ value.intro | safe }}
7450
</div>
75-
{% endif %}
51+
{%- endif %}
7652

7753
{% if value.body %}
7854
{{ value.body | safe }}
7955
{% endif %}
56+
8057
{% for link in value.links %}
8158
{% if link.text %}
8259
{% if loop.first %}<ul class="m-list m-list__links">{% endif %}

cfgov/jinja2/v1/_includes/organisms/item-introduction.html

Lines changed: 50 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -4,72 +4,73 @@
44

55
==========================================================================
66

7-
Description:
7+
Create an Item Introduction organism.
88

9-
Create an Item Introduction molecule.
10-
See [GHE]/flapjack/Modules-V1/wiki/Item-Introduction
9+
https://cfpb.github.io/design-system/patterns/item-introductions
1110

12-
value: An object with the following options for value.
11+
value.show_category: (Optional) Whether to show category.
1312

14-
value.show_category: Whether to show the category or not.
15-
value.heading: Heading text.
16-
value.paragraph.source: Body introduction text.
17-
value.authors: Array of author names and associated URLs.
13+
value.category: (Optional) Category to show above heading.
1814

19-
value.date: A datetime for the post.
20-
value.has_social: Whether to show the share icons or not.
21-
value.social_options: An object with options for the share icons
15+
value.category_url: (Optional) URL to link category to.
16+
17+
value.heading: Heading text.
18+
19+
value.paragraph: (Optional) Subheader paragraph.
20+
21+
value.authors: (Optional) A list of author names to be included
22+
on a byline.
23+
24+
value.date: (Optional) A date to be included on a byline.
25+
26+
value.has_social: Whether to show the share icons or not.
27+
28+
value.social_options: (Optional) Share icon options.
2229

2330
========================================================================== #}
2431

2532

2633
{% import 'molecules/social-media.html' as social_media with context %}
2734
{% import 'macros/category-slug.html' as category_slug %}
2835

29-
{% macro render(value) %}
30-
31-
{% set filter_page = page.get_filter_data() %}
32-
{% set filter_page_url = pageurl(filter_page) if filter_page else none %}
33-
{% set published_date = value.date %}
34-
{% set has_authors = page.authors.exists() %}
35-
{% set social_options = value.social_options or {} %}
36-
36+
{%- macro render( value ) %}
3737
<div class="o-item-introduction">
38-
{% if filter_page_url and page.categories.count() > 0 and value.show_category %}
39-
{{ category_slug.render(category=page.categories.first().name, href=filter_page_url) }}
40-
{% endif %}
38+
{% if value.show_category and value.category -%}
39+
{{ category_slug.render( value.category, href=value.category_url ) }}
40+
{%- endif %}
41+
4142
<h1>{{ value.heading | safe }}</h1>
4243

43-
{% if value.paragraph %}
44+
{% if value.paragraph -%}
4445
<div class="lead-paragraph">{{ value.paragraph | safe }}</div>
45-
{% endif %}
46+
{%- endif %}
4647

47-
{% if published_date or has_authors %}
48-
<div class="meta">
49-
{% endif %}
50-
{% if filter_page_url and has_authors %}
51-
<span class="byline">
52-
{%- for author in page.get_authors() -%}
53-
{% if loop.first %}By {% elif loop.last %}and {% endif %}
54-
{{ author.name }}
55-
{%- if loop.length > 2 and loop.index < loop.length %}, {% endif %}
56-
{% endfor %}
57-
&ndash;
58-
</span>
59-
{% endif %}
60-
{% if published_date %}
61-
<span class="a-date">
62-
{% import 'macros/time.html' as time %}
63-
{{ time.render(published_date, {'date':true}) }}
64-
</span>
48+
{% include 'atoms/byline.html' with context %}
49+
50+
{% if value.has_social -%}
51+
{{ social_media.render( value.social_options or {} ) }}
52+
{%- endif %}
53+
</div>
54+
{% endmacro -%}
55+
56+
{%- if value %}
57+
58+
{% if page %}
59+
{% if not "category" in value %}
60+
{% set category = page.categories.values_list("name", flat=True).first() %}
61+
{% if category %}
62+
{% do value.update( { "category": category } ) %}
63+
64+
{% set filter_page = page.get_filter_data() %}
65+
{% if filter_page %}
66+
{% do value.update(
67+
{ "category_url": pageurl( filter_page ) }
68+
) %}
69+
{% endif %}
6570
{% endif %}
66-
{% if published_date or has_authors %}
67-
</div>
6871
{% endif %}
72+
{% endif %}
6973

70-
{% if value.has_social %}
71-
{{ social_media.render(social_options) }}
72-
{% endif %}
73-
</div>
74+
{{- render( value ) -}}
7475

75-
{% endmacro %}
76+
{% endif -%}

0 commit comments

Comments
 (0)