1
0
mirror of https://github.com/flextype/flextype.git synced 2025-08-06 13:16:45 +02:00

feat(shortcodes): add type shortcode

This commit is contained in:
Awilum
2022-05-27 17:14:42 +03:00
parent 9274fb42b1
commit 97e6bda8e0
4 changed files with 59 additions and 1 deletions

View File

@@ -0,0 +1,34 @@
<?php
declare(strict_types=1);
/**
* Flextype - Hybrid Content Management System with the freedom of a headless CMS
* and with the full functionality of a traditional CMS!
*
* Copyright (c) Sergey Romanenko (https://awilum.github.io)
*
* Licensed under The MIT License.
*
* For full copyright and license information, please see the LICENSE
* Redistributions of files must retain the above copyright notice.
*/
namespace Flextype\Parsers\Shortcodes;
use Thunder\Shortcode\Shortcode\ShortcodeInterface;
use function registry;
// Shortcode: type
// Usage: (type:string)
parsers()->shortcodes()->addHandler('type', static function (ShortcodeInterface $s) {
if (! registry()->get('flextype.settings.parsers.shortcodes.shortcodes.type.enabled')) {
return '';
}
if ($s->getBbCode() != null) {
return '@type[' . $s->getBBCode() . ']';
}
return '';
});

View File

@@ -627,7 +627,9 @@ parsers:
eval:
enabled: true
path: "/src/flextype/core/Parsers/Shortcodes/EvalShortcode.php"
type:
enabled: true
path: "/src/flextype/core/Parsers/Shortcodes/TypeShortcode.php"
# CORS
#
# CORS (Cross-origin resource sharing) allows JavaScript web apps to make HTTP requests to other domains.

View File

@@ -611,6 +611,9 @@ parsers:
eval:
enabled: true
path: "/src/flextype/core/Parsers/Shortcodes/EvalShortcode.php"
type:
enabled: true
path: "/src/flextype/core/Parsers/Shortcodes/TypeShortcode.php"
# CORS
#

View File

@@ -0,0 +1,19 @@
<?php
declare(strict_types=1);
beforeEach(function() {
filesystem()->directory(PATH['project'] . '/entries')->ensureExists(0755, true);
});
afterEach(function () {
filesystem()->directory(PATH['project'] . '/entries')->delete();
});
test('type shortcode', function () {
expect(entries()->create('test-1', ['price' => '(type:int) 10']))->toBeTrue();
expect(entries()->fetch('test-1')['price'])->toBe(10);
expect(entries()->create('test-2', ['price' => '(type:string) 10']))->toBeTrue();
expect(entries()->fetch('test-2')['price'])->toBe('10');
});