Skip to content

Commit

Permalink
remove line breaks in icon component
Browse files Browse the repository at this point in the history
  • Loading branch information
precious-onyenaucheya-ons committed Dec 1, 2023
1 parent 31859ef commit e55d7a2
Show file tree
Hide file tree
Showing 16 changed files with 175 additions and 100 deletions.
18 changes: 15 additions & 3 deletions lib/render-example.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import frontMatter from 'front-matter';
import fs from 'fs';
import nunjucks from 'nunjucks';
import { minify } from 'html-minifier';

export default function renderExample(templatePath, nunjucksEnvironment) {
try {
Expand All @@ -24,11 +25,22 @@ export default function renderExample(templatePath, nunjucksEnvironment) {
}

const compiledTemplate = nunjucks.compile(template, nunjucksEnvironment, templatePath);

let html = compiledTemplate.render(templatePath);
html = minify(html, {
removeComments: true,
collapseWhitespace: true,
});
//console.log(html);
return html;

// let html = compiledTemplate.render(templatePath);
// html = minify(html, {
// removeComments: true,
// collapseWhitespace: true,
// });

//removes whitespace and linebreaks before svg tags.
return html.replace(/\s*(<svg)/g, '$1');
// //removes whitespace and linebreaks before svg tags.
// return html.replace(/\s*(<svg)/g, '$1');
} catch (err) {
console.error(`An error occurred whilst rendering: ${templatePath}`);
throw err;
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@
"gulp-postcss": "^9.0.0",
"gulp-sourcemaps": "^3.0.0",
"gulp-terser": "^2.0.1",
"html-minifier": "^4.0.0",
"http-server": "^14.1.1",
"husky": "^8.0.3",
"jest": "^29.6.1",
Expand Down
4 changes: 2 additions & 2 deletions src/components/breadcrumbs/_macro.njk
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@
<a class="ons-breadcrumbs__link{{ ' ' + item.linkClasses if item.linkClasses else '' }}" href={% if not isDesignSystemExample %}"{{ item.url }}"{% else %}"#0"{% endif %}{% if item.id %} id="{{ item.id }}"{% endif %}
{% if item.attributes %}{% for attribute, value in (item.attributes.items() if item.attributes is mapping and item.attributes.items else item.attributes) %}{{attribute}}="{{value}}" {% endfor %}{% endif %}
>{{ item.text }}</a>
{{
{{-
onsIcon({
"iconType": "chevron"
})
}}
-}}
</li>
{% endfor %}
</ol>
Expand Down
12 changes: 6 additions & 6 deletions src/components/button/_macro.njk
Original file line number Diff line number Diff line change
Expand Up @@ -84,28 +84,28 @@
<span class="ons-btn__inner{% if params.innerClasses %} {{ params.innerClasses }}{% endif %}">
{%- if iconPosition == "before" or iconPosition == "after" %}
{%- if iconPosition == "before" %}
{{
{{-
onsIcon({
"iconType": iconType,
"classes": 'ons-u-mr-xs'
})
}}
-}}
{% endif -%}
<span class="ons-btn__text">{{- params.html | safe if params.html else params.text -}}</span>
{%- if iconPosition == "after" %}
{{
{{-
onsIcon({
"iconType": iconType,
"classes": 'ons-u-ml-xs'
})
}}
-}}
{% endif -%}
{% elif iconPosition == "only" -%}
{{
{{-
onsIcon({
"iconType": iconType
})
}}
-}}
<span class="ons-btn__text ons-u-vh@xxs@s">{{- params.html | safe if params.html else params.text -}}</span>
{% else -%}
<span class="ons-btn__text">{{- params.html | safe if params.html else params.text -}}</span>
Expand Down
8 changes: 4 additions & 4 deletions src/components/content-pagination/_macro.njk
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,20 @@
<span class="ons-content-pagination__link-title">
{% if contentPaginationItem.rel == 'prev' %}
{% from "components/icon/_macro.njk" import onsIcon %}
{{
{{-
onsIcon({
"iconType": 'arrow-previous',
"iconSize": 'm'
})
}}
-}}
{% else %}
{% from "components/icon/_macro.njk" import onsIcon %}
{{
{{-
onsIcon({
"iconType": 'arrow-next',
"iconSize": 'm'
})
}}
-}}
{% endif %}
<span class="ons-content-pagination__link-text">
{{ contentPaginationItem.text }}
Expand Down
4 changes: 2 additions & 2 deletions src/components/details/_macro.njk
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@
<{{ titleTag }} class="ons-details__title">{{ params.title }}</{{ titleTag }}>
<span class="ons-details__icon">
{% from "components/icon/_macro.njk" import onsIcon %}
{{
{{-
onsIcon({
"iconType": "chevron"
})
}}</span>
-}}</span>
</div>
<div id="{{ params.id }}-content" class="ons-details__content ons-js-details-content"
{% if params.contentAttributes %}{% for attribute, value in (params.contentAttributes.items() if params.contentAttributes is mapping and params.contentAttributes.items else params.contentAttributes) %}{{ attribute }}{% if value %}="{{ value }}"{% endif %} {% endfor %}{% endif %}
Expand Down
16 changes: 8 additions & 8 deletions src/components/footer/_macro.njk
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,21 @@

{% set onsLogo %}
{% if params.lang == 'cy' %}
{{
{{-
onsIcon({
"iconType": 'ons-logo-cy',
"altText": 'Swyddfa Ystadegau Gwladol',
"altTextId": 'ons-logo-cy-footer-alt'
})
}}
-}}
{% else %}
{{
{{-
onsIcon({
"iconType": 'ons-logo-en',
"altText": 'Office for National Statistics',
"altTextId": 'ons-logo-en-footer-alt'
})
}}
-}}
{% endif %}
{% endset %}

Expand Down Expand Up @@ -130,11 +130,11 @@
{% if params.OGLLink %}
<!-- OGL -->
<div class="ons-footer__license ons-u-mb-m">
{{
{{-
onsIcon({
"iconType": 'ogl'
})
}}
-}}
{% if params.OGLLink.HTML %}
{{ params.OGLLink.HTML | safe }}
{% elif params.OGLLink %}
Expand Down Expand Up @@ -166,11 +166,11 @@
{% if params.crest %}
<!-- Crest -->
<div class="ons-grid__col ons-footer__crest ons-u-mb-m@xxs@l">
{{
{{-
onsIcon({
"iconType": 'crest'
})
}}
-}}
</div>
{% endif %}
</div>
Expand Down
16 changes: 8 additions & 8 deletions src/components/header/_macro.njk
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,12 @@
{% if params.mastheadLogo.large %}
{{ params.mastheadLogo.large | safe }}
{% else %}
{{
{{-
onsIcon({
"iconType": 'ons-logo-' + currentLanguageISOCode,
"altText": 'Office for National Statistics logo'
})
}}
-}}
{% endif %}
</div>
<div class="ons-header__org-logo ons-header__org-logo--small">
Expand All @@ -55,12 +55,12 @@
{% elif params.mastheadLogo.large %}
{{ params.mastheadLogo.large | safe }}
{% else %}
{{
{{-
onsIcon({
"iconType": 'ons-logo-stacked-' + currentLanguageISOCode,
"altText": 'Office for National Statistics logo'
})
}}
-}}
{% endif %}
</div>
{% if params.mastheadLogoUrl %}
Expand Down Expand Up @@ -91,11 +91,11 @@
{% for item in params.serviceLinks.itemsList %}
<li class="ons-header-service-nav__item">
{% if item.iconType %}
{{
{{-
onsIcon({
"iconType": item.iconType
})
}}
-}}
{% endif %}
{% if item.url %}
<a
Expand Down Expand Up @@ -142,11 +142,11 @@
{% for item in params.serviceLinks.itemsList %}
<li class="ons-header-service-nav__item ons-header-service-nav__item--mobile">
{% if item.iconType %}
{{
{{-
onsIcon({
"iconType": item.iconType
})
}}
-}}
{% endif %}
{% if item.url %}
<a
Expand Down
Loading

0 comments on commit e55d7a2

Please sign in to comment.