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:
35
src/flextype/core/Entries/Directives/TextileDirective.php
Normal file
35
src/flextype/core/Entries/Directives/TextileDirective.php
Normal 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']);
|
||||
});
|
@@ -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"
|
||||
|
3
tests/fixtures/settings/settings.yaml
vendored
3
tests/fixtures/settings/settings.yaml
vendored
@@ -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"
|
||||
|
@@ -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']);
|
||||
});
|
Reference in New Issue
Block a user