From 0c3c36175a484eac5a4f9e12163d47255c3c1a67 Mon Sep 17 00:00:00 2001 From: Awilum Date: Thu, 5 May 2022 09:19:01 +0300 Subject: [PATCH] feat(shortcodes): `[strings]` shortcode - add `finish` modifier --- src/flextype/core/Parsers/Shortcodes/StringsShortcode.php | 4 ++++ .../flextype/core/Parsers/Shortcodes/StringsShortcodeTest.php | 3 +++ 2 files changed, 7 insertions(+) diff --git a/src/flextype/core/Parsers/Shortcodes/StringsShortcode.php b/src/flextype/core/Parsers/Shortcodes/StringsShortcode.php index 032f2c5f..8a36e683 100644 --- a/src/flextype/core/Parsers/Shortcodes/StringsShortcode.php +++ b/src/flextype/core/Parsers/Shortcodes/StringsShortcode.php @@ -141,6 +141,10 @@ parsers()->shortcodes()->addHandler('strings', static function (ShortcodeInterfa if ($key == 'endsWith') { $content = strings($content)->{'endsWith'}(isset($vars[0]) ? (string) $vars[0] : '') ? "true" : "false"; } + + if ($key == 'finish') { + $content = strings($content)->{'finish'}(isset($vars[0]) ? (string) $vars[0] : '')->toString(); + } } return (string) $content; diff --git a/tests/src/flextype/core/Parsers/Shortcodes/StringsShortcodeTest.php b/tests/src/flextype/core/Parsers/Shortcodes/StringsShortcodeTest.php index 662ebc8a..5007bbd3 100644 --- a/tests/src/flextype/core/Parsers/Shortcodes/StringsShortcodeTest.php +++ b/tests/src/flextype/core/Parsers/Shortcodes/StringsShortcodeTest.php @@ -91,4 +91,7 @@ test('[strings] shortcode', function () { // endsWith $this->assertEquals("true", parsers()->shortcodes()->parse('[strings endsWith="/"]/movies/sg-1/season-5/episode-21/[/strings]')); $this->assertEquals("false", parsers()->shortcodes()->parse('[strings endsWith="/"]/movies/sg-1/season-5/episode-21[/strings]')); + + // finish + $this->assertEquals("/movies/sg-1/season-5/episode-21/", parsers()->shortcodes()->parse('[strings finish="/"]/movies/sg-1/season-5/episode-21[/strings]')); }); \ No newline at end of file