Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add formatting for Nunjucks files #3218

Merged
merged 112 commits into from
Jul 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
112 commits
Select commit Hold shift + click to select a range
21e9d72
add formatting for nunjucks files
rmccar May 24, 2024
b4337f5
add plugin
rmccar May 24, 2024
4005db1
Merge branch 'main' into add-formatting-for-nunjucks-files
rmccar May 28, 2024
5f11386
fix example
rmccar May 28, 2024
d822876
add njk and html files to lint staged
rmccar May 28, 2024
37678cc
test
rmccar May 28, 2024
ec6a374
test
rmccar May 28, 2024
40ba41e
update prettier to latest
rmccar May 28, 2024
7e0b41a
fix title tag var
rmccar May 28, 2024
c710175
formatting
rmccar May 30, 2024
405136e
fix list
rmccar May 30, 2024
9757bf2
fix button
rmccar May 30, 2024
f30f802
formatting
rmccar May 30, 2024
a9d59c4
formatting
rmccar May 30, 2024
e5fe86c
Merge branch 'main' into add-formatting-for-nunjucks-files
rmccar May 30, 2024
993da2a
fixes
rmccar May 31, 2024
2197964
Merge branch 'add-formatting-for-nunjucks-files' of github.com:ONSdig…
rmccar May 31, 2024
3e24cb6
fixes
rmccar May 31, 2024
d99c12c
fixes
rmccar May 31, 2024
79cae3c
merge main
rmccar Jun 5, 2024
17cd7fc
merge main
rmccar Jun 5, 2024
9f925ac
fixes
rmccar Jun 5, 2024
877fd16
fixes
rmccar Jun 5, 2024
40ab44d
fixes
rmccar Jun 5, 2024
58105ac
fixes
rmccar Jun 5, 2024
aef848d
fixes
rmccar Jun 5, 2024
26fd7ad
fixes
rmccar Jun 5, 2024
ee34d6a
panel
rmccar Jun 5, 2024
7dc8695
fixes
rmccar Jun 5, 2024
93f81e9
fixes
rmccar Jun 5, 2024
4f4252a
fixes
rmccar Jun 5, 2024
1f75842
document list
rmccar Jun 6, 2024
01a79c0
label
rmccar Jun 6, 2024
737d524
layout
rmccar Jun 6, 2024
d925b2b
update input
rmccar Jun 6, 2024
8f8335e
input
rmccar Jun 6, 2024
ee075ec
input
rmccar Jun 6, 2024
b397c14
test
rmccar Jun 6, 2024
301cfca
input classes
rmccar Jun 6, 2024
d6ff587
label classes
rmccar Jun 6, 2024
a9c054b
input classes
rmccar Jun 6, 2024
31902ef
details field and fieldset classes
rmccar Jun 6, 2024
82bdba5
address autosuggest classes
rmccar Jun 6, 2024
6ddadab
Merge branch 'main' into add-formatting-for-nunjucks-files
rmccar Jun 14, 2024
fe7dc2c
formatting
rmccar Jun 14, 2024
c0e638c
panel classes
rmccar Jun 14, 2024
abd0a07
remove label class
rmccar Jun 14, 2024
4acf9ae
fix input
rmccar Jun 14, 2024
7dc1024
pagination classes
rmccar Jun 14, 2024
f8505ff
remove unused imports
rmccar Jun 14, 2024
99873f3
address output classes
rmccar Jun 14, 2024
de4d1f0
fix address example
rmccar Jun 14, 2024
646641c
fix dowloadable resources and remove elses
rmccar Jun 14, 2024
a6337a3
fix guide
rmccar Jun 14, 2024
f539241
fix select and question
rmccar Jun 14, 2024
0e0401a
fix addresses
rmccar Jun 14, 2024
5bd47a6
fix autosuggest
rmccar Jun 14, 2024
b6cc0a8
fix checkboxes
rmccar Jun 14, 2024
b7f20eb
remove elses
rmccar Jun 14, 2024
a1ca7dd
remove spaces
rmccar Jun 14, 2024
1c136f3
fix welsh header example
rmccar Jun 14, 2024
c36ef25
fix header
rmccar Jun 14, 2024
465200d
fix hero
rmccar Jun 14, 2024
b0c0191
fix textarea
rmccar Jun 14, 2024
9cf8e72
fix textarea
rmccar Jun 14, 2024
e5b724c
fix textarea
rmccar Jun 14, 2024
34fef51
update class logic
rmccar Jun 14, 2024
61e56a1
reorganise classes
rmccar Jun 14, 2024
0e2b72a
fix document list
rmccar Jun 17, 2024
468117f
refactor dynamic tags and remove most prettier ignores
rmccar Jun 18, 2024
2316b04
fix heading
rmccar Jun 18, 2024
c40a9c0
add safe filter to tags
rmccar Jun 18, 2024
ee9b9af
various fixes
rmccar Jun 18, 2024
f1e44f2
fix list
rmccar Jun 18, 2024
5fc18cf
update class logic
rmccar Jun 18, 2024
59eead1
fix tab gaps
rmccar Jun 19, 2024
cb3aa86
update vr snapshots
rmccar Jun 19, 2024
3964e2b
fix tests
rmccar Jun 19, 2024
04bd67a
fix tests
rmccar Jun 19, 2024
086aa63
fix tests
rmccar Jun 19, 2024
79c2794
fix tests
rmccar Jun 19, 2024
da2e8dc
fix footer test
rmccar Jun 19, 2024
53d2482
fix input test
rmccar Jun 19, 2024
0681b46
update snapshots
rmccar Jun 19, 2024
66ada37
fix tests
rmccar Jun 19, 2024
f25f87e
fix test
rmccar Jun 19, 2024
defdce9
remove erroneous test
rmccar Jun 19, 2024
aa23d68
fix test
rmccar Jun 19, 2024
c4a68e6
fix test
rmccar Jun 19, 2024
2864809
some tidying up
rmccar Jun 20, 2024
6b93d20
setting social class when using social logos
rmccar Jun 20, 2024
8b7b032
update vr snapshots
rmccar Jun 20, 2024
fc2ba0e
revert example
rmccar Jun 20, 2024
9f989a5
Merge branch 'main' into add-formatting-for-nunjucks-files
rmccar Jun 20, 2024
5ebfabc
revert header example
rmccar Jun 27, 2024
19c036a
revert
rmccar Jun 27, 2024
5ec9307
revert social list changes
rmccar Jun 27, 2024
911d5fe
update snapshots
rmccar Jun 27, 2024
e81335a
add elses
rmccar Jun 28, 2024
88283cb
add elses
rmccar Jun 28, 2024
3b1c568
add elses
rmccar Jun 28, 2024
8df76a6
remove
rmccar Jun 28, 2024
b1e4795
fixes for jinja
rmccar Jun 28, 2024
ff0f5a7
fixes for jinja
rmccar Jun 28, 2024
016c354
fixes for jinja
rmccar Jun 28, 2024
7c70634
fixes for jinja
rmccar Jun 28, 2024
413619e
fixes for jinja
rmccar Jun 28, 2024
9ae8879
fixes for jinja
rmccar Jun 28, 2024
e3ccac1
fixes for jinja
rmccar Jun 28, 2024
e9ae2c1
Merge branch 'main' into add-formatting-for-nunjucks-files
alessioventuriniAND Jul 2, 2024
8a69c0c
Merge branch 'main' into add-formatting-for-nunjucks-files
alessioventuriniAND Jul 3, 2024
bda325c
another var name fixed
rmccar Jul 4, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions .prettierrc.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
singleQuote: true
printWidth: 140
trailingComma: all
{
'plugins': ['prettier-plugin-jinja-template'],
'singleQuote': true,
'printWidth': 140,
'trailingComma': all,
'overrides': [{ 'files': ['*.html', '*.njk'], 'options': { 'parser': 'jinja-template' } }],
}
724 changes: 431 additions & 293 deletions __snapshots__/layout/_template.spec.js.snap

Large diffs are not rendered by default.

5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
"prettier --write",
"yarn run stylelint-fix"
],
"*.{yml,yaml}": [
"*.{yml,yaml,njk,html}": [
"prettier --write"
]
},
Expand Down Expand Up @@ -109,7 +109,8 @@
"postcss": "^8.3.5",
"postcss-url": "^10.1.3",
"prepend-file": "^2.0.1",
"prettier": "^3.0.0",
"prettier": "^3.2.5",
"prettier-plugin-jinja-template": "^1.4.0",
"puppeteer": "^21.0.2",
"remark-cli": "^12.0.0",
"remark-lint": "^9.1.2",
Expand Down
56 changes: 31 additions & 25 deletions src/components/access-code/_macro.njk
Original file line number Diff line number Diff line change
Expand Up @@ -7,41 +7,47 @@
{% set maxlength = params.maxlength | default(16) + extraSpaces %}

{% set content %}
{{ onsInput({
"id": params.id,
"type": params.type,
"name": params.name,
"classes": "ons-access-code__input ons-js-access-code" + (" ons-u-mb-xs" if params.postTextboxLinkText else ""),
"label": params.label,
"attributes": {
"maxlength": maxlength,
"data-group-size": groupSize,
"autocomplete": "off",
"autocapitalize": "characters"
},
"fieldClasses": "ons-question__answer",
"error": params.error,
"postTextboxLinkText": params.postTextboxLinkText,
"postTextboxLinkUrl": params.postTextboxLinkUrl
}) }}
{{
onsInput({
"id": params.id,
"type": params.type,
"name": params.name,
"classes": "ons-access-code__input ons-js-access-code" + (" ons-u-mb-xs" if params.postTextboxLinkText else ""),
"label": params.label,
"attributes": {
"maxlength": maxlength,
"data-group-size": groupSize,
"autocomplete": "off",
"autocapitalize": "characters"
},
"fieldClasses": "ons-question__answer",
"error": params.error,
"postTextboxLinkText": params.postTextboxLinkText,
"postTextboxLinkUrl": params.postTextboxLinkUrl
})
}}
{% endset %}

{% if not params.error %}
{% call onsPanel({
"classes": "ons-u-mb-s" + (' ' + params.classes if params.classes else '')
}) %}
{%
call onsPanel({
"classes": "ons-u-mb-s" + (" " + params.classes if params.classes else "")
})
%}
{{ content | safe }}
{% endcall %}
{% else %}
{{ content | safe }}
{% endif %}

{% if params.securityMessage %}
{% call onsPanel({
"variant": "bare",
"iconType": "lock",
"classes": "ons-u-mb-s"
}) %}
{%
call onsPanel({
"variant": "bare",
"iconType": "lock",
"classes": "ons-u-mb-s"
})
%}
{{ params.securityMessage }}
{% endcall %}
{% endif %}
Expand Down
86 changes: 49 additions & 37 deletions src/components/access-code/example-access-code-error.njk
Original file line number Diff line number Diff line change
@@ -1,22 +1,26 @@
---
title: "Example: Access code error"
title: 'Example: Access code error'
layout: ~
---

{% extends "layout/_template.njk" %}
{% from "components/access-code/_macro.njk" import onsAccessCode %}
{% from "components/button/_macro.njk" import onsButton %}
{% from "components/panel/_macro.njk" import onsPanel %}
{% from "components/details/_macro.njk" import onsDetails %}

{% set pageConfig = {
"title": "Study title"
} %}
{%
set pageConfig = {
"title": "Study title"
}
%}

{% block main %}
{% call onsPanel({
"title": "There is a problem with this page",
"variant": "error"
}) %}
{%
call onsPanel({
"title": "There is a problem with this page",
"variant": "error"
})
%}
{% from "components/list/_macro.njk" import onsList %}
{{
onsList({
Expand All @@ -34,46 +38,54 @@ layout: ~

<h1 class="ons-u-mt-l">Start study</h1>

{{ onsAccessCode({
"id": "access-code",
"name": "access-code",
"postTextboxLinkText": "Where to find your access code",
"postTextboxLinkUrl": "#0",
"label": {
"text": "Enter your 16-character access code",
"description": "Keep this code safe. You will need to enter it every time you access your survey"
},
"securityMessage": "Your personal information is protected by law and will be kept confidential",
"error": {
"id": "access-code-error",
"text": "Enter an access code"
}
}) }}
{{
onsAccessCode({
"id": "access-code",
"name": "access-code",
"postTextboxLinkText": "Where to find your access code",
"postTextboxLinkUrl": "#0",
"label": {
"text": "Enter your 16-character access code",
"description": "Keep this code safe. You will need to enter it every time you access your survey"
},
"securityMessage": "Your personal information is protected by law and will be kept confidential",
"error": {
"id": "access-code-error",
"text": "Enter an access code"
}
})
}}

{{ onsButton({
"text": "Access study",
"classes": "ons-u-mb-xl"
}) }}
{{
onsButton({
"text": "Access study",
"classes": "ons-u-mb-xl"
})
}}

<h2>If you do not have an access code</h2>
<p>
If you have lost or not received an access code, you can <a href="#0">request a new access code</a>.
This can be sent to you by text or post.
If you have lost or not received an access code, you can <a href="#0">request a new access code</a>. This can be sent to you by text
or post.
</p>

{% set content %}
<p>If you need to answer separately from the people you live with, you can <a href="#0">request an individual access code</a>.</p>
{% call onsPanel({
"variant": "warn"
}) %}
{%
call onsPanel({
"variant": "warn"
})
%}
Someone in your household must still complete a study using this household access code
{% endcall %}
{% endset %}

{% call onsDetails({
"id": "details-access-code-error",
"title": "Need to answer separately from your household?"
}) %}
{%
call onsDetails({
"id": "details-access-code-error",
"title": "Need to answer separately from your household?"
})
%}
{{ content | safe }}
{% endcall %}
{% endblock %}
70 changes: 40 additions & 30 deletions src/components/access-code/example-access-code.njk
Original file line number Diff line number Diff line change
@@ -1,58 +1,68 @@
---
title: "Example: Access code"
title: 'Example: Access code'
layout: ~
---

{% extends "layout/_template.njk" %}
{% from "components/access-code/_macro.njk" import onsAccessCode %}
{% from "components/button/_macro.njk" import onsButton %}
{% from "components/panel/_macro.njk" import onsPanel %}
{% from "components/details/_macro.njk" import onsDetails %}

{% set pageConfig = {
"header": {
"title": "Study title"
{%
set pageConfig = {
"header": {
"title": "Study title"
}
}
} %}
%}

{% block main %}
<h1 class="ons-u-mt-l">Start study</h1>

{{ onsAccessCode({
"id": "access-code-example",
"name": "access-code",
"postTextboxLinkText": "Where to find your access code",
"postTextboxLinkUrl": "#0",
"label": {
"text": "Enter your 16-character access code",
"description": "Keep this code safe. You will need to enter it every time you access your study"
},
"securityMessage": "Your personal information is protected by law and will be kept confidential"
}) }}
{{
onsAccessCode({
"id": "access-code-example",
"name": "access-code",
"postTextboxLinkText": "Where to find your access code",
"postTextboxLinkUrl": "#0",
"label": {
"text": "Enter your 16-character access code",
"description": "Keep this code safe. You will need to enter it every time you access your study"
},
"securityMessage": "Your personal information is protected by law and will be kept confidential"
})
}}

{{ onsButton({
"text": "Access study",
"classes": "ons-u-mb-xl"
}) }}
{{
onsButton({
"text": "Access study",
"classes": "ons-u-mb-xl"
})
}}

<h2>If you do not have an access code</h2>
<p>
If you have lost or not received an access code, you can <a href="#0">request a new access code</a>.
This can be sent to you by text or post.
If you have lost or not received an access code, you can <a href="#0">request a new access code</a>. This can be sent to you by text
or post.
</p>

{% set content %}
<p>If you need to answer separately from the people you live with, you can <a href="#0">request an individual access code</a>.</p>
{% call onsPanel({
"variant": "warn"
}) %}
{%
call onsPanel({
"variant": "warn"
})
%}
Someone in your household must still complete a study using this household access code
{% endcall %}
{% endset %}

{% call onsDetails({
"id": "details",
"title": "Need to answer separately from your household?"
}) %}
{%
call onsDetails({
"id": "details",
"title": "Need to answer separately from your household?"
})
%}
{{ content | safe }}
{% endcall %}
{% endblock %}
13 changes: 7 additions & 6 deletions src/components/accordion/_macro.njk
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
{% macro onsAccordion(params) %}
{% from "components/details/_macro.njk" import onsDetails %}

<div id="{{params.id}}" class="ons-accordion{{ ' ' + params.classes if params.classes }}">
<div id="{{ params.id }}" class="ons-accordion{{ ' ' + params.classes if params.classes else '' }}">
{% if params.allButton %}
{% from "components/button/_macro.njk" import onsButton %}
{% set attributes = params.allButton.attributes | default({}) %}

{% set attributes = attributes | setAttributes({
"data-close-all": params.allButton.close,
"data-group": params.id
}) %}
{%
set attributes = attributes | setAttributes({
"data-close-all": params.allButton.close,
"data-group": params.id
})
%}

{{
onsButton({
Expand Down
1 change: 0 additions & 1 deletion src/components/accordion/example-accordion-open.njk
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
{% from "components/accordion/_macro.njk" import onsAccordion %}
{% from "components/checkboxes/_macro.njk" import onsCheckboxes %}


{% set content1 %}
{{
onsCheckboxes({
Expand Down
Loading
Loading