1
0
mirror of https://github.com/flextype/flextype.git synced 2025-08-06 21:26:48 +02:00

feat(shortcodes): [strings] shortcode - add firstSegment modifier

This commit is contained in:
Awilum
2022-05-05 09:22:16 +03:00
parent 0c3c36175a
commit f2cb8548ee
2 changed files with 8 additions and 0 deletions

View File

@@ -145,6 +145,10 @@ parsers()->shortcodes()->addHandler('strings', static function (ShortcodeInterfa
if ($key == 'finish') {
$content = strings($content)->{'finish'}(isset($vars[0]) ? (string) $vars[0] : '')->toString();
}
if ($key == 'firstSegment') {
$content = strings($content)->{'firstSegment'}(isset($vars[0]) ? (string) $vars[0] : ' ')->toString();
}
}
return (string) $content;

View File

@@ -94,4 +94,8 @@ test('[strings] shortcode', function () {
// finish
$this->assertEquals("/movies/sg-1/season-5/episode-21/", parsers()->shortcodes()->parse('[strings finish="/"]/movies/sg-1/season-5/episode-21[/strings]'));
// firstSegment
$this->assertEquals("SG-1", parsers()->shortcodes()->parse('[strings firstSegment]SG-1 returns from an off-world mission[/strings]'));
$this->assertEquals("SG", parsers()->shortcodes()->parse('[strings firstSegment="-"]SG-1 returns from an off-world mission[/strings]'));
});