Skip to content

Commit

Permalink
Merge pull request #70 from LandRegistry/govuk-frontend-50
Browse files Browse the repository at this point in the history
GOV.UK Frontend v5.1.0
  • Loading branch information
matthew-shaw authored Feb 8, 2024
2 parents 2994e57 + 68f751e commit aa9b374
Show file tree
Hide file tree
Showing 43 changed files with 560 additions and 472 deletions.
1 change: 1 addition & 0 deletions .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* @matthew-shaw
4 changes: 2 additions & 2 deletions .github/workflows/python-package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,11 @@ jobs:
- name: Prepare to test
run: |
sudo apt-get install wait-for-it
curl -L https://github.com/surevine/govuk-frontend-diff/releases/download/v1.1.2/govuk-frontend-diff-linux --output govuk-frontend-diff
curl -L https://github.com/matthew-shaw/govuk-frontend-diff/releases/download/v2.0.0/govuk-frontend-diff-linux --output govuk-frontend-diff
chmod +x govuk-frontend-diff
- name: Test with govuk-frontend-diff
run: |
(cd tests/utils && nohup python -m flask run --port 3000 &)
wait-for-it localhost:3000
./govuk-frontend-diff http://localhost:3000 --govuk-frontend-version=v4.8.0 --ci
./govuk-frontend-diff http://localhost:3000 --govuk-frontend-version=v5.1.0 --exclude page-template --ci
18 changes: 17 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,13 @@ All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased](https://github.com/LandRegistry/govuk-frontend-jinja/compare/2.8.0...main)
## [Unreleased](https://github.com/LandRegistry/govuk-frontend-jinja/compare/3.0.0...main)

## [3.0.0](https://github.com/LandRegistry/govuk-frontend-jinja/releases/tag/3.0.0) - 08/02/2024

### Added

- [GOV.UK Frontend v5.1.0](https://github.com/alphagov/govuk-frontend/releases/tag/v5.1.0) support

## [2.8.0](https://github.com/LandRegistry/govuk-frontend-jinja/releases/tag/2.8.0) - 06/02/2024

Expand Down Expand Up @@ -80,6 +86,16 @@ Thanks to [Indigo Harrington](https://github.com/SentientHousePlant)

- Python 3.6 support

## [1.6.0](https://github.com/LandRegistry/govuk-frontend-jinja/releases/tag/1.6.0) -07/02/2024

### Added

- [GOV.UK Frontend v3.15.0](https://github.com/alphagov/govuk-frontend/releases/tag/v3.15.0) support

### Removed

- Python 3.6 support

## [1.5.1](https://github.com/LandRegistry/govuk-frontend-jinja/releases/tag/1.5.1) -14/10/2021

### Fixed
Expand Down
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
# GOV.UK Frontend Jinja Macros

[![PyPI version](https://badge.fury.io/py/govuk-frontend-jinja.svg)](https://pypi.org/project/govuk-frontend-jinja/)
![govuk-frontend 4.8.0](https://img.shields.io/badge/govuk--frontend%20version-4.8.0-005EA5?logo=gov.uk&style=flat)
![govuk-frontend 5.1.0](https://img.shields.io/badge/govuk--frontend%20version-5.1.0-005EA5?logo=gov.uk&style=flat)
[![Python package](https://github.com/LandRegistry/govuk-frontend-jinja/actions/workflows/python-package.yml/badge.svg)](https://github.com/LandRegistry/govuk-frontend-jinja/actions/workflows/python-package.yml)

**GOV.UK Frontend Jinja is a [community tool](https://design-system.service.gov.uk/community/resources-and-tools/) of the [GOV.UK Design System](https://design-system.service.gov.uk/). The Design System team is not responsible for it and cannot support you with using it. Contact the [maintainers](#contributors) directly if you need [help](#support) or you want to request a feature.**

This repository provides a complete set of [Jinja](https://jinja.palletsprojects.com/) macros that are kept up-to-date and 100% compliant with the original [GOV.UK Frontend](https://github.com/alphagov/govuk-frontend) Nunjucks macros. Porting is intentionally manual rather than automated to make updates simpler than maintaining an automated conversion routine. A [comprehensive test suite](https://github.com/surevine/govuk-frontend-diff) ensures compliance against the latest, and every subsequent, GOV.UK Frontend release.
This repository provides a complete set of [Jinja](https://jinja.palletsprojects.com/) macros that are kept up-to-date and 100% compliant with the original [GOV.UK Frontend](https://github.com/alphagov/govuk-frontend) Nunjucks macros. Porting is intentionally manual rather than automated to make updates simpler than maintaining an automated conversion routine. A [comprehensive test suite](https://github.com/matthew-shaw/govuk-frontend-diff) ensures compliance against the latest, and every subsequent, GOV.UK Frontend release.

If you are looking to build a fully featured Flask app that integrates with [GOV.UK Frontend Jinja](https://github.com/LandRegistry/govuk-frontend-jinja) and [GOV.UK Frontend WTForms](https://github.com/LandRegistry/govuk-frontend-wtf) please use the [GOV.UK Frontend Flask](https://github.com/LandRegistry/govuk-frontend-flask) template repository to [generate your app](https://github.com/LandRegistry/govuk-frontend-flask/generate).

Expand All @@ -16,6 +16,7 @@ The following table shows the version of GOV.UK Frontend Jinja that you should u

| GOV.UK Frontend Jinja Version | Target GOV.UK Frontend Version |
| ----------------------------- | ------------------------------ |
| [3.0.0](https://github.com/LandRegistry/govuk-frontend-jinja/releases/tag/3.0.0) | [5.1.0](https://github.com/alphagov/govuk-frontend/releases/tag/v5.1.0) |
| [2.8.0](https://github.com/LandRegistry/govuk-frontend-jinja/releases/tag/2.8.0) | [4.8.0](https://github.com/alphagov/govuk-frontend/releases/tag/v4.8.0) |
| [2.7.0](https://github.com/LandRegistry/govuk-frontend-jinja/releases/tag/2.7.0) | [4.7.0](https://github.com/alphagov/govuk-frontend/releases/tag/v4.7.0) |
| [2.6.0](https://github.com/LandRegistry/govuk-frontend-jinja/releases/tag/2.6.0) | [4.6.0](https://github.com/alphagov/govuk-frontend/releases/tag/v4.6.0) |
Expand Down Expand Up @@ -69,7 +70,7 @@ The options available to each component macro can be found in the original [GOV.

## Running the tests

The tests are run in a GitHub actions pipeline but if you want to run them locally you will need to install [govuk-frontend-diff](https://github.com/surevine/govuk-frontend-diff).
The tests are run in a GitHub actions pipeline but if you want to run them locally you will need to install [govuk-frontend-diff](https://github.com/matthew-shaw/govuk-frontend-diff).

There is a test server at `tests/utils/app.py` which you will need to run using the following command:

Expand Down
94 changes: 61 additions & 33 deletions govuk_frontend_jinja/templates/components/accordion/macro.html
Original file line number Diff line number Diff line change
@@ -1,40 +1,68 @@
{% macro govukAccordion(params) %}
{% set id = params.id %}
{% set headingLevel = params.headingLevel if params.headingLevel else 2 %}
{% from "govuk_frontend_jinja/macros/i18n.html" import govukI18nAttributes %}

<div class="govuk-accordion {%- if params.classes %} {{ params.classes }}{% endif -%}" data-module="govuk-accordion" id="{{ id }}"
{%- if params.hideAllSectionsText %} data-i18n.hide-all-sections="{{ params.hideAllSectionsText | escape }}"{% endif %}
{%- if params.hideSectionText %} data-i18n.hide-section="{{ params.hideSectionText | escape }}"{% endif %}
{%- if params.hideSectionAriaLabelText %} data-i18n.hide-section-aria-label="{{ params.hideSectionAriaLabelText | escape }}"{% endif %}
{%- if params.rememberExpanded is not undefined %} data-remember-expanded="{{ params.rememberExpanded | escape | lower }}"{% endif %}
{%- if params.showAllSectionsText %} data-i18n.show-all-sections="{{ params.showAllSectionsText | escape }}"{% endif %}
{%- if params.showSectionText %} data-i18n.show-section="{{ params.showSectionText | escape }}"{% endif %}
{%- if params.showSectionAriaLabelText %} data-i18n.show-section-aria-label="{{ params.showSectionAriaLabelText | escape }}"{% endif %}
{%- for attribute, value in (params.attributes.items() if params.attributes else {}.items()) %} {{attribute}}="{{value}}"{% endfor %}>
{% for item in params['items'] %}
{% if item %}
<div class="govuk-accordion__section {%- if item.expanded %} govuk-accordion__section--expanded{% endif %}">
<div class="govuk-accordion__section-header">
<h{{ headingLevel }} class="govuk-accordion__section-heading">
<span class="govuk-accordion__section-button" id="{{ id }}-heading-{{ loop.index }}">
{{ item.heading.html | safe if item.heading.html else item.heading.text }}
</span>
</h{{ headingLevel }}>
{% if item.summary and (item.summary.html or item.summary.text) %}
<div class="govuk-accordion__section-summary govuk-body" id="{{ id }}-summary-{{ loop.index }}">
{{ item.summary.html | safe if item.summary.html else item.summary.text }}
</div>
{% endif %}
</div>
<div id="{{ id }}-content-{{ loop.index }}" class="govuk-accordion__section-content" aria-labelledby="{{ id }}-heading-{{ loop.index }}">
{% if item.content.html %}
{{ item.content.html | safe }}
{% elif item.content.text %}
<p class="govuk-body">{{ item.content.text }}</p>
{% endif %}
</div>
{%- macro _accordionItem(params, item, index) %}
{%- set headingLevel = params.headingLevel if params.headingLevel else 2 %}
<div class="govuk-accordion__section {%- if item.expanded %} govuk-accordion__section--expanded{% endif %}">
<div class="govuk-accordion__section-header">
<h{{ headingLevel }} class="govuk-accordion__section-heading">
<span class="govuk-accordion__section-button" id="{{ params.id }}-heading-{{ index }}">
{{ item.heading.html | safe | trim | indent(8) if item.heading.html else item.heading.text }}
</span>
</h{{ headingLevel }}>
{% if item.summary and (item.summary.html or item.summary.text) %}
<div class="govuk-accordion__section-summary govuk-body" id="{{ params.id }}-summary-{{ index }}">
{{ item.summary.html | safe | trim | indent(8) if item.summary.html else item.summary.text }}
</div>
{% endif %}
</div>
<div id="{{ params.id }}-content-{{ index }}" class="govuk-accordion__section-content">
{% if item.content.html %}
{{ item.content.html | safe | trim | indent(6) }}
{% elif item.content.text %}
<p class="govuk-body">
{{ item.content.text | trim | indent(8) }}
</p>
{% endif %}
</div>
</div>
{% endmacro -%}

<div class="govuk-accordion {%- if params.classes %} {{ params.classes }}{% endif %}" data-module="govuk-accordion" id="{{ params.id }}"
{{- govukI18nAttributes({
'key': 'hide-all-sections',
'message': params.hideAllSectionsText
}) -}}

{{- govukI18nAttributes({
'key': 'hide-section',
'message': params.hideSectionText
}) -}}

{{- govukI18nAttributes({
'key': 'hide-section-aria-label',
'message': params.hideSectionAriaLabelText
}) -}}

{{- govukI18nAttributes({
'key': 'show-all-sections',
'message': params.showAllSectionsText
}) -}}

{{- govukI18nAttributes({
'key': 'show-section',
'message': params.showSectionText
}) -}}

{{- govukI18nAttributes({
'key': 'show-section-aria-label',
'message': params.showSectionAriaLabelText
}) -}}

{%- if params.rememberExpanded is not undefined %} data-remember-expanded="{{ params.rememberExpanded | escape | lower }}"{% endif %}
{%- for attribute, value in (params.attributes.items() if params.attributes else {}.items()) %} {{ attribute }}="{{ value }}"{% endfor %}>
{% for item in params['items'] %}
{% if item %}{{ _accordionItem(params, item, loop.index) }}{% endif %}
{% endfor %}
</div>
{% endmacro %}
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
{% macro govukBackLink(params) %}
<a href="{%- if params.href %}{{ params.href }}{% else %}#{% endif -%}" class="govuk-back-link{%- if params.classes %} {{ params.classes }}{% endif -%}"
{%- for attribute, value in (params.attributes.items() if params.attributes else {}.items()) %} {{attribute}}="{{value}}"{% endfor %}>{{ (params.html | safe if params.html else (params.text if params.text else 'Back')) }}
</a>
<a href="{% if params.href %}{{ params.href }}{% else %}#{% endif %}" class="govuk-back-link {%- if params.classes %} {{ params.classes }}{% endif %}"
{%- for attribute, value in (params.attributes.items() if params.attributes else {}.items()) %} {{ attribute }}="{{ value }}"{% endfor %}>{{ (params.html | safe if params.html else (params.text if params.text else 'Back')) }}</a>
{% endmacro %}
27 changes: 15 additions & 12 deletions govuk_frontend_jinja/templates/components/breadcrumbs/macro.html
Original file line number Diff line number Diff line change
@@ -1,27 +1,30 @@
{% macro govukBreadcrumbs(params) %}
{# Set classes for this component #}
{%- set classNames = "govuk-breadcrumbs " -%}
{# Set classes for this component #}
{%- set classNames = "govuk-breadcrumbs" -%}

{% if params.classes %}
{% set classNames = classNames + params.classes %}
{% set classNames = classNames + " " + params.classes %}
{% endif -%}

{% if params.collapseOnMobile %}
{% set classNames = classNames + " govuk-breadcrumbs--collapse-on-mobile" %}
{% endif -%}

<div class="{{classNames}}"{% for attribute, value in (params.attributes.items() if params.attributes else {}.items()) %} {{attribute}}="{{value}}"{% endfor %}>
<div class="{{ classNames }}" {%- for attribute, value in (params.attributes.items() if params.attributes else {}.items()) %} {{ attribute }}="{{ value }}"{% endfor %}>
<ol class="govuk-breadcrumbs__list">
{% for item in params['items'] %}
{% if item.href %}
{% for item in params['items'] %}
{% if item.href %}
<li class="govuk-breadcrumbs__list-item">
<a class="govuk-breadcrumbs__link" href="{{ item.href }}"{% for attribute, value in (item.attributes.items() if item.attributes else {}.items()) %} {{attribute}}="{{value}}"{% endfor %}>{{ item.html | safe if item.html else item.text }}</a>
<a class="govuk-breadcrumbs__link" href="{{ item.href }}" {%- for attribute, value in (item.attributes.items() if item.attributes else {}.items()) %} {{ attribute }}="{{ value }}"{% endfor %}>
{{- item.html | safe if item.html else item.text -}}
</a>
</li>
{% else %}
<li class="govuk-breadcrumbs__list-item" aria-current="page">{{ item.html | safe if item.html else item.text }}</li>
{% endif %}
{% endfor %}
{% else %}
<li class="govuk-breadcrumbs__list-item" aria-current="page">
{{- item.html | safe if item.html else item.text -}}
</li>
{% endif %}
{% endfor %}
</ol>
</div>

{% endmacro %}
44 changes: 20 additions & 24 deletions govuk_frontend_jinja/templates/components/button/macro.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@
{%- if params.classes %}
{% set classNames = classNames + " " + params.classes %}
{% endif %}
{% if params.disabled %}
{% set classNames = classNames + " govuk-button--disabled" %}
{% endif -%}

{# Determine type of element to use, if not explicitly set #}
{%- if params.isStartButton %}
{% set classNames = classNames + " govuk-button--start" %}
{% endif %}

{#- Determine type of element to use, if not explicitly set #}
{%- if params.element %}
{% set element = params.element | lower %}
{% else %}
Expand All @@ -20,40 +21,35 @@
{% endif %}
{% endif -%}

{% if params.isStartButton %}
{% set iconHtml %}
{#- The SVG needs `focusable="false"` so that Internet Explorer does not
treat it as an interactive element - without this it will be
'focusable' when using the keyboard to navigate. #}
<svg class="govuk-button__start-icon" xmlns="http://www.w3.org/2000/svg" width="17.5" height="19" viewBox="0 0 33 40" aria-hidden="true" focusable="false">
<path fill="currentColor" d="M0 0h13l20 20-20 20H0l20-20z"/>
</svg>
{% endset %}
{% set classNames = classNames + " govuk-button--start" %}
{% endif %}
{%- macro _startIcon() %}
{#- The SVG needs `focusable="false"` so that Internet Explorer does not
treat it as an interactive element - without this it will be
'focusable' when using the keyboard to navigate. #}
<svg class="govuk-button__start-icon" xmlns="http://www.w3.org/2000/svg" width="17.5" height="19" viewBox="0 0 33 40" aria-hidden="true" focusable="false">
<path fill="currentColor" d="M0 0h13l20 20-20 20H0l20-20z"/>
</svg>
{%- endmacro -%}

{#- Define common attributes that we can use across all element types #}

{%- set commonAttributes %} class="{{ classNames }}" data-module="govuk-button"{% for attribute, value in (params.attributes.items() if params.attributes else {}.items()) %} {{attribute}}="{{value}}"{% endfor %}{% if params.id %} id="{{ params.id }}"{% endif %}{% endset %}
{%- set commonAttributes %} class="{{ classNames }}" data-module="govuk-button" {%- for attribute, value in (params.attributes.items() if params.attributes else {}.items()) %} {{ attribute }}="{{ value }}"{% endfor %}{% if params.id %} id="{{ params.id }}"{% endif %}{% endset %}

{#- Define common attributes we can use for both button and input types #}

{%- set buttonAttributes %}{% if params.name %} name="{{ params.name }}"{% endif %}{% if params.disabled %} disabled="disabled" aria-disabled="true"{% endif %}{% if params.preventDoubleClick is not undefined %} data-prevent-double-click="{{params.preventDoubleClick | lower}}"{% endif %}{% endset %}
{%- set buttonAttributes %}{% if params.name %} name="{{ params.name }}"{% endif %}{% if params.disabled %} disabled aria-disabled="true"{% endif %}{% if params.preventDoubleClick is not undefined %} data-prevent-double-click="{{ params.preventDoubleClick | lower }}"{% endif %}{% endset %}

{#- Actually create a button... or a link! #}

{%- if element == 'a' %}
<a href="{{ params.href if params.href else '#' }}" role="button" draggable="false" {{- commonAttributes | safe }}>
{{ params.html | safe if params.html else params.text }}
{# Indentation is intentional to output HTML nicely #}
{{- iconHtml | safe | trim if iconHtml -}}
{{ params.html | safe | trim | indent(2) if params.html else params.text }}
{{- _startIcon() | safe if params.isStartButton }}
</a>

{%- elif element == 'button' %}
<button {%- if params.value %} value="{{ params.value }}"{% endif %}{%- if params.type %} type="{{ params.type }}"{% endif %} {{- buttonAttributes | safe }} {{- commonAttributes | safe }}>
{{ params.html | safe if params.html else params.text }}
{# Indentation is intentional to output HTML nicely #}
{{- iconHtml | safe | trim if iconHtml -}}
<button {%- if params.value %} value="{{ params.value }}"{% endif %} type="{{ params.type if params.type else 'submit' }}" {{- buttonAttributes | safe }} {{- commonAttributes | safe }}>
{{ params.html | safe | trim | indent(2) if params.html else params.text }}
{{- _startIcon() | safe if params.isStartButton }}
</button>

{%- elif element == 'input' %}
Expand Down
Loading

0 comments on commit aa9b374

Please sign in to comment.