Skip to content

Commit

Permalink
Twig 1.2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Awilum committed Aug 19, 2020
1 parent 814c2b7 commit d3a7893
Show file tree
Hide file tree
Showing 19 changed files with 90 additions and 83 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.2.0"></a>
# [1.2.0](https://github.com/flextype-plugins/twig/compare/v1.1.1...v1.2.0) (2020-08-19)

### Features

* **core** update code base for new Flextype 0.9.10

<a name="1.1.1"></a>
# [1.1.1](https://github.com/flextype-plugins/twig/compare/v1.1.0...v1.1.1) (2020-08-05)

Expand Down
14 changes: 7 additions & 7 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.9-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.10-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.9 | [download](https://github.com/flextype/flextype/releases) |
| [flextype](https://github.com/flextype/flextype) | 0.9.10 | [download](https://github.com/flextype/flextype/releases) |

## Installation

Expand Down Expand Up @@ -165,7 +165,7 @@ List contents of a directory
Usage:

```twig
{% set media = filesystem_list_contents(PATH_UPLOADS ~ '/' ~ entry.slug) %}
{% set media = filesystem_list_contents(PATH_UPLOADS ~ '/' ~ entry.id) %}
```

Result:
Expand All @@ -178,7 +178,7 @@ Check whether a file exists

Usage:
```twig
{% if (filesystem_has(PATH_PROJECT ~ '/uploads/' ~ entry.slug ~ '/about.md')) %}
{% if (filesystem_has(PATH_PROJECT ~ '/uploads/' ~ entry.id ~ '/about.md')) %}
Show something...
{% endif %}
```
Expand All @@ -189,7 +189,7 @@ Read a file

Usage:
```twig
{{ filesystem_read(PATH_PROJECT ~ '/uploads/' ~ entry.slug ~ '/about.md') }}
{{ filesystem_read(PATH_PROJECT ~ '/uploads/' ~ entry.id ~ '/about.md') }}
```

Result:
Expand All @@ -204,7 +204,7 @@ Get file extension

Usage:
```twig
{{ filesystem_ext(PATH_PROJECT ~ '/uploads/' ~ entry.slug ~ '/about.md') }}
{{ filesystem_ext(PATH_PROJECT ~ '/uploads/' ~ entry.id ~ '/about.md') }}
```

Result:
Expand All @@ -218,7 +218,7 @@ Get filename
Usage:

```twig
{{ filesystem_basename(PATH_PROJECT ~ '/uploads/' ~ entry.slug ~ '/about.md') }}
{{ filesystem_basename(PATH_PROJECT ~ '/uploads/' ~ entry.id ~ '/about.md') }}
```

Result:
Expand Down
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"issues": "https://github.com/flextype-plugins/twig/issues"
},
"require": {
"php": ">=7.2.5",
"php": ">=7.3.0",
"slim/twig-view": "~2.5.0",
"slim/csrf": "~0.8.3",
"slim/flash": "~0.4.0"
Expand All @@ -25,7 +25,7 @@
"apcu-autoloader": true,
"optimize-autoloader": true,
"platform": {
"php": "7.2.5"
"php": "7.3.0"
}
},
"autoload": {
Expand Down
20 changes: 10 additions & 10 deletions dependencies.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,28 +22,28 @@
/**
* Add CSRF (cross-site request forgery) protection service to Flextype container
*/
$flextype['csrf'] = static function ($container) {
$flextype->container()['csrf'] = static function () use ($flextype){
return new Guard();
};

/**
* Add Twig service to Flextype container
*/
$flextype['twig'] = static function ($container) {
$flextype->container()['twig'] = static function () use ($flextype) {

// Get twig settings
$twigSettings = [
'auto_reload' => $container['registry']->get('plugins.twig.settings.auto_reload'),
'cache' => $container['registry']->get('plugins.twig.settings.cache') ? PATH['cache'] . '/twig' : false,
'debug' => $container['registry']->get('plugins.twig.settings.debug'),
'charset' => $container['registry']->get('plugins.twig.settings.charset')
'auto_reload' => $flextype->container('registry')->get('plugins.twig.settings.auto_reload'),
'cache' => $flextype->container('registry')->get('plugins.twig.settings.cache') ? PATH['cache'] . '/twig' : false,
'debug' => $flextype->container('registry')->get('plugins.twig.settings.debug'),
'charset' => $flextype->container('registry')->get('plugins.twig.settings.charset')
];

// Create Twig View
$twig = new Twig(PATH['project'], $twigSettings);

// Instantiate
$router = $container->get('router');
$router = $flextype->container('router');
$uri = Uri::createFromEnvironment(new Environment($_SERVER));

// Add Twig Extension
Expand All @@ -53,7 +53,7 @@
$twig->addExtension(new DebugExtension());

// Load Flextype Twig extensions from directory /flextype/twig/ based on settings.twig.extensions array
$twig_extensions = $container['registry']->get('plugins.twig.settings.extensions');
$twig_extensions = $flextype->container('registry')->get('plugins.twig.settings.extensions');

foreach ($twig_extensions as $twig_extension) {
$twig_extension_class_name = $twig_extension . 'TwigExtension';
Expand All @@ -62,12 +62,12 @@
if (file_exists(ROOT_DIR . '/project/plugins/twig/twig/' . $twig_extension_class_name . '.php')) {

if ($twig_extension == 'Flash') {
$container['flash'] = static function () {
$flextype->container()['flash'] = static function () {
return new Messages();
};
}

$twig->addExtension(new $twig_extension_class_name_with_namespace($container));
$twig->addExtension(new $twig_extension_class_name_with_namespace($flextype));
}
}

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.1.1
version: 1.2.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.9
flextype: 0.9.10
8 changes: 4 additions & 4 deletions twig/ArraysTwigExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@
class ArraysTwigExtension extends AbstractExtension implements GlobalsInterface
{
/**
* Flextype Dependency Container
* Flextype Application
*/
private $flextype;
protected $flextype;

/**
* Constructor
Expand All @@ -42,9 +42,9 @@ public function getGlobals() : array
class ArraysTwig
{
/**
* Flextype Dependency Container
* Flextype Application
*/
private $flextype;
protected $flextype;

/**
* Constructor
Expand Down
6 changes: 3 additions & 3 deletions twig/CacheTwigExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@
class CacheTwigExtension extends AbstractExtension implements GlobalsInterface
{
/**
* Flextype Dependency Container
* Flextype Application
*/
private $flextype;
protected $flextype;

/**
* Constructor
Expand All @@ -33,7 +33,7 @@ public function __construct($flextype)
public function getGlobals() : array
{
return [
'cache' => $this->flextype['cache'],
'cache' => $this->flextype->container('cache'),
];
}
}
4 changes: 2 additions & 2 deletions twig/CollectionTwigExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@
class CollectionTwigExtension extends AbstractExtension
{
/**
* Flextype Dependency Container
* Flextype Application
*/
private $flextype;
protected $flextype;

/**
* Constructor
Expand Down
16 changes: 8 additions & 8 deletions twig/CsrfTwigExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@
class CsrfTwigExtension extends AbstractExtension implements GlobalsInterface
{
/**
* Flextype Dependency Container
* Flextype Application
*/
private $flextype;
protected $flextype;

/**
* Constructor
Expand All @@ -33,10 +33,10 @@ public function __construct($flextype)
public function getGlobals() : array
{
// CSRF token name and value
$csrfNameKey = $this->flextype->csrf->getTokenNameKey();
$csrfValueKey = $this->flextype->csrf->getTokenValueKey();
$csrfName = $this->flextype->csrf->getTokenName();
$csrfValue = $this->flextype->csrf->getTokenValue();
$csrfNameKey = $this->flextype->container('csrf')->getTokenNameKey();
$csrfValueKey = $this->flextype->container('csrf')->getTokenValueKey();
$csrfName = $this->flextype->container('csrf')->getTokenName();
$csrfValue = $this->flextype->container('csrf')->getTokenValue();

return [
'csrf' => [
Expand Down Expand Up @@ -72,7 +72,7 @@ public function getFunctions() : array
*/
public function csrf() : string
{
return '<input type="hidden" name="' . $this->flextype->csrf->getTokenNameKey() . '" value="' . $this->flextype->csrf->getTokenName() . '">' .
'<input type="hidden" name="' . $this->flextype->csrf->getTokenValueKey() . '" value="' . $this->flextype->csrf->getTokenValue() . '">';
return '<input type="hidden" name="' . $this->flextype->container('csrf')->getTokenNameKey() . '" value="' . $this->flextype->container('csrf')->getTokenName() . '">' .
'<input type="hidden" name="' . $this->flextype->container('csrf')->getTokenValueKey() . '" value="' . $this->flextype->container('csrf')->getTokenValue() . '">';
}
}
12 changes: 6 additions & 6 deletions twig/EmitterTwigExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@
class EmitterTwigExtension extends AbstractExtension implements GlobalsInterface
{
/**
* Flextype Dependency Container
* Flextype Application
*/
private $flextype;
protected $flextype;

/**
* Constructor
Expand All @@ -41,9 +41,9 @@ public function getGlobals() : array
class EmitterTwig
{
/**
* Flextype Dependency Container
* Flextype Application
*/
private $flextype;
protected $flextype;

/**
* Constructor
Expand All @@ -58,14 +58,14 @@ public function __construct($flextype)
*/
public function emit($event)
{
return $this->flextype['emitter']->emit($event);
return $this->flextype->container('emitter')->emit($event);
}

/**
* Emitting events in batches
*/
public function emitBatch(array $events)
{
return $this->flextype['emitter']->emitBatch($events);
return $this->flextype->container('emitter')->emitBatch($events);
}
}
14 changes: 7 additions & 7 deletions twig/EntriesTwigExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@
class EntriesTwigExtension extends AbstractExtension implements GlobalsInterface
{
/**
* Flextype Dependency Container
* Flextype Application
*/
private $flextype;
protected $flextype;

/**
* Constructor
Expand All @@ -41,9 +41,9 @@ public function getGlobals() : array
class EntriesTwig
{
/**
* Flextype Dependency Container
* Flextype Application
*/
private $flextype;
protected $flextype;

/**
* Constructor
Expand All @@ -58,22 +58,22 @@ public function __construct($flextype)
*/
public function fetch(string $path, bool $collection = false, array $filter = []) : array
{
return $this->flextype['entries']->fetch($path, $collection, $filter);
return $this->flextype->container('entries')->fetch($path, $collection, $filter);
}

/**
* Fetch single entry
*/
public function fetchSingle(string $path) : array
{
return $this->flextype['entries']->fetch($path);
return $this->flextype->container('entries')->fetch($path);
}

/**
* Fetch entries collection
*/
public function fetchCollection(string $path, array $filter = []) : array
{
return $this->flextype['entries']->fetchCollection($path, $filter);
return $this->flextype->container('entries')->fetchCollection($path, $filter);
}
}
8 changes: 4 additions & 4 deletions twig/FlashTwigExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@
class FlashTwigExtension extends AbstractExtension
{
/**
* Flextype Dependency Container
* Flextype Application
*/
private $flextype;
protected $flextype;

/**
* Constructor
Expand Down Expand Up @@ -47,9 +47,9 @@ public function getFunctions() : array
public function getMessages(?string $key = null) : array
{
if ($key !== null) {
return $this->flextype['flash']->getMessage($key);
return $this->flextype->container('flash')->getMessage($key);
}

return $this->flextype['flash']->getMessages();
return $this->flextype->container('flash')->getMessages();
}
}
4 changes: 2 additions & 2 deletions twig/GlobalVarsTwigExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@
class GlobalVarsTwigExtension extends AbstractExtension implements GlobalsInterface
{
/**
* Flextype Dependency Container
* Flextype Application
*/
private $flextype;
protected $flextype;

/**
* Constructor
Expand Down
Loading

0 comments on commit d3a7893

Please sign in to comment.