From 1447a92d83d7816b541a1d7e56f41683fa5cd2f6 Mon Sep 17 00:00:00 2001 From: Awilum Date: Wed, 4 May 2022 22:11:28 +0300 Subject: [PATCH] feat(shortcodes): `[strings]` shortcode - add `capitalize` 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 af7bc73c..45d1f43c 100644 --- a/src/flextype/core/Parsers/Shortcodes/StringsShortcode.php +++ b/src/flextype/core/Parsers/Shortcodes/StringsShortcode.php @@ -100,6 +100,10 @@ parsers()->shortcodes()->addHandler('strings', static function (ShortcodeInterfa if ($key == 'camel') { $content = strings($content)->{'camel'}()->toString(); } + + if ($key == 'capitalize') { + $content = strings($content)->{'capitalize'}()->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 d287d280..a8dc516f 100644 --- a/tests/src/flextype/core/Parsers/Shortcodes/StringsShortcodeTest.php +++ b/tests/src/flextype/core/Parsers/Shortcodes/StringsShortcodeTest.php @@ -52,4 +52,7 @@ test('[strings] shortcode', function () { // camel $this->assertEquals("fooBar", parsers()->shortcodes()->parse('[strings camel]foo_bar[/strings]')); + // capitalize + $this->assertEquals("That Country Was At The Same Stage Of Development As The United States In The 1940S", parsers()->shortcodes()->parse('[strings capitalize]that country was at the same stage of development as the United States in the 1940s[/strings]')); + }); \ No newline at end of file