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

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

This commit is contained in:
Awilum
2022-05-05 07:18:17 +03:00
parent f5c3f3867e
commit 3828a81789
2 changed files with 8 additions and 0 deletions

View File

@@ -112,6 +112,10 @@ parsers()->shortcodes()->addHandler('strings', static function (ShortcodeInterfa
if ($key == 'charsFrequency') {
$content = serializers()->json()->encode(strings($content)->{'charsFrequency'}());
}
if ($key == 'contains') {
$content = strings($content)->{'contains'}(isset($values[0]) ? (string) $values[0] : '', isset($values[1]) ? (bool) $values[1] : true) ? "true" : "false";
}
}
return (string) $content;

View File

@@ -61,4 +61,8 @@ test('[strings] shortcode', function () {
// charsFrequency
$this->assertEquals('{"_":"16.67","a":"11.11","p":"11.11","c":"5.56","r":"5.56","f":"5.56","ò":"5.56","ô":"5.56","b":"5.56","à":"5.56","ř":"5.56","s":"5.56","l":"5.56","e":"5.56"}', parsers()->shortcodes()->parse('[strings charsFrequency]car_fòô_bàřs_apple[/strings]'));
// contains
$this->assertEquals("true", parsers()->shortcodes()->parse('[strings contains=SG-1]SG-1 returns from an off-world mission to P9Y-3C3[/strings]'));
$this->assertEquals("false", parsers()->shortcodes()->parse('[strings contains=sg-1|false]SG-1 returns from an off-world mission to P9Y-3C3[/strings]'));
});