Skip to content

Commit

Permalink
5.2.0
Browse files Browse the repository at this point in the history
- Added new if statements
- Update if statements functionality
  • Loading branch information
beebmx committed Jul 4, 2024
1 parent 4ec8b22 commit 2c604cf
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 32 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"keywords": [
"kirby", "kirby-3", "kirby-4", "blade", "view", "template"
],
"version": "5.1.0",
"version": "5.2.0",
"type": "kirby-plugin",
"license": "MIT",
"authors": [
Expand Down
22 changes: 14 additions & 8 deletions src/Template.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,21 +88,19 @@ public function render(array $data = []): string
$application->terminate();
});
}

return Tpl::load($this->file(), $data);
} else {
return Tpl::load($this->file(), $data);
}

return Tpl::load($this->file(), $data);
}

public function setViewDirectory()
public function setViewDirectory(): void
{
if (! file_exists($this->views)) {
Dir::make($this->views);
}
}

protected function setDirectives()
protected function setDirectives(): void
{
$this->blade->compiler()->directive('js', function (string $path) {
return "<?php echo Kirby\Cms\Html::js($path) ?>";
Expand Down Expand Up @@ -237,9 +235,17 @@ protected function setDirectives()
}
}

protected function setIfStatements()
protected function setIfStatements(): void
{
foreach ($statements = Kirby::instance()->option('beebmx.kirby-blade.ifs', []) as $statement => $callback) {
$this->blade->compiler()->if('auth', function () {
return Kirby::instance()->user() !== null;
});

$this->blade->compiler()->if('guest', function () {
return Kirby::instance()->user() === null;
});

foreach (Kirby::instance()->option('beebmx.kirby-blade.ifs', []) as $statement => $callback) {
$this->blade->compiler()->if($statement, $callback);
}
}
Expand Down
23 changes: 0 additions & 23 deletions src/View/Compiler/BladeCompiler.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,29 +13,6 @@ class BladeCompiler extends Compiler
*/
protected $echoFormat = '_e(%s)';

/**
* Register an "if" statement directive.
*
* @param string $name
*/
public function if($name, callable $callback): void
{
$this->conditions[$name] = $callback;
$this->directive($name, function ($expression) use ($name) {
return $expression !== ''
? "<?php if (option('beebmx.kirby-blade.ifs')['{$name}']($expression)): ?>"
: "<?php if (option('beebmx.kirby-blade.ifs')['{$name}'](null)): ?>";
});
$this->directive('else'.$name, function ($expression) use ($name) {
return $expression !== ''
? "<?php elseif (option('beebmx.kirby-blade.ifs')['{$name}']($expression)): ?>"
: "<?php elseif (option('beebmx.kirby-blade.ifs')['{$name}'](null)): ?>";
});
$this->directive('end'.$name, function () {
return '<?php endif; ?>';
});
}

/**
* Set the "echo" format to double encode entities.
*/
Expand Down

0 comments on commit 2c604cf

Please sign in to comment.