diff --git a/src/flextype/core/Parsers/Shortcodes/TypeShortcode.php b/src/flextype/core/Parsers/Shortcodes/TypeShortcode.php new file mode 100644 index 00000000..3d1d3072 --- /dev/null +++ b/src/flextype/core/Parsers/Shortcodes/TypeShortcode.php @@ -0,0 +1,34 @@ +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 ''; +}); diff --git a/src/flextype/settings.yaml b/src/flextype/settings.yaml index 567cdbd0..a4021436 100644 --- a/src/flextype/settings.yaml +++ b/src/flextype/settings.yaml @@ -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. diff --git a/tests/fixtures/settings/settings.yaml b/tests/fixtures/settings/settings.yaml index 283125e5..46b30e9c 100644 --- a/tests/fixtures/settings/settings.yaml +++ b/tests/fixtures/settings/settings.yaml @@ -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 # diff --git a/tests/src/flextype/core/Parsers/Shortcodes/TypeShortcodeTest.php b/tests/src/flextype/core/Parsers/Shortcodes/TypeShortcodeTest.php new file mode 100644 index 00000000..3f0f9778 --- /dev/null +++ b/tests/src/flextype/core/Parsers/Shortcodes/TypeShortcodeTest.php @@ -0,0 +1,19 @@ +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'); +}); \ No newline at end of file