Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
6 changes: 3 additions & 3 deletions src/Quark/QuarkCompiler.php
Original file line number Diff line number Diff line change
Expand Up @@ -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}");
};
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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],
Expand Down
6 changes: 3 additions & 3 deletions tests/Unit/Quark/QuarkCompilerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public function testAddDirective(): void {
$this->assertArrayHasKey('test', $directives);
$this->assertEquals(
"<?php\necho '<div>';\necho 'test_directive_ran';\necho '</div>';\n",
$this->compiler->compile('<div>{% test %}</div>')
$this->compiler->compile('<div>~test()</div>')
);
}

Expand All @@ -68,7 +68,7 @@ public function testTokenizeSource(): void {
['type' => 'text', 'content' => '</div>'],
['type' => 'directive', 'name' => 'outlet', 'args' => ''],
],
$method->invoke($this->compiler, '<div>{{ test }}</div>{% outlet %}')
$method->invoke($this->compiler, '<div>{{ test }}</div>~outlet()')
);
}

Expand All @@ -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)')
);
}

Expand Down
26 changes: 13 additions & 13 deletions tests/Unit/Quark/QuarkEngineTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ public function testRenderTemplate(): void {
}

public function testRenderTemplateWithLayout(): void {
$this->createTestTemplate('layout', '<div>{% outlet %}</div>');
$this->createTestTemplate('test', '{% layout layout %}<p>{{ test }}</p>');
$this->createTestTemplate('layout', '<div>~outlet()</div>');
$this->createTestTemplate('test', '~layout(layout)<p>{{ test }}</p>');

$this->assertEquals(
'<div><p>Test Value</p></div>',
Expand All @@ -55,7 +55,7 @@ public function testRenderTemplateWithLayout(): void {
}

public function testRenderTemplateWithRootLayout(): void {
$this->createTestTemplate('root', '<div>{% outlet %}</div>');
$this->createTestTemplate('root', '<div>~outlet()</div>');
$this->createTestTemplate('test', '<p>{{ test }}</p>');
$this->engine->setRootLayout('root');

Expand All @@ -66,7 +66,7 @@ public function testRenderTemplateWithRootLayout(): void {
}

public function testRenderTemplateWithSkipRootLayout(): void {
$this->createTestTemplate('root', '<div>{% outlet %}</div>');
$this->createTestTemplate('root', '<div>~outlet()</div>');
$this->createTestTemplate('test', '<p>{{ test }}</p>');
$this->engine->setRootLayout('root');
$this->engine->skipRootLayout();
Expand All @@ -78,8 +78,8 @@ public function testRenderTemplateWithSkipRootLayout(): void {
}

public function testRenderTemplateWithSkipRootDirective(): void {
$this->createTestTemplate('root', '<div>{% outlet %}</div>');
$this->createTestTemplate('test', '{% skip_root %}<p>{{ test }}</p>');
$this->createTestTemplate('root', '<div>~outlet()</div>');
$this->createTestTemplate('test', '~skip_root()<p>{{ test }}</p>');
$this->engine->setRootLayout('root');

$this->assertEquals(
Expand All @@ -89,8 +89,8 @@ public function testRenderTemplateWithSkipRootDirective(): void {
}

public function testRenderTemplateWithCustomOutlet(): void {
$this->createTestTemplate('layout', '<div>{% outlet custom %}</div>');
$this->createTestTemplate('test', '{% layout layout %}{% slot custom %}<p>{{ test }}</p>{% endslot %}');
$this->createTestTemplate('layout', '<div>~outlet(custom)</div>');
$this->createTestTemplate('test', '~layout(layout)~slot(custom)<p>{{ test }}</p>~endslot()');

$this->assertEquals(
'<div><p>Test Value</p></div>',
Expand All @@ -99,7 +99,7 @@ public function testRenderTemplateWithCustomOutlet(): void {
}

public function testRenderTemplateWithInclude(): void {
$this->createTestTemplate('test', '<div>{% include included %}</div>');
$this->createTestTemplate('test', '<div>~include(included)</div>');
$this->createTestTemplate('included', '<p>Included</p>');

$this->assertEquals(
Expand All @@ -109,7 +109,7 @@ public function testRenderTemplateWithInclude(): void {
}

public function testRenderTemplateWithIf(): void {
$this->createTestTemplate('test', '<div>{% if $test %}True{% endif %}</div>');
$this->createTestTemplate('test', '<div>~if($test)True~endif()</div>');

$this->assertEquals(
'<div></div>',
Expand All @@ -124,7 +124,7 @@ public function testRenderTemplateWithIf(): void {
public function testRenderTemplateWithIfWithElses(): void {
$this->createTestTemplate(
'test',
'<div>{% if $test == 1 %}One{% elseif $test == 2 %}Two{% else %}None{% endif %}</div>'
'<div>~if($test == 1)One~elseif($test == 2)Two~else()None~endif()</div>'
);

$this->assertEquals(
Expand All @@ -144,7 +144,7 @@ public function testRenderTemplateWithIfWithElses(): void {
public function testRenderTemplateWithForeach(): void {
$this->createTestTemplate(
'test',
'<div>{% foreach $test as $item %}<p>{{ $item[\'name\'] }}</p>{% endforeach %}</div>'
'<div>~foreach($test as $item)<p>{{ $item[\'name\'] }}</p>~endforeach()</div>'
);

$this->assertEquals(
Expand All @@ -160,7 +160,7 @@ public function testRenderTemplateWithForeach(): void {
public function testRenderTemplateWithSet(): void {
$this->createTestTemplate(
'test',
'<div>{% if $test %}{% set $text = \'new_value\' %}{% endif %}{{ text }}</div>'
'<div>~if($test)~set($text = \'new_value\')~endif(){{ text }}</div>'
);

$this->assertEquals(
Expand Down