Skip to content

Commit

Permalink
Fixed Twig coding standards.
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexSkrypnyk committed Nov 6, 2023
1 parent 40af895 commit d262b55
Show file tree
Hide file tree
Showing 36 changed files with 86 additions and 87 deletions.
15 changes: 13 additions & 2 deletions .twig_cs.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,22 @@

use FriendsOfTwig\Twigcs;

// Exclude directories with compiled components.
$excluded = [
'.components-civictheme',
'components_combined',
];

// Filter-out stories templates
$filter = function (\SplFileInfo $fileInfo) {
return !str_contains($fileInfo->getFilename(), 'stories');
};

return Twigcs\Config\Config::create()
->setName('custom-config')
->setSeverity('error')
->setReporter('console')
->setRuleSet(Twigcs\Ruleset\Official::class)
->addFinder(Twigcs\Finder\TemplateFinder::create()->in(__DIR__ . '/web/modules/custom'))
->addFinder(Twigcs\Finder\TemplateFinder::create()->in(__DIR__ . '/web/themes/contrib/civictheme'))
->addFinder(Twigcs\Finder\TemplateFinder::create()->in(__DIR__ . '/web/themes/custom'));
->addFinder(Twigcs\Finder\TemplateFinder::create()->in(__DIR__ . '/web/themes/contrib/civictheme')->exclude($excluded)->filter($filter))
->addFinder(Twigcs\Finder\TemplateFinder::create()->in(__DIR__ . '/web/themes/custom')->exclude($excluded)->filter($filter));
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
<div class="example-container__content story-colors-wrapper story-wrapper-size--large">
{% for color_name, color in colors %}
<div class="story-color-{{ theme }}--{{ color_name }}">
<span class="story-color-element" title="{{ color_name }}"></span><span class="story-color-text" title="{{ color_name }}">{{ color_name|capitalize|replace({'-':' '}) }}</span>
<span class="story-color-element" title="{{ color_name }}"></span><span class="story-color-text" title="{{ color_name }}">{{ color_name|capitalize|replace({'-': ' '}) }}</span>
</div>
{% endfor %}
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
{% if symbol is not empty %}
{% set source = source(assets_dir ~ '/icons/' ~ symbol ~ '.svg', true) %}
{% if source is not empty %}
{% set attributes = 'class="ct-icon ' ~ (size ? 'ct-icon--size-' ~ size : '') ~ ' ' ~ modifier_class|default('') ~ '" aria-hidden="true" role="img" ' ~ (alt is defined ? 'alt="' ~ alt ~ '"' : '') ~ attributes|default('') %}
{% set attributes = 'class="ct-icon ' ~ (size ? 'ct-icon--size-' ~ size : '') ~ ' ' ~ modifier_class|default('') ~ '" aria-hidden="true" role="img" ' ~ (alt is defined ? 'alt="' ~ alt ~ '"' : '') ~ attributes|default('') %}
{{ source|replace({'<svg ': '<svg ' ~ attributes ~ ' '})|raw }}
{% endif %}
{% endif %}
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
{% set type_class = type ? 'ct-button--%s'|format(type) : '' %}
{% set kind_class = kind ? 'ct-button--%s'|format(kind) : '' %}
{% set size_class = 'ct-button--%s'|format(size) %}
{% set dismiss_class = is_dismissable ? 'ct-button--dismiss' : '' %}
{% set dismiss_class = is_dismissable ? 'ct-button--dismiss' : '' %}
{% set is_external = is_external ? 'ct-button--external' : '' %}
{% set theme_class = 'ct-theme-%s'|format(theme|default('light')) %}
{% set modifier_class = '%s %s %s %s %s %s %s'|format(theme_class, type_class, kind_class, size_class, dismiss_class, is_external, modifier_class|default('')) %}
Expand Down Expand Up @@ -93,7 +93,7 @@
type="{{ kind }}"
class="ct-button {{ modifier_class }}"
data-component-name="button"
value="{{ (is_raw_text ? text|raw : text) |trim }}"
value="{{ (is_raw_text ? text|raw : text)|trim }}"
{% if is_disabled %}disabled="disabled" aria-disabled="true"{% endif %}
{% if attributes is not empty %}{{ attributes|raw }}{% endif %}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
{% set kind_class = kind ? 'ct-chip--%s'|format(kind) : '' %}
{% set size = size in ['large', 'regular', 'small'] ? size : 'regular' %}
{% set size_class = 'ct-chip--%s'|format(size) %}
{% set selected_class = is_selected ? 'active' : '' %}
{% set selected_class = is_selected ? 'active' : '' %}
{% set multiple_class = is_multiple ? 'ct-chip--multiple' : '' %}
{% set theme_class = 'ct-theme-%s'|format(theme|default('light')) %}
{% set modifier_class = '%s %s %s %s %s %s'|format(theme_class, kind_class, size_class, selected_class, multiple_class, modifier_class|default('')) %}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
#}

{% set text = text|default('') %}
{% set only_icon_class = icon is not empty and text is empty ? 'ct-link--only-icon' : '' %}
{% set only_icon_class = icon is not empty and text is empty ? 'ct-link--only-icon' : '' %}
{% set icon_placement = icon_placement in ['before', 'after'] ? icon_placement : 'after' %}
{% set is_external_class = is_external ? 'ct-link--external' : '' %}
{% set is_active_class = is_active ? 'ct-link--active' : '' %}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
{% set icon_class = icon is not empty ? 'ct-tag--with-icon' : '' %}
{% set icon_placement = icon_placement in ['before', 'after'] ? icon_placement : 'after' %}
{% set icon_placement_class = icon ? 'ct-tag--icon-%s'|format(icon_placement|default('before')) : '' %}
{% set is_external = is_external ? 'ct-tag--external': '' %}
{% set is_external = is_external ? 'ct-tag--external' : '' %}
{% set theme_class = 'ct-theme-%s'|format(theme|default('light')) %}
{% set modifier_class = '%s %s %s %s %s %s'|format(theme_class, type_class, icon_class, icon_placement_class, is_external, modifier_class|default('')) %}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@

{% block links %}
{% set link_items = [] %}
{% for k, file in files %}
{% for file in files %}
{%- set link %}
{% include '@base/icon/icon.twig' with {
symbol: file.icon ? file.icon : 'download-file',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
<nav class="ct-breadcrumb {{ modifier_class }}" aria-label="breadcrumb" {% if attributes is not empty %}{{ attributes|raw }}{% endif %}>
{% set link_items = [] %}

{% for key, link in links %}
{% for link in links %}
{% set link_item %}
{% set link = {
text: link.text,
Expand All @@ -42,7 +42,7 @@
{% endif %}
{% endset %}

{% set link_items = link_items|merge([ link_item ]) %}
{% set link_items = link_items|merge([link_item]) %}

{% if loop.index < links_count %}
{% set link_item %}
Expand All @@ -51,7 +51,7 @@
modifier_class: 'ct-breadcrumb__links__separator',
} only %}
{% endset %}
{% set link_items = link_items|merge([ link_item ]) %}
{% set link_items = link_items|merge([link_item]) %}
{% endif %}

{% if loop.index == links_count - 1 %}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@

{% block links %}
{% set link_items = [] %}
{% for k, link in links %}
{% for link in links %}
{%- set link %}
{% include '@atoms/button/button.twig' with {
theme: theme,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,17 @@
* - description_modifier_class: [string] Additional classes for description.
* - attributes: [string] Additional attributes.
* - modifier_class: [string] Additional classes.
*
* - id: [string] DOM Id.
*/
#}

{% set theme_class = 'ct-theme-%s'|format(theme|default('light')) %}
{% set type_class = type is not empty ? 'ct-form-element--%s'|format(type) : '' %}
{% set name_class = name is not empty ? 'ct-form-element--%s'|format(name) : '' %}
{% set type_class = type is not empty ? 'ct-form-element--%s'|format(type) : '' %}
{% set name_class = name is not empty ? 'ct-form-element--%s'|format(name) : '' %}
{% set label_class = label_display not in ['after', 'before'] ? 'ct-form-element--no-label' : 'ct-form-element--label--%s'|format(title_display) %}
{% set description_class = description_display not in ['after', 'before'] ? 'ct-form-element--no-description' : 'ct-form-element--label--%s'|format(description_display) %}
{% set disabled_class = disabled == 'disabled' ? 'ct-form-element--form-disabled' : '' %}
{% set error_class = errors is not empty ? 'ct-form-element--error' : '' %}
{% set disabled_class = disabled == 'disabled' ? 'ct-form-element--form-disabled' : '' %}
{% set error_class = errors is not empty ? 'ct-form-element--error' : '' %}
{% set modifier_class = '%s %s %s %s %s %s %s %s'|format(theme_class, type_class, name_class, label_class, description_class, disabled_class, error_class, modifier_class|default('')) %}

{% set description_modifier_class = '%s %s'|format(description_visibility_class|default(''), description_display_class|default('')) %}
Expand All @@ -49,7 +48,7 @@
{% include '@atoms/field-description/field-description.twig' with {
theme: theme,
content: description,
modifier_class: 'ct-form-element__description',
modifier_class: 'ct-form-element__description ' ~ description_modifier_class,
} only %}
{% endif %}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@
{% endblock %}

{% block filters %}
{% set group = 'ct-group-filter--group-' ~ random(1000,9999) %}
{% set group = 'ct-group-filter--group-' ~ random(1000, 9999) %}
{% set filters_items = [] %}
{% for key, filter in filters %}
{% for filter in filters %}
{% set filters_item %}
{% include '@atoms/popover/popover.twig' with {
theme: theme,
Expand All @@ -56,7 +56,7 @@
group: group,
} only %}
{% endset %}
{% set filters_items = filters_items|merge([ filters_item ]) %}
{% set filters_items = filters_items|merge([filters_item]) %}
{% endfor %}

{% if form_attributes is not empty %}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
{% set type = type in ['default', 'inline', 'stacked', 'inline-stacked'] ? type : 'default' %}
{% set type_class = 'ct-logo--%s'|format(type|default('default')) %}
{% set theme_class = 'ct-theme-%s'|format(theme|default('light')) %}
{% set modifier_class = '%s %s %s'|format(theme_class, type_class, modifier_class|default('')) %}
{% set modifier_class = '%s %s %s'|format(theme_class, type_class, modifier_class|default('')) %}

{% if logos is not empty %}
{% if url is not empty %}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@
#}

{% set with_image = image.url is not empty %}
{% set with_image_class = with_image ? 'ct-navigation-card--with-image': '' %}
{% set with_image_class = with_image ? 'ct-navigation-card--with-image' : '' %}
{% set with_link = link is not empty and link.url is defined and link.url is not empty %}
{% set with_link_class = with_link ? 'ct-navigation-card--with-link': '' %}
{% set with_link_class = with_link ? 'ct-navigation-card--with-link' : '' %}
{% set image_as_icon_class = image_as_icon ? 'ct-navigation-card--image-as-icon' : '' %}
{% set theme_class = 'ct-theme-%s'|format(theme|default('light')) %}
{% set modifier_class = '%s %s %s %s %s'|format(theme_class, with_image_class, with_link_class, image_as_icon_class, modifier_class|default('')) %}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
#}

{% set with_image = image.url is not empty %}
{% set with_image_class = with_image ? 'ct-publication-card--with-image': '' %}
{% set with_image_class = with_image ? 'ct-publication-card--with-image' : '' %}
{% set theme_class = 'ct-theme-%s'|format(theme|default('light')) %}
{% set modifier_class = '%s %s %s %s'|format(theme_class, with_image_class, with_link_class, modifier_class|default('')) %}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@
{% set modifier_class = '%s %s %s'|format(theme_class, vertical_spacing_class, modifier_class|default('')) %}

{% if content is not empty %}
<figure class="ct-quote {{ modifier_class }}" {% if attributes is not empty %}{{ attributes|raw }}{% endif%}>
<figure class="ct-quote {{ modifier_class }}" {% if attributes is not empty %}{{ attributes|raw }}{% endif %}>
<blockquote class="ct-quote__content">
{{ content }}
</blockquote>
{%- if author %}
<figcaption class="ct-quote__author">
{{ author }}
</figcaption>
{% endif -%}
{% endif -%}
</figure>
{% endif %}
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
{% block links %}
{% if links is not empty %}
{% set list_items = [] %}
{% for key, link in links %}
{% for link in links %}
{% if link.text is not empty %}
{% set list_item %}
{% include '@atoms/link/link.twig' with {
Expand All @@ -57,7 +57,7 @@
is_external: link.is_external is defined ? link.is_external : false,
} only %}
{% endset %}
{% set list_items = list_items|merge([ list_item ]) %}
{% set list_items = list_items|merge([list_item]) %}
{% endif %}
{% endfor %}
{% include '@base/item-list/item-list.twig' with {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
{% if item.text is not empty %}
{% set item_attributes = item.attributes is defined and item.attributes is not empty ? item.attributes : '' %}
{% set item_name = item.name is defined ? item.name : (is_multiple ? 'single-filter-' ~ loop.index : 'single-filter') %}
{% set item_attributes = 'name' not in item_attributes ? item_attributes ~ ' name="' ~ item_name ~ '"' : item_attributes %}
{% set item_attributes = 'name' not in item_attributes ? item_attributes ~ ' name="' ~ item_name ~ '"' : item_attributes %}
{% include '@atoms/chip/chip.twig' with {
theme: theme,
kind: 'input',
Expand All @@ -60,7 +60,7 @@
} only %}
{% endif %}
{% endset %}
{% set filter_items = filter_items|merge([ filter_item ]) %}
{% set filter_items = filter_items|merge([filter_item]) %}
{% endfor %}

{% if form_attributes is not empty %}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,14 @@
{% block content %}
{% if tags %}
{% set tag_items = [] %}
{% for key, tag in tags %}
{% for tag in tags %}
{% set tag_item %}
{% include '@atoms/tag/tag.twig' with {
theme: theme,
content: tag,
} only %}
{% endset %}
{% set tag_items = tag_items|merge([ tag_item ]) %}
{% set tag_items = tag_items|merge([tag_item]) %}
{% endfor %}
{% include '@base/item-list/item-list.twig' with {
items: tag_items,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
{% set theme_class = 'ct-theme-%s'|format(theme|default('light')) %}
{% set type = type|default('information') %}
{% set type_class = 'ct-alert--%s'|format(type|default('information')) %}
{% set modifier_class = '%s %s %s'|format(theme_class, type_class, modifier_class | default('')) %}
{% set modifier_class = '%s %s %s'|format(theme_class, type_class, modifier_class|default('')) %}

{% set icons = {
information: 'information-mark',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
*/
#}

{% set is_decorative_class = is_decorative ? 'ct-banner--decorative': '' %}
{% set is_decorative_class = is_decorative ? 'ct-banner--decorative' : '' %}
{% set theme_class = 'ct-theme-%s'|format(theme|default('light')) %}
{% set modifier_class = '%s %s %s'|format(theme_class, is_decorative_class, modifier_class|default('')) %}

Expand Down Expand Up @@ -155,7 +155,7 @@
{% include '@atoms/image/image.twig' with {
theme: theme,
url: featured_image.url,
alt: featured_image.alt,
alt: featured_image.alt,
modifier_class: 'ct-banner__featured-image',
} only %}
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@
{% block links %}
{% if links is not empty %}
{% set link_items = [] %}
{% for key, link in links %}
{% for link in links %}
{% set link_item %}
{% include '@atoms/button/button.twig' with {
theme: theme,
Expand All @@ -106,7 +106,7 @@
is_new_window: link.is_new_window,
} only %}
{% endset %}
{% set link_items = link_items|merge([ link_item ]) %}
{% set link_items = link_items|merge([link_item]) %}
{% endfor %}

{% include '@base/item-list/item-list.twig' with {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
{% set theme_class = 'ct-theme-%s'|format(theme|default('light')) %}
{% set modifier_class = '%s %s'|format(theme_class, modifier_class|default('')) %}

{% if content_top1 is not empty or content_top2 is not empty or content_top3 is not empty or content_middle1 is not empty or content_middle2 is not empty or content_middle3 is not empty or content_bottom1 is not empty %}
{% if content_top1 is not empty or content_top2 is not empty or content_top3 is not empty or content_middle1 is not empty or content_middle2 is not empty or content_middle3 is not empty or content_bottom1 is not empty %}
<header class="ct-header {{ modifier_class }}" role="banner">

{% if content_top1 is not empty or content_top2 is not empty or content_top3 is not empty %}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
{% set type = type|default('information') %}
{% set type_class = 'ct-message--%s'|format(type) %}
{% set theme_class = 'ct-theme-%s'|format(theme|default('light')) %}
{% set modifier_class = '%s %s %s'|format(theme_class, type_class, modifier_class | default('')) %}
{% set modifier_class = '%s %s %s'|format(theme_class, type_class, modifier_class|default('')) %}

{% set icons = {
information: 'information-mark',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,13 @@
{% set item_dropdown_columns_fill_class = dropdown_columns_fill ? 'ct-navigation__dropdown-columns--fill' : '' %}
{% set item_modifier_class = 'ct-navigation__has-dropdown %s %s'|format(item_dropdown_columns_class, item_dropdown_columns_fill_class) %}
{# Update item with attributes and classes. #}
{% set new_item = items[key]|merge({'attributes': item_attributes, 'modifier_class': item_modifier_class }) %}
{% set new_item = items[key]|merge({'attributes': item_attributes, 'modifier_class': item_modifier_class}) %}
{% set items = items|merge({(key): new_item}) %}
{% else %}
{# Item classes to style dynamically. #}
{% set item_modifier_class = 'ct-navigation__has-dropdown' %}
{# Update item with attributes and classes. #}
{% set new_item = items[key]|merge({'attributes': item_attributes, 'modifier_class': item_modifier_class }) %}
{% set new_item = items[key]|merge({'attributes': item_attributes, 'modifier_class': item_modifier_class}) %}
{% set items = items|merge({(key): new_item}) %}
{% endif %}
{% endif %}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@
{% block links %}
{% if links is not empty %}
{% set link_items = [] %}
{% for key, link in links %}
{% for link in links %}
{% set link_item %}
{% include '@atoms/button/button.twig' with {
theme: theme,
Expand All @@ -118,7 +118,7 @@
modifier_class: 'ct-slide__links__link',
} only %}
{% endset %}
{% set link_items = link_items|merge([ link_item ]) %}
{% set link_items = link_items|merge([link_item]) %}
{% endfor %}

{% include '@base/item-list/item-list.twig' with {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

{% block items %}
{% set items_rendered = [] %}
{% for k, item in items %}
{% for item in items %}
{%- set item_rendered %}
{% include '@atoms/button/button.twig' with {
theme: theme,
Expand Down
Loading

0 comments on commit d262b55

Please sign in to comment.