From 77fa4479f58ff434fde0dac919ad2ffc83640118 Mon Sep 17 00:00:00 2001 From: James <78121730+itsnewtjam@users.noreply.github.com> Date: Tue, 30 Sep 2025 20:00:46 -0400 Subject: [PATCH 1/2] Quark updates (#29) * fix multiple roots with include * update directive syntax --- src/Quark/QuarkCompiler.php | 6 +++--- tests/Unit/Quark/QuarkCompilerTest.php | 6 +++--- tests/Unit/Quark/QuarkEngineTest.php | 26 +++++++++++++------------- 3 files changed, 19 insertions(+), 19 deletions(-) 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->compiler->compile('
~test()
') ); } @@ -68,7 +68,7 @@ public function testTokenizeSource(): void { ['type' => 'text', 'content' => ''], ['type' => 'directive', 'name' => 'outlet', 'args' => ''], ], - $method->invoke($this->compiler, '
{{ test }}
{% outlet %}') + $method->invoke($this->compiler, '
{{ test }}
~outlet()') ); } @@ -79,7 +79,7 @@ public function testParseDirective(): void { $this->assertEquals( ['type' => 'directive', 'name' => 'outlet', 'args' => 'custom'], - $method->invoke($this->compiler, 'outlet custom') + $method->invoke($this->compiler, '~outlet(custom)') ); } diff --git a/tests/Unit/Quark/QuarkEngineTest.php b/tests/Unit/Quark/QuarkEngineTest.php index 64a496a..948bbcc 100644 --- a/tests/Unit/Quark/QuarkEngineTest.php +++ b/tests/Unit/Quark/QuarkEngineTest.php @@ -45,8 +45,8 @@ public function testRenderTemplate(): void { } public function testRenderTemplateWithLayout(): void { - $this->createTestTemplate('layout', '
{% outlet %}
'); - $this->createTestTemplate('test', '{% layout layout %}

{{ test }}

'); + $this->createTestTemplate('layout', '
~outlet()
'); + $this->createTestTemplate('test', '~layout(layout)

{{ test }}

'); $this->assertEquals( '

Test Value

', @@ -55,7 +55,7 @@ public function testRenderTemplateWithLayout(): void { } public function testRenderTemplateWithRootLayout(): void { - $this->createTestTemplate('root', '
{% outlet %}
'); + $this->createTestTemplate('root', '
~outlet()
'); $this->createTestTemplate('test', '

{{ test }}

'); $this->engine->setRootLayout('root'); @@ -66,7 +66,7 @@ public function testRenderTemplateWithRootLayout(): void { } public function testRenderTemplateWithSkipRootLayout(): void { - $this->createTestTemplate('root', '
{% outlet %}
'); + $this->createTestTemplate('root', '
~outlet()
'); $this->createTestTemplate('test', '

{{ test }}

'); $this->engine->setRootLayout('root'); $this->engine->skipRootLayout(); @@ -78,8 +78,8 @@ public function testRenderTemplateWithSkipRootLayout(): void { } public function testRenderTemplateWithSkipRootDirective(): void { - $this->createTestTemplate('root', '
{% outlet %}
'); - $this->createTestTemplate('test', '{% skip_root %}

{{ test }}

'); + $this->createTestTemplate('root', '
~outlet()
'); + $this->createTestTemplate('test', '~skip_root()

{{ test }}

'); $this->engine->setRootLayout('root'); $this->assertEquals( @@ -89,8 +89,8 @@ public function testRenderTemplateWithSkipRootDirective(): void { } public function testRenderTemplateWithCustomOutlet(): void { - $this->createTestTemplate('layout', '
{% outlet custom %}
'); - $this->createTestTemplate('test', '{% layout layout %}{% slot custom %}

{{ test }}

{% endslot %}'); + $this->createTestTemplate('layout', '
~outlet(custom)
'); + $this->createTestTemplate('test', '~layout(layout)~slot(custom)

{{ test }}

~endslot()'); $this->assertEquals( '

Test Value

', @@ -99,7 +99,7 @@ public function testRenderTemplateWithCustomOutlet(): void { } public function testRenderTemplateWithInclude(): void { - $this->createTestTemplate('test', '
{% include included %}
'); + $this->createTestTemplate('test', '
~include(included)
'); $this->createTestTemplate('included', '

Included

'); $this->assertEquals( @@ -109,7 +109,7 @@ public function testRenderTemplateWithInclude(): void { } public function testRenderTemplateWithIf(): void { - $this->createTestTemplate('test', '
{% if $test %}True{% endif %}
'); + $this->createTestTemplate('test', '
~if($test)True~endif()
'); $this->assertEquals( '
', @@ -124,7 +124,7 @@ public function testRenderTemplateWithIf(): void { public function testRenderTemplateWithIfWithElses(): void { $this->createTestTemplate( 'test', - '
{% if $test == 1 %}One{% elseif $test == 2 %}Two{% else %}None{% endif %}
' + '
~if($test == 1)One~elseif($test == 2)Two~else()None~endif()
' ); $this->assertEquals( @@ -144,7 +144,7 @@ public function testRenderTemplateWithIfWithElses(): void { public function testRenderTemplateWithForeach(): void { $this->createTestTemplate( 'test', - '
{% foreach $test as $item %}

{{ $item[\'name\'] }}

{% endforeach %}
' + '
~foreach($test as $item)

{{ $item[\'name\'] }}

~endforeach()
' ); $this->assertEquals( @@ -160,7 +160,7 @@ public function testRenderTemplateWithForeach(): void { public function testRenderTemplateWithSet(): void { $this->createTestTemplate( 'test', - '
{% if $test %}{% set $text = \'new_value\' %}{% endif %}{{ text }}
' + '
~if($test)~set($text = \'new_value\')~endif(){{ text }}
' ); $this->assertEquals( From 6d5a7260f7ed8548de43e2491f46d9b8b912e538 Mon Sep 17 00:00:00 2001 From: James <78121730+itsnewtjam@users.noreply.github.com> Date: Tue, 30 Sep 2025 20:04:10 -0400 Subject: [PATCH 2/2] Release 0.1.4 (#31) --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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",