Skip to content

Commit

Permalink
Twig 3.2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Awilum committed Sep 13, 2022
1 parent 1a86511 commit 166afc6
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 1 deletion.
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
<a name="3.2.0"></a>
# [3.2.0](https://github.com/flextype-plugins/twig/compare/v3.1.0...v3.2.0) (2022-09-13)

### Features

* **core** Add new functions `abs` and `round` for Math Extension.

* **core** Add new filter `expressions`.

* **core** Add new extensions `Fetch`.


<a name="3.1.0"></a>
# [3.1.0](https://github.com/flextype-plugins/twig/compare/v3.0.0...v3.1.0) (2022-09-13)

Expand Down
2 changes: 1 addition & 1 deletion plugin.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: Twig
version: 3.1.0
version: 3.2.0
description: Twig plugin to present Twig template engine for Flextype.
icon:
name: palette
Expand Down
1 change: 1 addition & 0 deletions settings.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ extensions:
- Image
- Url
- Vars
- Fetch

# Twig plugin priority
priority: 0
36 changes: 36 additions & 0 deletions src/twig/core/Extensions/FetchTwigExtension.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?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.
*/

namespace Flextype\Plugin\Twig\Extension;

use Twig\Extension\AbstractExtension;
use Twig\TwigFunction;
use function Flextype\fetch;

class FetchTwigExtension extends AbstractExtension
{
/**
* Callback for twig.
*
* @return array
*/
public function getFunctions() : array
{
return [
new TwigFunction('fetch', '\Flextype\fetch')
];
}
}
6 changes: 6 additions & 0 deletions src/twig/core/Extensions/FiltersTwigExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ public function getFilters() : array
new TwigFilter('shortcodes', [$this, 'shortcodes']),
new TwigFilter('textile', [$this, 'textile']),
new TwigFilter('markdown', [$this, 'markdown']),
new TwigFilter('expressions', [$this, 'expressions']),
];
}

Expand All @@ -50,4 +51,9 @@ public function markdown($value): string
{
return !empty($value) ? parsers()->markdown()->parse($value) : '';
}

public function expressions($value): string
{
return !empty($value) ? parsers()->expressions()->evaluate($value) : '';
}
}
2 changes: 2 additions & 0 deletions src/twig/core/Extensions/MathTwigExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ public function getFunctions() : array
return [
new TwigFunction('ceil', '\ceil'),
new TwigFunction('floor', '\floor'),
new TwigFunction('round', '\round'),
new TwigFunction('abs', '\abs'),
new TwigFunction('min', '\min'),
new TwigFunction('max', '\max')
];
Expand Down

0 comments on commit 166afc6

Please sign in to comment.