Skip to content

Commit

Permalink
Twig 1.4.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Awilum committed Dec 7, 2020
1 parent ad4cf07 commit 660de69
Show file tree
Hide file tree
Showing 11 changed files with 52 additions and 153 deletions.
20 changes: 20 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Global
.composer
composer.lock
package-lock.json
vendor/
node_modules/
dist/

# Flextype Site Specific
var/

# OS Generated
.DS_Store*
ehthumbs.db
Icon?
Thumbs.db
*.swp

# phpstorm
.idea/*
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.4.0"></a>
# [1.4.0](https://github.com/flextype-plugins/twig/compare/v1.3.0...v1.4.0) (2020-12-07)

### Features

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

<a name="1.3.0"></a>
# [1.3.0](https://github.com/flextype-plugins/twig/compare/v1.2.0...v1.3.0) (2020-08-25)

Expand Down
2 changes: 1 addition & 1 deletion LICENSE.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
The MIT License (MIT)

Copyright (c) 2018-2020 Sergey Romanenko
Copyright (c) 2021 Sergey Romanenko

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
10 changes: 5 additions & 5 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.11-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.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>
</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.11 | [download](https://github.com/flextype/flextype/releases) |
| [flextype](https://github.com/flextype/flextype) | 0.9.12 | [download](https://github.com/flextype/flextype/releases) |

## Installation

Expand Down Expand Up @@ -306,15 +306,15 @@ Fetch single entry
Usage:

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

Fetch collection of entries

Usage:

```twig
{% set posts = entries.fetch('blog', {}) %}
{% set posts = entries.fetchSingle('blog', {}) %}
or
{% set posts = entries.fetchCollection('blog') %}
```
Expand Down Expand Up @@ -487,4 +487,4 @@ Usage:

## LICENSE
[The MIT License (MIT)](https://github.com/flextype-plugins/twig/blob/master/LICENSE.txt)
Copyright (c) 2018-2020 [Sergey Romanenko](https://github.com/Awilum)
Copyright (c) 2021 [Sergey Romanenko](https://github.com/Awilum)
4 changes: 3 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@
"php": ">=7.3.0",
"slim/twig-view": "~2.5.0",
"slim/csrf": "~0.8.3",
"slim/flash": "~0.4.0"
"slim/flash": "~0.4.0",
"flextype-components/arrays" : "3.0.1",
"flextype-components/filesystem": "2.0.8"
},
"config": {
"apcu-autoloader": true,
Expand Down
2 changes: 1 addition & 1 deletion dependencies.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
// Get twig settings
$twigSettings = [
'auto_reload' => flextype('registry')->get('plugins.twig.settings.auto_reload'),
'cache' => flextype('registry')->get('plugins.twig.settings.cache') ? PATH['cache'] . '/twig' : false,
'cache' => flextype('registry')->get('plugins.twig.settings.cache') ? PATH['tmp'] . '/twig' : false,
'debug' => flextype('registry')->get('plugins.twig.settings.debug'),
'charset' => flextype('registry')->get('plugins.twig.settings.charset')
];
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.3.0
version: 1.4.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.11
flextype: 0.9.12
95 changes: 8 additions & 87 deletions twig/ArraysTwigExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,8 @@
namespace Flextype\Plugin\Twig\Twig;

use Twig\Extension\AbstractExtension;
use Twig\Extension\GlobalsInterface;
use Flextype\Component\Arrays\Arrays;

class ArraysTwigExtension extends AbstractExtension implements GlobalsInterface
class ArraysTwigExtension extends AbstractExtension
{
/**
* Constructor
Expand All @@ -24,96 +22,19 @@ public function __construct()
}

/**
* Register Global variables in an extension
*/
public function getGlobals() : array
{
return [
'arrays' => new ArraysTwig(),
];
}
}

class ArraysTwig
{
/**
* Flextype Application
*/


/**
* Constructor
*/
public function __construct()
{

}

/**
* Sorts a multi-dimensional array by a certain column
* Callback for twig.
*
* @param array $array The source array
* @param string $field The name of the column
* @param string $direction Order type DESC (descending) or ASC (ascending)
* @param const $method A PHP sort method flag or 'natural' for natural sorting, which is not supported in PHP by sort flags
* @return array
*/
public function sort(array $array, string $field, string $direction = 'ASC', $method = SORT_REGULAR) : array
{
return Arrays::sort($array, $field, $direction, $method);
}

/**
* Sets an array value using "dot notation".
*
* @access public
* @param array $array Array you want to modify
* @param string $path Array path
* @param mixed $value Value to set
*/
public function set(array &$array, string $path, $value)
public function getFunctions() : array
{
Arrays::set($array, $path, $value);
return $array;
}

/**
* Returns value from array using "dot notation".
* If the key does not exist in the array, the default value will be returned instead.
*
* @param array $array Array to extract from
* @param string $path Array path
* @param mixed $default Default value
* @return mixed
*/
public function get(array $array, string $path, $default = null)
{
return Arrays::get($array, $path, $default);
}

/**
* Deletes an array value using "dot notation".
*
* @access public
* @param array $array Array you want to modify
* @param string $path Array path
* @return bool
*/
public function delete(array &$array, string $path) : bool
{
Arrays::delete($array, $path);
return $array;
return [
new \Twig\TwigFunction('arrays', [$this, 'arrays']),
];
}

/**
* Checks if the given dot-notated key exists in the array.
*
* @param array $array The search array
* @param mixed $path Array path
* @return bool
*/
public function has(array $array, $path) : bool
public function arrays($items)
{
return Arrays::has($array, $path);
return arrays($items);
}
}
40 changes: 0 additions & 40 deletions twig/CollectionTwigExtension.php

This file was deleted.

19 changes: 5 additions & 14 deletions twig/EntriesTwigExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class EntriesTwigExtension extends AbstractExtension implements GlobalsInterface
/**
* Register Global variables in an extension
*/
public function getGlobals() : array
public function getGlobals(): array
{
return [
'entries' => new EntriesTwig(),
Expand All @@ -31,7 +31,6 @@ class EntriesTwig
* Flextype Application
*/


/**
* Constructor
*/
Expand All @@ -40,27 +39,19 @@ public function __construct()

}

/**
* Fetch entry(entries)
*/
public function fetch(string $path, bool $collection = false, array $filter = []) : array
{
return flextype('entries')->fetch($path, $collection, $filter);
}

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

/**
* Fetch entries collection
*/
public function fetchCollection(string $path, array $filter = []) : array
public function fetchCollection(string $id, array $options = [])
{
return flextype('entries')->fetchCollection($path, $filter);
return flextype('entries')->fetchCollection($id, $options);
}
}
2 changes: 0 additions & 2 deletions twig/GlobalVarsTwigExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@ public function getGlobals() : array
{
return [
'PATH_PROJECT' => PATH['project'],
'PATH_CACHE' => PATH['cache'],
'PATH_LOGS' => PATH['logs'],
'PHP_VERSION' => PHP_VERSION
];
}
Expand Down

0 comments on commit 660de69

Please sign in to comment.