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

feat(directives): add @textile directive

This commit is contained in:
Awilum
2022-05-13 16:52:30 +03:00
parent f7e717f3b8
commit b70e32d6ed
4 changed files with 58 additions and 0 deletions

View File

@@ -0,0 +1,35 @@
<?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.
*/
use Glowy\Arrays\Arrays as Collection;
emitter()->addListener('onEntriesFetchSingleField', static function (): void {
if (! registry()->get('flextype.settings.entries.directives.textile.enabled')) {
return;
}
$field = entries()->registry()->get('methods.fetch.field');
if (is_string($field['value'])) {
if (strings($field['value'])->contains('@textile')) {
$field['value'] = strings(parsers()->textile()->parse($field['value']))->replace('@textile', '')->trim()->toString();
}
}
entries()->registry()->set('methods.fetch.field.key', $field['key']);
entries()->registry()->set('methods.fetch.field.value', $field['value']);
});

View File

@@ -83,6 +83,9 @@ entries:
markdown:
enabled: true
path: "/src/flextype/core/Entries/Directives/MarkdownDirective.php"
textile:
enabled: true
path: "/src/flextype/core/Entries/Directives/TextileDirective.php"
shortcodes:
enabled: true
path: "/src/flextype/core/Entries/Directives/ShortcodesDirective.php"

View File

@@ -79,6 +79,9 @@ entries:
markdown:
enabled: true
path: "/src/flextype/core/Entries/Directives/MarkdownDirective.php"
textile:
enabled: true
path: "/src/flextype/core/Entries/Directives/TextileDirective.php"
shortcodes:
enabled: true
path: "/src/flextype/core/Entries/Directives/ShortcodesDirective.php"

View File

@@ -0,0 +1,17 @@
<?php
use Flextype\Component\Filesystem\Filesystem;
beforeEach(function() {
filesystem()->directory(PATH['project'] . '/entries')->create();
});
afterEach(function (): void {
filesystem()->directory(PATH['project'] . '/entries')->delete();
});
test('textile directive', function () {
entries()->create('textile', ['foo' => '@textile **Hello world!**']);
$this->assertEquals('<p> <b>Hello world!</b></p>', entries()->fetch('textile')['foo']);
});