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:
@@ -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;
|
||||
|
@@ -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]'));
|
||||
});
|
Reference in New Issue
Block a user