-
Notifications
You must be signed in to change notification settings - Fork 332
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
Review use indent
in our templates
#3211
Comments
Turns out that I've added |
I'm in the process of reviewing that PR but I don't fully grasp how |
Yeah course, I should say it's vital to "carry the indent level" from the one macro to the next for tidiness sake only I'll add some examples below using this little unindented macro: {% macro govukExample() %}
<article>
<h2>Example</h2>
<p>Hello Owen</p>
</article>
{% endmacro %} Without indentSee how the macro contents isn't indented at all? It appears to indent the macro's 1st HTML line, but that's from the 2 spaces before Input<section>
<h1>Demo</h1>
{{ govukExample() }}
</section> Output<section>
<h1>Demo</h1>
<article>
<h2>Example</h2>
<p>Hello Owen</p>
</article>
</section> Without indent, nestedAs above, only the macro's 1st HTML line is indented by the spaces before But none of the macro's subsequent HTML lines are indented at all Input<div class="govuk-grid-row">
<div class="govuk-grid-column">
<section>
<h1>Demo</h1>
{{ govukExample() }}
</section>
</div>
</div> Output<div class="govuk-grid-row">
<div class="govuk-grid-column">
<section>
<h1>Demo</h1>
<article>
<h2>Example</h2>
<p>Hello Owen</p>
</article>
</section>
</div>
</div> With indentNotice now how Input<section>
<h1>Demo</h1>
{{ govukExample() | trim | indent(2) }}
</section> Output<section>
<h1>Demo</h1>
<article>
<h2>Example</h2>
<p>Hello Owen</p>
</article>
</section> With indent, nestedWith a nested example we now begin at 6 spaces (not 2) so we need But notice how Input<div class="govuk-grid-row">
<div class="govuk-grid-column">
<section>
<h1>Demo</h1>
{{ govukExample() | trim | indent(6) }}
</section>
</div>
</div> Output<div class="govuk-grid-row">
<div class="govuk-grid-column">
<section>
<h1>Demo</h1>
<article>
<h2>Example</h2>
<p>Hello Owen</p>
</article>
</section>
</div>
</div> |
Just a quick variation to the above too Lots of our formatting issues were with For example, take this Nunjucks macro instead: {% macro govukExample(html) %}
<article>
{{ html | trim | safe | indent(2) }}
</article>
{% endmacro %} With indent, nested
|
Cheers Colin that makes sense! |
I've added some suggestions to Accordion, Breadcrumbs and Button for @owenatgov to review |
Thanks for all these reviews @romaricpascal Thought I'd got them all but I'd not split out Task list or Tabs so will reopen
|
@owenatgov All done ✅ |
What
We use
indent
across our component templates. Do we still need to do this?Why
The primary intent of using
indent
in our context is to make it look tidy when a developer is viewing the source for a page with our components on. There's a question now about how valuable this is based on the reckon that most devs will use dev tools over view source and that we pretty print our HTML.We should investigate if this is still valuable. If so, we should see if there are things we can do to improve and/or document our use of it. If not, we should remove it.
Notes
Places we use indent
In many of the below examples there are more than one use of
indent
so look at the whole file as well as the referenced line.govuk-frontend/src/govuk/components/button/template.njk
Line 48 in 853403d
govuk-frontend/src/govuk/components/checkboxes/template.njk
Line 85 in 853403d
govuk-frontend/src/govuk/components/cookie-banner/template.njk
Line 50 in 853403d
govuk-frontend/src/govuk/components/date-input/template.njk
Line 40 in 853403d
govuk-frontend/src/govuk/components/file-upload/template.njk
Line 16 in 853403d
govuk-frontend/src/govuk/components/input/template.njk
Line 16 in 853403d
govuk-frontend/src/govuk/components/label/template.njk
Line 11 in 853403d
govuk-frontend/src/govuk/components/phase-banner/template.njk
Line 10 in 853403d
govuk-frontend/src/govuk/components/radios/template.njk
Line 25 in 853403d
govuk-frontend/src/govuk/components/select/template.njk
Line 16 in 853403d
Extra things to think about
indent
other than for view source?Who needs to work on this
Developers
Done when
indent
indent
or notindent
/more efficient ways to leverageindent
The text was updated successfully, but these errors were encountered: