1
0
mirror of https://github.com/flextype/flextype.git synced 2025-08-06 05:07:41 +02:00

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

This commit is contained in:
Awilum
2022-05-04 21:54:39 +03:00
parent 71e53a393b
commit 3a41115328
2 changed files with 10 additions and 1 deletions

View File

@@ -20,7 +20,7 @@ use Thunder\Shortcode\Shortcode\ShortcodeInterface;
use function parsers;
use function registry;
// Shortcode: [strings at=1 sort=desc transform=lower,upper]
// Shortcode: [strings] strings to modify [/strings]
parsers()->shortcodes()->addHandler('strings', static function (ShortcodeInterface $s) {
if (! registry()->get('flextype.settings.parsers.shortcodes.shortcodes.strings.enabled')) {
return '';
@@ -80,6 +80,10 @@ parsers()->shortcodes()->addHandler('strings', static function (ShortcodeInterfa
if ($key == 'wordsLimit') {
$content = strings($content)->{'wordsLimit'}(isset($values[0]) ? (int) $values[0] : 100, isset($values[1]) ? (string) $values[1] : '...')->toString();
}
if ($key == 'at') {
$content = strings($content)->{'at'}((int) $values)->toString();
}
}
return (string) $content;

View File

@@ -34,4 +34,9 @@ test('[strings] shortcode', function () {
// wordsLimit
$this->assertEquals("foo...", parsers()->shortcodes()->parse('[strings wordsLimit="1"]foo bar zed[/strings]'));
$this->assertEquals("foo >>>", parsers()->shortcodes()->parse('[strings wordsLimit="1| >>>"]foo bar zed[/strings]'));
// at
$this->assertEquals("a", parsers()->shortcodes()->parse('[strings at=0]abc[/strings]'));
$this->assertEquals("b", parsers()->shortcodes()->parse('[strings at=1]abc[/strings]'));
$this->assertEquals("c", parsers()->shortcodes()->parse('[strings at=2]abc[/strings]'));
});