diff --git a/composer.json b/composer.json index b74a529..26272e7 100644 --- a/composer.json +++ b/composer.json @@ -1,6 +1,6 @@ { "name": "newtron/core", - "version": "0.1.3", + "version": "0.1.4", "type": "library", "description": "Core framework package for Newtron", "homepage": "https://github.com/newtron-framework/core", diff --git a/src/Quark/QuarkCompiler.php b/src/Quark/QuarkCompiler.php index 39fb6dc..df83be9 100644 --- a/src/Quark/QuarkCompiler.php +++ b/src/Quark/QuarkCompiler.php @@ -98,7 +98,7 @@ private function registerBuiltinDirectives(): void { $data = "compact(" . implode(', ', $quotedVars) . ")"; } - return "echo \$__quark->render('{$template}', {$data});\n"; + return "echo \$__quark->render('{$template}', {$data}, [], true);\n"; } throw new \Exception("Invalid include syntax: {$args}"); }; @@ -126,7 +126,7 @@ private function registerBuiltinDirectives(): void { */ private function tokenize(string $source): array { $tokens = []; - $pattern = '/\{\{(.*?)\}\}|\{%(.*?)%\}/s'; + $pattern = '/\{\{(.*?)\}\}|(~[a-zA-Z\-_]+\([^~]*\))/s'; $lastPos = 0; preg_match_all($pattern, $source, $matches, PREG_OFFSET_CAPTURE); @@ -167,7 +167,7 @@ private function tokenize(string $source): array { * @throws \Exception If the directive syntax is invalid */ private function parseDirective(string $directive): array { - if (preg_match('/^(\w+)(?:\s+(.+))?$/', $directive, $matches)) { + if (preg_match('/^~(\w+)\((.*)\)$/', $directive, $matches)) { return [ 'type' => 'directive', 'name' => $matches[1], diff --git a/tests/Unit/Quark/QuarkCompilerTest.php b/tests/Unit/Quark/QuarkCompilerTest.php index c3ac740..297cca7 100644 --- a/tests/Unit/Quark/QuarkCompilerTest.php +++ b/tests/Unit/Quark/QuarkCompilerTest.php @@ -52,7 +52,7 @@ public function testAddDirective(): void { $this->assertArrayHasKey('test', $directives); $this->assertEquals( "';\necho 'test_directive_ran';\necho '';\n", - $this->compiler->compile('
{{ test }}
'); + $this->createTestTemplate('layout', '{{ test }}
'); $this->assertEquals( 'Test Value
{{ test }}
'); $this->engine->setRootLayout('root'); @@ -66,7 +66,7 @@ public function testRenderTemplateWithRootLayout(): void { } public function testRenderTemplateWithSkipRootLayout(): void { - $this->createTestTemplate('root', '{{ test }}
'); $this->engine->setRootLayout('root'); $this->engine->skipRootLayout(); @@ -78,8 +78,8 @@ public function testRenderTemplateWithSkipRootLayout(): void { } public function testRenderTemplateWithSkipRootDirective(): void { - $this->createTestTemplate('root', '{{ test }}
'); + $this->createTestTemplate('root', '{{ test }}
'); $this->engine->setRootLayout('root'); $this->assertEquals( @@ -89,8 +89,8 @@ public function testRenderTemplateWithSkipRootDirective(): void { } public function testRenderTemplateWithCustomOutlet(): void { - $this->createTestTemplate('layout', '{{ test }}
{% endslot %}'); + $this->createTestTemplate('layout', '{{ test }}
~endslot()'); $this->assertEquals( 'Test Value
Included
'); $this->assertEquals( @@ -109,7 +109,7 @@ public function testRenderTemplateWithInclude(): void { } public function testRenderTemplateWithIf(): void { - $this->createTestTemplate('test', '{{ $item[\'name\'] }}
{% endforeach %}{{ $item[\'name\'] }}
~endforeach()