diff --git a/src/Pug/Symfony/Traits/HelpersHandler.php b/src/Pug/Symfony/Traits/HelpersHandler.php index b2af19c..724e974 100644 --- a/src/Pug/Symfony/Traits/HelpersHandler.php +++ b/src/Pug/Symfony/Traits/HelpersHandler.php @@ -196,9 +196,13 @@ protected function interpolateTwigFunctions(string $code): string for ($index = 0; $index < $count; $index++) { $token = $tokens[$index]; - if (is_array($token) && $token[0] === T_STRING && $tokens[$index + 1] === '(') { + if (is_array($token) && $token[0] === T_STRING && ($tokens[$index + 1] ?? null) === '(') { if ($token[1] === 'function_exists') { - if ($tokens[$index + 3] === ')' && is_array($tokens[$index + 2]) && $tokens[$index + 2][0] === T_CONSTANT_ENCAPSED_STRING && isset($this->twigHelpers[substr($tokens[$index + 2][1], 1, -1)])) { + if ($tokens[$index + 3] === ')' && + is_array($tokens[$index + 2]) && + $tokens[$index + 2][0] === T_CONSTANT_ENCAPSED_STRING && + isset($this->twigHelpers[substr($tokens[$index + 2][1], 1, -1)]) + ) { $output .= 'true'; $index += 3; continue; diff --git a/tests/Pug/PugSymfonyBundle/Command/AssetsPublishCommandTest.php b/tests/Pug/PugSymfonyBundle/Command/AssetsPublishCommandTest.php index 16f4b05..0b8ff09 100644 --- a/tests/Pug/PugSymfonyBundle/Command/AssetsPublishCommandTest.php +++ b/tests/Pug/PugSymfonyBundle/Command/AssetsPublishCommandTest.php @@ -45,7 +45,7 @@ public function testCommand() file_put_contents($customHelperFile, $customHelper); file_put_contents($stylePhpFile, $stylePhp); - $this->assertStringContainsString('15 templates cached', $output, 'All templates can be cached except filter.pug as the upper filter does not exists.'); + $this->assertStringContainsString('16 templates cached', $output, 'All templates can be cached except filter.pug as the upper filter does not exists.'); $this->assertStringContainsString('1 templates failed to be cached', $output, 'filter.pug fails as the upper filter does not exists.'); $this->assertRegExp('/(Unknown\sfilter\supper|upper:\sFilter\sdoes\s?n[\'o]t\sexists)/', $output, 'filter.pug fails as the upper filter does not exists.'); $this->assertStringContainsString('filter.pug', $output, 'filter.pug fails as the upper filter does not exists.'); diff --git a/tests/Pug/PugSymfonyEngineTest.php b/tests/Pug/PugSymfonyEngineTest.php index 5db3e28..7406ba9 100644 --- a/tests/Pug/PugSymfonyEngineTest.php +++ b/tests/Pug/PugSymfonyEngineTest.php @@ -146,6 +146,18 @@ public function testPreRenderPhp() ); } + public function testMixin() + { + $pugSymfony = new PugSymfonyEngine(self::$kernel); + $pugSymfony->setOption('expressionLanguage', 'js'); + $pugSymfony->setOption('prettyprint', false); + + self::assertSame( + '', + $pugSymfony->render('mixin.pug') + ); + } + /** * @throws ErrorException */ diff --git a/tests/project-s5/templates/mixin.pug b/tests/project-s5/templates/mixin.pug new file mode 100644 index 0000000..dbdfaa6 --- /dev/null +++ b/tests/project-s5/templates/mixin.pug @@ -0,0 +1,6 @@ +mixin pet(name) + li.pet= name +ul + +pet('cat') + +pet('dog') + +pet('pig')