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

feat(shortcodes): add const shortcode

This commit is contained in:
Awilum
2022-05-29 11:30:01 +03:00
parent 9ec6a73a7c
commit cd55223e0c
4 changed files with 63 additions and 0 deletions

View File

@@ -0,0 +1,40 @@
<?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: const
// Usage: (const:PROJECT_DIR)
parsers()->shortcodes()->addHandler('const', static function (ShortcodeInterface $s) {
if (! registry()->get('flextype.settings.parsers.shortcodes.shortcodes.const.enabled')) {
return '';
}
if ($s->getBBCode() !== null) {
$const = parsers()->shortcodes()->parse($s->getBBCode());
if (defined($const)) {
return constant($const);
} else {
return '';
}
}
return '';
});

View File

@@ -661,6 +661,9 @@ parsers:
uuid:
enabled: true
path: "/src/flextype/core/Parsers/Shortcodes/UuidShortcode.php"
const:
enabled: true
path: "/src/flextype/core/Parsers/Shortcodes/ConstShortcode.php"
var:
enabled: true
path: "/src/flextype/core/Parsers/Shortcodes/VarShortcode.php"

View File

@@ -645,6 +645,9 @@ parsers:
uuid:
enabled: true
path: "/src/flextype/core/Parsers/Shortcodes/UuidShortcode.php"
const:
enabled: true
path: "/src/flextype/core/Parsers/Shortcodes/ConstShortcode.php"
var:
enabled: true
path: "/src/flextype/core/Parsers/Shortcodes/VarShortcode.php"

View File

@@ -0,0 +1,17 @@
<?php
declare(strict_types=1);
beforeEach(function() {
filesystem()->directory(PATH['project'] . '/entries')->ensureExists(0755, true);
});
afterEach(function () {
filesystem()->directory(PATH['project'] . '/entries')->delete();
});
test('const shortcode', function () {
define('foo', 'Foo');
expect(entries()->create('const', ['test' => '(const:foo)']))->toBeTrue();
expect(entries()->fetch('const')['test'])->toBe('Foo');
});