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:
34
src/flextype/core/Parsers/Shortcodes/TypeShortcode.php
Normal file
34
src/flextype/core/Parsers/Shortcodes/TypeShortcode.php
Normal 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 '';
|
||||
});
|
@@ -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.
|
||||
|
3
tests/fixtures/settings/settings.yaml
vendored
3
tests/fixtures/settings/settings.yaml
vendored
@@ -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
|
||||
#
|
||||
|
@@ -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');
|
||||
});
|
Reference in New Issue
Block a user