From cbd77c720178ced3dcd723008fef2b7cc2401a8c Mon Sep 17 00:00:00 2001 From: Kenneth Ormandy Date: Sun, 28 Jul 2024 14:43:32 -0700 Subject: [PATCH 1/3] Removes use of `jsonPrettyPrint` in favour of built-in pretty printing --- src/helpers/ComponentViewerHelper.php | 11 +++++++++-- .../blocks/unknown-block/unknown-block.twig | 2 +- src/templates/_components/cards/date/readme.md | 4 +++- src/templates/_components/utils/dump/dump.twig | 2 +- 4 files changed, 14 insertions(+), 5 deletions(-) diff --git a/src/helpers/ComponentViewerHelper.php b/src/helpers/ComponentViewerHelper.php index 02de173..a67bcae 100644 --- a/src/helpers/ComponentViewerHelper.php +++ b/src/helpers/ComponentViewerHelper.php @@ -139,7 +139,14 @@ public static function getComponent($componentId = '', $variant = null): array try { $readme = file_get_contents(self::getComponentReadmePath($componentId, $componentConfigPath)); } catch (\Exception) { - $readme = 'Tags: {{ tags|join(",") }}

{{ title }}: {{ handle }}

{% include "@{{ handle }}" with {{ jsonPrettyPrint(context) }} %}
'; + $readme = 'Tags: {{ tags|join(",") }}

{{ title }}: {{ handle }}

{% include \'@{{ handle }}\'';
+            
+            // Only show `with { … }` in the include example if context exists
+            if ($context) {
+                $readme = $readme . ' with {{ context|json_encode(constant(\'JSON_PRETTY_PRINT\')) }}';
+            }
+
+            $readme = $readme . ' %}
'; } try { $parser = new Markdown(); @@ -151,7 +158,7 @@ public static function getComponent($componentId = '', $variant = null): array return [ 'config' => $componentConfig, - 'context' => self::getComponentContext($componentId, $variant), + 'context' => $context, 'readme' => $readme, 'twig' => $twigString, 'rendered' => $rendered, diff --git a/src/templates/_components/blocks/unknown-block/unknown-block.twig b/src/templates/_components/blocks/unknown-block/unknown-block.twig index 5d13fd5..a985d8d 100644 --- a/src/templates/_components/blocks/unknown-block/unknown-block.twig +++ b/src/templates/_components/blocks/unknown-block/unknown-block.twig @@ -12,7 +12,7 @@ {% endif %}

Block data:

{% if data is defined %} -
{{ jsonPrettyPrint(data) }}
+
{{ data|json_encode(constant('JSON_PRETTY_PRINT')) }}
{% endif %} {% endif %} diff --git a/src/templates/_components/cards/date/readme.md b/src/templates/_components/cards/date/readme.md index 9ad584e..2f67554 100644 --- a/src/templates/_components/cards/date/readme.md +++ b/src/templates/_components/cards/date/readme.md @@ -1,7 +1,9 @@ Tags: {{ tags|join(',') }} +Hello +

{{ title }}: {{ handle }}


-{% include '{{ handle }}' with {{ jsonPrettyPrint(context) }} %}
+{% include '{{ handle }}' with {{ context|json_encode(constant("JSON_PRETTY_PRINT")) }} %}
 
diff --git a/src/templates/_components/utils/dump/dump.twig b/src/templates/_components/utils/dump/dump.twig index fe44d8a..abae907 100644 --- a/src/templates/_components/utils/dump/dump.twig +++ b/src/templates/_components/utils/dump/dump.twig @@ -1,4 +1,4 @@ {% if data is not defined %} {% set data = contextData|default(_context) %} {% endif %} -
{{ jsonPrettyPrint(data) }}
+
{{ data|json_encode(constant('JSON_PRETTY_PRINT')) }}
From 4476ce9ddd7eb8db0b9d362b12044dd94754c52e Mon Sep 17 00:00:00 2001 From: Kenneth Ormandy Date: Sun, 28 Jul 2024 14:43:55 -0700 Subject: [PATCH 2/3] Adds overriding of context per variant in default README --- src/helpers/ComponentViewerHelper.php | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/helpers/ComponentViewerHelper.php b/src/helpers/ComponentViewerHelper.php index a67bcae..b9bc0c6 100644 --- a/src/helpers/ComponentViewerHelper.php +++ b/src/helpers/ComponentViewerHelper.php @@ -130,8 +130,15 @@ public static function getComponent($componentId = '', $variant = null): array $componentConfigPath = $componentMap[$componentId]; $twigString = file_get_contents($componentConfigPath); $componentConfig = Json::decode(file_get_contents(self::getComponentConfigPath($componentConfigPath))); + $context = self::getComponentContext($componentId, $variant); + + // Override the default context with the variant context + if ($context) { + $componentConfig['context'] = $context; + } + try { - $rendered = Craft::$app->view->renderString($twigString, self::getComponentContext($componentId, $variant)); + $rendered = Craft::$app->view->renderString($twigString, $context); } catch (\Exception $e) { $rendered = $e->getMessage(); } From 02b88e5bfba6aff501d6da7ccf9f1950b0e3a5c6 Mon Sep 17 00:00:00 2001 From: Kenneth Ormandy Date: Sun, 28 Jul 2024 14:44:23 -0700 Subject: [PATCH 3/3] Removes use of `arrayToAttributes` in favour of built-in `attr` --- src/templates/_components/atoms/btn/btn.twig | 4 ++-- src/templates/_components/atoms/burger-btn/burger-btn.twig | 2 +- src/templates/_components/atoms/chip/chip.twig | 2 +- .../_components/atoms/icons/icon-24-arrow-left.twig | 2 +- .../_components/atoms/icons/icon-24-arrow-right.twig | 2 +- .../_components/atoms/icons/icon-24-arrow-top-right.twig | 2 +- src/templates/_components/atoms/icons/icon-24-burger.twig | 2 +- .../_components/atoms/icons/icon-24-chevron-down.twig | 2 +- .../_components/atoms/icons/icon-24-chevron-left.twig | 2 +- .../_components/atoms/icons/icon-24-chevron-right.twig | 2 +- src/templates/_components/atoms/icons/icon-24-cross.twig | 2 +- src/templates/_components/atoms/icons/icon-24-facebook.twig | 2 +- src/templates/_components/atoms/icons/icon-24-link.twig | 2 +- src/templates/_components/atoms/icons/icon-24-search.twig | 2 +- .../_components/atoms/icons/icon-24-thumbs-down.twig | 2 +- .../_components/atoms/icons/icon-24-thumbs-up.twig | 2 +- src/templates/_components/atoms/icons/icon-24-tick.twig | 2 +- src/templates/_components/atoms/icons/icon-24-twitter.twig | 2 +- src/templates/_components/atoms/icons/icon-24-user-2.twig | 2 +- src/templates/_components/atoms/icons/icon-24-user.twig | 2 +- .../_components/atoms/icons/icon-arrow-down-right.twig | 2 +- src/templates/_components/atoms/icons/icon-play.twig | 4 ++-- src/templates/_components/atoms/icons/logo-large.twig | 2 +- src/templates/_components/atoms/icons/logo-mark-large.twig | 2 +- src/templates/_components/atoms/icons/logo-mark-small.twig | 2 +- src/templates/_components/atoms/icons/logo-small.twig | 2 +- src/templates/_components/atoms/img/img.twig | 6 +++--- src/templates/_components/atoms/label/label.twig | 2 +- src/templates/_components/atoms/link/link.twig | 4 ++-- .../_components/atoms/logo-splash/logo-splash.twig | 2 +- src/templates/_components/atoms/topic/topic.twig | 2 +- src/templates/_components/atoms/video/video.twig | 4 ++-- .../behavior-blocks/filter-select/filter-select.twig | 4 ++-- .../behavior-blocks/listing-block/listing-block.twig | 2 +- .../behavior-blocks/multi-select/multi-select.twig | 2 +- src/templates/_components/behavior-blocks/tabs/tabs.twig | 2 +- src/templates/_components/blocks/accordion/accordion.twig | 2 +- src/templates/_components/blocks/blockquote/blockquote.twig | 2 +- src/templates/_components/blocks/image/image.twig | 2 +- src/templates/_components/blocks/video/video.twig | 2 +- src/templates/_components/cards/date/date.twig | 4 ++-- src/templates/_components/cards/image/image.twig | 4 ++-- src/templates/_components/cards/stat/stat.twig | 4 ++-- .../_components/features/expressive/expressive.twig | 2 +- src/templates/_components/form/checkbox/checkbox.twig | 4 ++-- src/templates/_components/form/field-group/field-group.twig | 2 +- src/templates/_components/form/hidden/hidden.twig | 2 +- src/templates/_components/form/radio/radio.twig | 2 +- .../_components/form/select-filter/select-filter.twig | 4 ++-- src/templates/_components/form/select/select.twig | 2 +- src/templates/_components/form/text/text.twig | 2 +- src/templates/_components/form/textarea/textarea.twig | 2 +- src/templates/_components/foundation/splashes/dotted.twig | 2 +- .../_components/foundation/splashes/kaleidoscopic-bold.twig | 2 +- .../foundation/splashes/kaleidoscopic-medium.twig | 2 +- .../_components/foundation/splashes/kaleidoscopic.twig | 2 +- src/templates/_components/foundation/splashes/linear.twig | 2 +- src/templates/_components/foundation/splashes/pointed.twig | 2 +- src/templates/_components/foundation/splashes/wedged.twig | 2 +- src/templates/_components/heros/404/404.twig | 2 +- .../_components/heros/default-50:50/default-50:50.twig | 2 +- src/templates/_components/heros/default/default.twig | 2 +- src/templates/_components/heros/feature/feature.twig | 2 +- src/templates/_components/layouts/article/article.twig | 2 +- src/templates/_components/layouts/bio/bio.twig | 2 +- .../_components/layouts/center-column/center-column.twig | 2 +- src/templates/_components/layouts/htv-bio/htv-bio.twig | 2 +- .../_components/layouts/htv-scoring/htv-scoring.twig | 2 +- src/templates/_components/layouts/modal/modal.twig | 2 +- src/templates/_components/layouts/partner/partner.twig | 2 +- .../_components/listings/features-a/features-a.twig | 2 +- .../_components/listings/features-e/features-e.twig | 2 +- src/templates/_components/listings/grid-3/grid-3.twig | 2 +- src/templates/_components/listings/grid-4/grid-4.twig | 2 +- src/templates/_components/repeaters/blocks/blocks.twig | 2 +- src/templates/_components/repeaters/modals/modals.twig | 2 +- 76 files changed, 88 insertions(+), 88 deletions(-) diff --git a/src/templates/_components/atoms/btn/btn.twig b/src/templates/_components/atoms/btn/btn.twig index 291979a..5dec9de 100644 --- a/src/templates/_components/atoms/btn/btn.twig +++ b/src/templates/_components/atoms/btn/btn.twig @@ -12,10 +12,10 @@ {% endif %} {% if href is defined and href is not null %} +? ' disabled' }} {{ attrs is defined ? attr(attrs) }}> {% else %}