diff --git a/composer.json b/composer.json index 0ad2e17..ccec6cd 100644 --- a/composer.json +++ b/composer.json @@ -1,6 +1,6 @@ { "name": "newtron/core", - "version": "0.1.0", + "version": "0.1.1", "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 249d6fe..2db9520 100644 --- a/src/Quark/QuarkCompiler.php +++ b/src/Quark/QuarkCompiler.php @@ -76,6 +76,11 @@ private function registerBuiltinDirectives(): void { return "\$__quark->endSlot();\n"; }; + $this->directives['include'] = function ($args) { + $template = trim($args, '"\''); + return "echo \$__quark->render('{$template}');\n"; + }; + $this->directives['if'] = fn($args) => "if ({$args}) {\n"; $this->directives['elseif'] = fn($args) => "} elseif ({$args}) {\n"; $this->directives['else'] = fn($args) => "} else {\n"; diff --git a/tests/Unit/Document/DocumentTest.php b/tests/Unit/Document/DocumentTest.php index 6414fc1..cb4454b 100644 --- a/tests/Unit/Document/DocumentTest.php +++ b/tests/Unit/Document/DocumentTest.php @@ -87,7 +87,7 @@ public function testGetSingleMeta(): void { ); } - public function testSetOG(): void { + public function testSetOg(): void { App::create($this->testRootPath); $document = App::getDocument(); @@ -96,7 +96,7 @@ public function testSetOG(): void { $this->assertEquals(['og:test' => 'test_og'], $document->getOG()); } - public function testGetAllOG(): void { + public function testGetAllOg(): void { App::create($this->testRootPath); $document = App::getDocument(); @@ -109,7 +109,7 @@ public function testGetAllOG(): void { ); } - public function testGetSingleOG(): void { + public function testGetSingleOg(): void { App::create($this->testRootPath); $document = App::getDocument(); diff --git a/tests/Unit/Http/RequestTest.php b/tests/Unit/Http/RequestTest.php index 2fe0b96..8896884 100644 --- a/tests/Unit/Http/RequestTest.php +++ b/tests/Unit/Http/RequestTest.php @@ -49,7 +49,7 @@ public function testGetCookies(): void { $this->assertEquals('test_value', $request->getCookie('test-cookie')); } - public function testGetURI(): void { + public function testGetUri(): void { $_SERVER['REQUEST_URI'] = '/test?param=value'; $request = new Request(); @@ -63,7 +63,7 @@ public function testGetPath(): void { $this->assertEquals('/test', $request->getPath()); } - public function testGetURL(): void { + public function testGetUrl(): void { $_SERVER['HTTPS'] = 'on'; $_SERVER['HTTP_HOST'] = 'test.com'; $_SERVER['REQUEST_URI'] = '/test?param=value'; @@ -118,13 +118,13 @@ public function testIsAjax(): void { $this->assertTrue($request->isAjax()); } - public function testGetZeroIPWhenNotSet(): void { + public function testGetZeroIpWhenNotSet(): void { $request = new Request(); $this->assertEquals('0.0.0.0', $request->getIP()); } - public function testGetIP(): void { + public function testGetIp(): void { $_SERVER['REMOTE_ADDR'] = '127.0.0.1'; $request = new Request(); diff --git a/tests/Unit/Quark/QuarkCompilerTest.php b/tests/Unit/Quark/QuarkCompilerTest.php index aff9bff..918d3e4 100644 --- a/tests/Unit/Quark/QuarkCompilerTest.php +++ b/tests/Unit/Quark/QuarkCompilerTest.php @@ -19,6 +19,7 @@ public function testBuiltinDirectivesRegistered(): void { 'outlet', 'slot', 'endslot', + 'include', 'if', 'elseif', 'else', diff --git a/tests/Unit/Quark/QuarkEngineTest.php b/tests/Unit/Quark/QuarkEngineTest.php index 15d95c1..8859b28 100644 --- a/tests/Unit/Quark/QuarkEngineTest.php +++ b/tests/Unit/Quark/QuarkEngineTest.php @@ -97,6 +97,16 @@ public function testRenderTemplateWithCustomOutlet(): void { ); } + public function testRenderTemplateWithInclude(): void { + $this->createTestTemplate('test', '
Included
'); + + $this->assertEquals( + 'Included