From 307c3b9bab7e67ce133d83decea32f6ac746c5a8 Mon Sep 17 00:00:00 2001 From: David Lapointe Gilbert Date: Fri, 21 Jun 2024 09:24:43 -0400 Subject: [PATCH 1/3] Add @menu, @hasmenu and @endhasmenu --- src/Directives/WordPress.php | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/Directives/WordPress.php b/src/Directives/WordPress.php index 1622f01..66c9ed6 100644 --- a/src/Directives/WordPress.php +++ b/src/Directives/WordPress.php @@ -631,6 +631,25 @@ public function directives(): array return ""; }, + + /* + |--------------------------------------------------------------------- + | @menu / @hasmenu / @endhasmenu + |--------------------------------------------------------------------- + */ + + 'menu' => function ($expression) { + $expression = $this->parse($expression); + return "get(0)}); ?>"; + }, + + 'hasmenu' => function ($expression) { + return ""; + }, + + 'endhasmenu' => function () { + return ''; + }, ]; } } From 6c971526df07a95d1095a9e6db975e5056c41372 Mon Sep 17 00:00:00 2001 From: David Lapointe Gilbert Date: Fri, 21 Jun 2024 09:30:56 -0400 Subject: [PATCH 2/3] Update WordPress.php --- src/Directives/WordPress.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/Directives/WordPress.php b/src/Directives/WordPress.php index 66c9ed6..de08c58 100644 --- a/src/Directives/WordPress.php +++ b/src/Directives/WordPress.php @@ -639,8 +639,7 @@ public function directives(): array */ 'menu' => function ($expression) { - $expression = $this->parse($expression); - return "get(0)}); ?>"; + return ""; }, 'hasmenu' => function ($expression) { From 799af80479b0fc66c7f10155dd0f8fd80f61a640 Mon Sep 17 00:00:00 2001 From: David Lapointe Gilbert Date: Fri, 21 Jun 2024 09:57:41 -0400 Subject: [PATCH 3/3] Update tests for @menu, @hasmenu, @endhasmenu --- tests/Unit/WordPressTest.php | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/tests/Unit/WordPressTest.php b/tests/Unit/WordPressTest.php index 0b347d0..30a230f 100644 --- a/tests/Unit/WordPressTest.php +++ b/tests/Unit/WordPressTest.php @@ -845,3 +845,33 @@ expect($compiled)->toBe(""); }); }); + +describe('@menu', function () { + it('compiles correctly', function () { + $directive = "@menu(['theme_location' => 'primary_navigation'])"; + + $compiled = $this->compile($directive); + + expect($compiled)->toBe(" 'primary_navigation']); ?>"); + }); +}); + +describe('@hasmenu', function () { + it('compiles correctly', function () { + $directive = "@hasmenu('primary_navigation')"; + + $compiled = $this->compile($directive); + + expect($compiled)->toBe(""); + }); +}); + +describe('@endhasmenu', function () { + it('compiles correctly', function () { + $directive = '@endhasmenu'; + + $compiled = $this->compile($directive); + + expect($compiled)->toBe(''); + }); +});