Skip to content

Commit

Permalink
Twig 1.6.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Awilum committed Dec 20, 2020
1 parent a95f43d commit 6b31d13
Show file tree
Hide file tree
Showing 12 changed files with 131 additions and 54 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
<a name="1.6.0"></a>
# [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

<a name="1.5.1"></a>
# [1.5.1](https://github.com/flextype-plugins/twig/compare/v1.5.0...v1.5.1) (2020-12-10)

Expand Down
18 changes: 8 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<h1 align="center">Twig Plugin for <a href="https://flextype.org/">Flextype</a></h1>

<p align="center">
<a href="https://github.com/flextype-plugins/twig/releases"><img alt="Version" src="https://img.shields.io/github/release/flextype-plugins/twig.svg?label=version&color=black"></a> <a href="https://github.com/flextype-plugins/twig"><img src="https://img.shields.io/badge/license-MIT-blue.svg?color=black" alt="License"></a> <a href="https://github.com/flextype-plugins/twig"><img src="https://img.shields.io/github/downloads/flextype-plugins/twig/total.svg?color=black" alt="Total downloads"></a> <a href="https://github.com/flextype-plugins/twig"><img src="https://img.shields.io/badge/Flextype-0.9.12-green.svg?color=black" alt="Flextype"></a> <a href="https://flextype.org/en/discord"><img src="https://img.shields.io/discord/423097982498635778.svg?logo=discord&color=black&label=Discord%20Chat" alt="Discord"></a>
<a href="https://github.com/flextype-plugins/twig/releases"><img alt="Version" src="https://img.shields.io/github/release/flextype-plugins/twig.svg?label=version&color=black"></a> <a href="https://github.com/flextype-plugins/twig"><img src="https://img.shields.io/badge/license-MIT-blue.svg?color=black" alt="License"></a> <a href="https://github.com/flextype-plugins/twig"><img src="https://img.shields.io/github/downloads/flextype-plugins/twig/total.svg?color=black" alt="Total downloads"></a> <a href="https://github.com/flextype-plugins/twig"><img src="https://img.shields.io/badge/Flextype-0.9.13-green.svg?color=black" alt="Flextype"></a> <a href="https://flextype.org/en/discord"><img src="https://img.shields.io/discord/423097982498635778.svg?logo=discord&color=black&label=Discord%20Chat" alt="Discord"></a>
</p>

Twig plugin to present Twig template engine for Flextype.
Expand All @@ -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

Expand Down Expand Up @@ -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 %}
```
Expand All @@ -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:
Expand All @@ -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:
Expand All @@ -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:
Expand Down Expand Up @@ -306,17 +306,15 @@ Fetch single entry
Usage:

```twig
{% set about_entry = entries.fetchSingle('about') %}
{% set about_entry = entries.fetch('about') %}
```

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
Expand Down
4 changes: 2 additions & 2 deletions plugin.yaml
Original file line number Diff line number Diff line change
@@ -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:
Expand All @@ -11,4 +11,4 @@ bugs: https://github.com/flextype-plugins/twig/issues
license: MIT

dependencies:
flextype: 0.9.12
flextype: 0.9.13
2 changes: 1 addition & 1 deletion settings.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
14 changes: 12 additions & 2 deletions twig/ArraysTwigExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

namespace Flextype\Plugin\Twig\Twig;

use Atomastic\Arrays\Arrays;
use Twig\Extension\AbstractExtension;

class ArraysTwigExtension extends AbstractExtension
Expand All @@ -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<Arrays>
*/
function arrays($items = []): Arrays
{
return arrays($items);
return Arrays::create($items);
}
}
14 changes: 3 additions & 11 deletions twig/EntriesTwigExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
4 changes: 2 additions & 2 deletions twig/JsonTwigExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,14 @@ public function getFilters() : array
*/
public function encode($input) : string
{
return flextype('json')->encode($input);
return flextype('serializers')->json()->encode($input);
}

/**
* Decode JSON
*/
public function decode(string $input, bool $cache = true)
{
return flextype('json')->decode($input, $cache);
return flextype('serializers')->json()->decode($input, $cache);
}
}
2 changes: 1 addition & 1 deletion twig/MarkdownTwigExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 '';
Expand Down
62 changes: 40 additions & 22 deletions twig/MediaTwigExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
2 changes: 1 addition & 1 deletion twig/ShortcodeTwigExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 '';
Expand Down
52 changes: 52 additions & 0 deletions twig/StringsTwigExtension.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<?php

declare(strict_types=1);

/**
* Flextype (https://flextype.org)
* Founded by Sergey Romanenko and maintained by Flextype Community.
*/

namespace Flextype\Plugin\Twig\Twig;

use Atomastic\Strings\Strings;
use Twig\Extension\AbstractExtension;

class StringsTwigExtension extends AbstractExtension
{
/**
* Constructor
*/
public function __construct()
{

}

/**
* Callback for twig.
*
* @return array
*/
public function getFunctions() : array
{
return [
new \Twig\TwigFunction('strings', [$this, 'strings']),
];
}

/**
* Create a new stringable object from the given string.
*
* Initializes a Strings object and assigns both $string and $encoding properties
* the supplied values. $string is cast to a string prior to assignment. Throws
* an InvalidArgumentException if the first argument is an array or object
* without a __toString method.
*
* @param mixed $string Value to modify, after being cast to string. Default: ''
* @param mixed $encoding The character encoding. Default: UTF-8
*/
function strings($string = '', $encoding = 'UTF-8'): Strings
{
return new Strings($string, $encoding);
}
}
4 changes: 2 additions & 2 deletions twig/YamlTwigExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,14 @@ public function getFilters() : array
*/
public function encode($input) : string
{
return flextype('yaml')->encode($input);
return flextype('serializers')->yaml()->encode($input);
}

/**
* Decode YAML
*/
public function decode(string $input, bool $cache = true)
{
return flextype('yaml')->decode($input, $cache);
return flextype('serializers')->yaml()->decode($input, $cache);
}
}

0 comments on commit 6b31d13

Please sign in to comment.