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