From 2c604cf8a1c50e7d3ec255dfcf9336a867646065 Mon Sep 17 00:00:00 2001 From: Fernando Gutierrez Date: Thu, 4 Jul 2024 13:19:05 -0600 Subject: [PATCH] 5.2.0 - Added new if statements - Update if statements functionality --- composer.json | 2 +- src/Template.php | 22 ++++++++++++++-------- src/View/Compiler/BladeCompiler.php | 23 ----------------------- 3 files changed, 15 insertions(+), 32 deletions(-) diff --git a/composer.json b/composer.json index 626819d..cf6a4cd 100644 --- a/composer.json +++ b/composer.json @@ -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": [ diff --git a/src/Template.php b/src/Template.php index 551c770..715ba7b 100644 --- a/src/Template.php +++ b/src/Template.php @@ -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 ""; @@ -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); } } diff --git a/src/View/Compiler/BladeCompiler.php b/src/View/Compiler/BladeCompiler.php index c8130e1..b71f009 100644 --- a/src/View/Compiler/BladeCompiler.php +++ b/src/View/Compiler/BladeCompiler.php @@ -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 !== '' - ? "" - : ""; - }); - $this->directive('else'.$name, function ($expression) use ($name) { - return $expression !== '' - ? "" - : ""; - }); - $this->directive('end'.$name, function () { - return ''; - }); - } - /** * Set the "echo" format to double encode entities. */