diff --git a/CHANGELOG.md b/CHANGELOG.md index 77de5e6..a9c0be5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,10 @@ + +# [1.6.0](https://github.com/flextype-plugins/twig/compare/v1.5.1...v1.6.0) (2020-12-20) + +### Features + +* **core** update code base for new Flextype 0.9.13 + # [1.5.1](https://github.com/flextype-plugins/twig/compare/v1.5.0...v1.5.1) (2020-12-10) diff --git a/README.md b/README.md index 174337c..09259ae 100755 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@

Twig Plugin for Flextype

-Version License Total downloads Flextype Discord +Version License Total downloads Flextype Discord

Twig plugin to present Twig template engine for Flextype. @@ -12,7 +12,7 @@ The following dependencies need to be installed for Twig Plugin. | Item | Version | Download | |---|---|---| -| [flextype](https://github.com/flextype/flextype) | 0.9.12 | [download](https://github.com/flextype/flextype/releases) | +| [flextype](https://github.com/flextype/flextype) | 0.9.13 | [download](https://github.com/flextype/flextype/releases) | ## Installation @@ -178,7 +178,7 @@ Check whether a file exists Usage: ```twig -{% if (filesystem_has(PATH_PROJECT ~ '/uploads/' ~ entry.id ~ '/about.md')) %} +{% if (filesystem_has(PATH_PROJECT ~ '/media/' ~ entry.id ~ '/about.md')) %} Show something... {% endif %} ``` @@ -189,7 +189,7 @@ Read a file Usage: ```twig -{{ filesystem_read(PATH_PROJECT ~ '/uploads/' ~ entry.id ~ '/about.md') }} +{{ filesystem_read(PATH_PROJECT ~ '/media/' ~ entry.id ~ '/about.md') }} ``` Result: @@ -204,7 +204,7 @@ Get file extension Usage: ```twig -{{ filesystem_ext(PATH_PROJECT ~ '/uploads/' ~ entry.id ~ '/about.md') }} +{{ filesystem_ext(PATH_PROJECT ~ '/media/' ~ entry.id ~ '/about.md') }} ``` Result: @@ -218,7 +218,7 @@ Get filename Usage: ```twig -{{ filesystem_basename(PATH_PROJECT ~ '/uploads/' ~ entry.id ~ '/about.md') }} +{{ filesystem_basename(PATH_PROJECT ~ '/media/' ~ entry.id ~ '/about.md') }} ``` Result: @@ -306,7 +306,7 @@ Fetch single entry Usage: ```twig -{% set about_entry = entries.fetchSingle('about') %} +{% set about_entry = entries.fetch('about') %} ``` Fetch collection of entries @@ -314,9 +314,7 @@ Fetch collection of entries Usage: ```twig -{% set posts = entries.fetchSingle('blog', {}) %} -or -{% set posts = entries.fetchCollection('blog') %} +{% set posts = entries.fetch('blog', {'collection': true}) %} ``` ##### emitter diff --git a/plugin.yaml b/plugin.yaml index a3d7c54..22a17b1 100755 --- a/plugin.yaml +++ b/plugin.yaml @@ -1,5 +1,5 @@ name: Twig -version: 1.5.1 +version: 1.6.0 description: Twig plugin to present Twig template engine for Flextype. icon: fas fa-palette author: @@ -11,4 +11,4 @@ bugs: https://github.com/flextype-plugins/twig/issues license: MIT dependencies: - flextype: 0.9.12 + flextype: 0.9.13 diff --git a/settings.yaml b/settings.yaml index d17f57f..8f2dace 100644 --- a/settings.yaml +++ b/settings.yaml @@ -20,7 +20,7 @@ auto_reload: true cache: true debug: false charset: "UTF-8" -extensions: ['Cache', 'Entries', 'Emitter', 'I18n', 'Json', 'Yaml', 'Markdown', 'Filesystem', 'Csrf', 'GlobalVars', 'Url', 'Registry', 'Shortcode', 'Arrays', 'Flash', 'Media'] +extensions: ['Cache', 'Entries', 'Emitter', 'I18n', 'Json', 'Yaml', 'Markdown', 'Filesystem', 'Csrf', 'GlobalVars', 'Url', 'Registry', 'Shortcode', 'Arrays', 'Flash', 'Media', 'Strings'] # Twig plugin priority priority: 100 diff --git a/twig/ArraysTwigExtension.php b/twig/ArraysTwigExtension.php index 7531207..8032b18 100644 --- a/twig/ArraysTwigExtension.php +++ b/twig/ArraysTwigExtension.php @@ -9,6 +9,7 @@ namespace Flextype\Plugin\Twig\Twig; +use Atomastic\Arrays\Arrays; use Twig\Extension\AbstractExtension; class ArraysTwigExtension extends AbstractExtension @@ -33,8 +34,17 @@ public function getFunctions() : array ]; } - public function arrays($items) + /** + * Create a new arrayable object from the given elements. + * + * Initializes a Arrays object and assigns $items the supplied values. + * + * @param mixed $items Items + * + * @return Atomastic\Arrays\Arrays + */ + function arrays($items = []): Arrays { - return arrays($items); + return Arrays::create($items); } } diff --git a/twig/EntriesTwigExtension.php b/twig/EntriesTwigExtension.php index 8c486e2..bd56eb1 100644 --- a/twig/EntriesTwigExtension.php +++ b/twig/EntriesTwigExtension.php @@ -40,18 +40,10 @@ public function __construct() } /** - * Fetch single entry + * Fetch. */ - public function fetchSingle(string $id, array $options = []) + public function fetch(string $id, array $options = []) { - return flextype('entries')->fetchSingle($id, $options); - } - - /** - * Fetch entries collection - */ - public function fetchCollection(string $id, array $options = []) - { - return flextype('entries')->fetchCollection($id, $options); + return flextype('entries')->fetch($id, $options); } } diff --git a/twig/JsonTwigExtension.php b/twig/JsonTwigExtension.php index c836f84..f56e4e9 100644 --- a/twig/JsonTwigExtension.php +++ b/twig/JsonTwigExtension.php @@ -52,7 +52,7 @@ public function getFilters() : array */ public function encode($input) : string { - return flextype('json')->encode($input); + return flextype('serializers')->json()->encode($input); } /** @@ -60,6 +60,6 @@ public function encode($input) : string */ public function decode(string $input, bool $cache = true) { - return flextype('json')->decode($input, $cache); + return flextype('serializers')->json()->decode($input, $cache); } } diff --git a/twig/MarkdownTwigExtension.php b/twig/MarkdownTwigExtension.php index 6d2a7b5..5b85d0a 100644 --- a/twig/MarkdownTwigExtension.php +++ b/twig/MarkdownTwigExtension.php @@ -39,7 +39,7 @@ public function getFilters() : array public function markdown($input, bool $cache = true) : string { if (!empty($input)) { - return flextype('markdown')->parse($input, $cache); + return flextype('parsers')->markdown()->parse($input, $cache); } return ''; diff --git a/twig/MediaTwigExtension.php b/twig/MediaTwigExtension.php index d4f5c9d..4c5a601 100644 --- a/twig/MediaTwigExtension.php +++ b/twig/MediaTwigExtension.php @@ -21,72 +21,90 @@ class MediaTwigExtension extends AbstractExtension implements GlobalsInterface public function getGlobals(): array { return [ - 'media_files' => new MediaFilesTwig(), - 'media_files_meta' => new MediaFilesMetaTwig(), - 'media_folders' => new MediaFoldersTwig(), - 'media_folders_meta' => new MediaFoldersMetaTwig(), + 'media' => new MediaTwig(), ]; } } -class MediaFilesTwig +class MediaTwig { - public function fetchSingle(string $path, array $options = []): Arrays + /** + * Create a Media Files instance. + */ + public function files(): MediaFiles + { + return new MediaTwigFiles(); + } + + /** + * Create a Media Files instance. + */ + public function folders(): MediaFolders { - return flextype('media_files')->fetchSingle($path, $options); + return new MediaTwigFolders(); } +} - public function fetchCollection(string $path, array $options = []): Arrays +class MediaTwigFiles +{ + public function meta(): MediaTwigFilesMeta { - return flextype('media_files')->fetchCollection($path, $options); + return new MediaTwigFilesMeta(); + } + + public function fetch(string $path, array $options = []): Arrays + { + return flextype('media')->files()->fetch($path, $options); } public function has(string $path): bool { - return flextype('media_files')->has($path); + return flextype('media')->files()->has($path); } public function getFileLocation(string $path): bool { - return flextype('media_files')->getFileLocation($path); + return flextype('media')->files()->getFileLocation($path); } } -class MediaFilesMetaTwig + +class MediaTwigFilesMeta { public function getFileMetaLocation(string $path): bool { - return flextype('media_files_meta')->getFileMetaLocation($path); + return flextype('media')->files()->meta()->getFileMetaLocation($path); } } -class MediaFoldersTwig +class MediaTwigFolders { - public function fetchSingle(string $path, array $options = []): Arrays + public function meta(): MediaTwigFoldersMeta { - return flextype('media_folders')->fetchSingle($path, $options); + return new MediaTwigFoldersMeta(); } - public function fetchCollection(string $path, array $options = []): Arrays + public function fetch(string $path, array $options = []): Arrays { - return flextype('media_folders')->fetchCollection($path, $options); + return flextype('media')->folders()->fetch($path, $options); } public function has(string $path): bool { - return flextype('media_folders')->has($path); + return flextype('media')->folders()->has($path); } public function getDirectoryLocation(string $path): bool { - return flextype('media_folders')->getDirectoryLocation($path); + return flextype('media')->folders()->getDirectoryLocation($path); } } -class MediaFoldersMetaTwig + +class MediaTwigFoldersMeta { public function getDirectoryMetaLocation(string $path): bool { - return flextype('media_folders_meta')->getDirectoryMetaLocation($path); + return flextype('media')->folders()->meta()->getDirectoryMetaLocation($path); } } diff --git a/twig/ShortcodeTwigExtension.php b/twig/ShortcodeTwigExtension.php index b996303..279cde0 100644 --- a/twig/ShortcodeTwigExtension.php +++ b/twig/ShortcodeTwigExtension.php @@ -39,7 +39,7 @@ public function getFilters() : array public function shortcode($value) : string { if (!empty($value)) { - return flextype('shortcode')->process($value); + return flextype('parsers')->shortcode()->process($value); } return ''; diff --git a/twig/StringsTwigExtension.php b/twig/StringsTwigExtension.php new file mode 100644 index 0000000..b3d191a --- /dev/null +++ b/twig/StringsTwigExtension.php @@ -0,0 +1,52 @@ +encode($input); + return flextype('serializers')->yaml()->encode($input); } /** @@ -60,6 +60,6 @@ public function encode($input) : string */ public function decode(string $input, bool $cache = true) { - return flextype('yaml')->decode($input, $cache); + return flextype('serializers')->yaml()->decode($input, $cache); } }