diff --git a/src/Modello.php b/src/Modello.php index 28e46df..db5d693 100644 --- a/src/Modello.php +++ b/src/Modello.php @@ -16,8 +16,7 @@ class Modello private array $handlers = [ 'handleIncludes', 'handleBlocks', - 'handleHasBlock', - 'handleBlockMissing', + 'handleBlockConditionals', 'handleYields', 'handleEchoes', 'handleEscapedEchoes', @@ -208,18 +207,11 @@ private function handleIncludes(string $view): string private function handleBlocks(string $page): string { preg_match_all('/@block\( ?\'(\w*?)\' ?\)(.*?)@endblock/is', $page, $matches, PREG_SET_ORDER); + preg_match_all('/@block\( ?\'(\w*?)\', ?\'(\N*?)\' ?\)/is', $page, $inlineMatches, PREG_SET_ORDER); + $matches = array_merge($matches, $inlineMatches); foreach ($matches as $match) { - if (!array_key_exists($match[1], $this->blocks)) { - $this->blocks[$match[1]] = ''; - } - - if (strpos($match[2], '@parent') === false) { - $this->blocks[$match[1]] = trim($match[2]); - } else { - $this->blocks[$match[1]] = trim(str_replace('@parent', $this->blocks[$match[1]], $match[2])); - } - + $this->blocks[$match[1]] = $match[2]; $page = str_replace($match[0], '', $page); } @@ -285,24 +277,17 @@ private function handleComment(string $page): string } // A directive to test whether we have a block by a given key - function handleHasBlock(string $page): string + function handleBlockConditionals(string $page): string { - preg_match_all('/@hasblock\( ?\'(\w*?)\' ?\)(.*?)@endif/is', $page, $matches, PREG_SET_ORDER); + preg_match_all('/@hasblock\( ?\'(\w*?)\' ?\)(.*?)@endif/is', $page, $has, PREG_SET_ORDER); + preg_match_all('/@blockmissing\( ?\'(\w*?)\' ?\)(.*?)@endif/is', $page, $missing, PREG_SET_ORDER); - foreach ($matches as $match) { + foreach ($has as $match) { $replace = array_key_exists($match[1], $this->blocks) ? $match[2] : ''; $page = str_replace($match[0], $replace, $page); } - - return $page; - } - - // Directive that does the opposite of @hasblock - function handleBlockMissing(string $page): string - { - preg_match_all('/@blockmissing\( ?\'(\w*?)\' ?\)(.*?)@endif/is', $page, $matches, PREG_SET_ORDER); - foreach ($matches as $match) { + foreach ($missing as $match) { $replace = !array_key_exists($match[1], $this->blocks) ? $match[2] : ''; $page = str_replace($match[0], $replace, $page); }