From da0036b3ac705ae71bade2e1d16f55258a4fe979 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Simon=20Schwei=C3=9Finger?= Date: Mon, 26 Feb 2024 16:43:51 +0100 Subject: [PATCH] feat: move param-handling into separate functions to make them overwritable #13 --- src/Tags/Picture.php | 64 +++++++++++++++++++++++++++----------------- 1 file changed, 39 insertions(+), 25 deletions(-) diff --git a/src/Tags/Picture.php b/src/Tags/Picture.php index 30adeeb..f987c32 100644 --- a/src/Tags/Picture.php +++ b/src/Tags/Picture.php @@ -62,6 +62,41 @@ public function __call($method, $args): string return $this->output($asset); } + + protected function handleAltText(Picturesque &$picture) + { + // if no param is set, the asset will be checked for an alt text + if ($alt = $this->params->get('alt')) { + $picture->alt($alt); + } + } + + protected function handleCssClasses(Picturesque &$picture) + { + if ($class = $this->params->get('class')) { + $picture->css($class); + } + } + + protected function handleLazyLoading(Picturesque &$picture) + { + // if no param is set, config default is used + if ($this->params->has('lazy')) { + if ($this->params->get('lazy') == false) { + $picture->lazy(false); + } + else { + $picture->lazy(true); + } + } + } + + protected function handleWrapperCssClasses(Picturesque &$picture) + { + if ($wrapperClass = $this->params->get('wrapperClass')) { + $picture->wrapperClass($wrapperClass); + } + } protected function output($asset) { @@ -109,31 +144,10 @@ protected function output($asset) } } - // alt tag - // if no param is set, the asset will be checked for an alt text - if ($alt = $this->params->get('alt')) { - $picture->alt($alt); - } - - // css classes - if ($class = $this->params->get('class')) { - $picture->css($class); - } - - if ($wrapperClass = $this->params->get('wrapperClass')) { - $picture->wrapperClass($wrapperClass); - } - - // lazy loading - // if no param is set, config default is used - if ($this->params->has('lazy')) { - if ($this->params->get('lazy') == false) { - $picture->lazy(false); - } - else { - $picture->lazy(true); - } - } + $this->handleAltText($picture); + $this->handleCssClasses($picture); + $this->handleWrapperCssClasses($picture); + $this->handleLazyLoading($picture); $picture->generate();