Skip to content

Commit

Permalink
Merge pull request #115 from getherbie/2.x-develop
Browse files Browse the repository at this point in the history
2.x develop
  • Loading branch information
tbreuss authored Dec 27, 2022
2 parents 9d5f418 + 25e2008 commit f75df2b
Show file tree
Hide file tree
Showing 103 changed files with 2,063 additions and 2,313 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/cicd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ jobs:
matrix:
# operating-systems: ubuntu-latest, windows-latest, macos-latest
operating-system: [ubuntu-latest]
# php-versions: 7.4, 8.0, 8.1
php-versions: ['7.4', '8.0', '8.1']
# php-versions: 8.0, 8.1, 8.2
php-versions: ['8.0', '8.1', '8.2']
runs-on: ${{ matrix.operating-system }}
steps:
- name: Checkout
Expand Down Expand Up @@ -61,7 +61,7 @@ jobs:
- name: Setup PHP and Composer
uses: shivammathur/setup-php@v2
with:
php-version: 7.4
php-version: 8.0
tools: composer:v2

- name: Install PHP dependencies
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ TBD
The easiest way to install Herbie is through Composer.
Run the following commands in your terminal to create a new project and install all dependent libraries.

For the upcoming 2.x version (PHP 7.4, 8.0, 8.1):
For the upcoming 2.x version (PHP 8.x):

composer create-project getherbie/start-website:dev-master mywebsite

Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
}
},
"require": {
"php": ">=7.4",
"php": ">=8.0",
"ext-json": "*",
"composer-runtime-api": "^2.0",
"ausi/slug-generator": "^1.1",
Expand Down
20 changes: 10 additions & 10 deletions plugins/imagine/ImagineSysPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,13 @@ public function twigFunctions(): array
];
}

public function imagineFunction(string $path, string $filterSet = 'default', array $attribs = []): string
public function imagineFunction(string $path, string $collection = 'default', array $attribs = []): string
{
$abspath = $this->alias->get('@media/' . $path);
$absolutePath = $this->alias->get('@media/' . $path);

$attribs['class'] = $attribs['class'] ?? 'imagine';

if (!is_file($abspath)) {
if (!is_file($absolutePath)) {
$attribs['class'] = trim($attribs['class'] . ' imagine--file-not-found');
return sprintf(
'<img src="%s"%s>',
Expand All @@ -65,7 +65,7 @@ public function imagineFunction(string $path, string $filterSet = 'default', arr
);
}

$sanitizedFilter = $this->sanitizeFilterName($filterSet);
$sanitizedFilter = $this->sanitizeFilterName($collection);

$attribs['class'] = trim($attribs['class'] . ' imagine--filter-' . $sanitizedFilter);

Expand Down Expand Up @@ -98,16 +98,16 @@ private function getTransparentOnePixelSrc(): string
/**
* Gets the browser path for the image and filter to apply.
*/
public function imagineFilter(string $path, string $filterSet = 'default'): Markup
public function imagineFilter(string $path, string $collection = 'default'): Markup
{
$abspath = $this->alias->get('@media/' . $path);
$absolutePath = $this->alias->get('@media/' . $path);

if (!is_file($abspath)) {
if (!is_file($absolutePath)) {
$dataSrc = $this->getTransparentOnePixelSrc();
return new Markup($dataSrc, 'utf8');
}

$sanitizedFilterSet = $this->sanitizeFilterName($filterSet);
$sanitizedFilterSet = $this->sanitizeFilterName($collection);

return new Markup(
$this->basePath . $this->applyFilterSet($path, $sanitizedFilterSet),
Expand All @@ -118,7 +118,7 @@ public function imagineFilter(string $path, string $filterSet = 'default'): Mark
private function sanitizeFilterName(string $filterSet): string
{
if ($filterSet !== 'default') {
if ($this->config->check("plugins.imagine.filterSets.{$filterSet}") === false) {
if ($this->config->check("plugins.imagine.collections.{$filterSet}") === false) {
$filterSet = 'default';
}
}
Expand All @@ -141,7 +141,7 @@ protected function applyFilterSet(string $relpath, string $filterSet): string
{
$path = $this->alias->get('@media/' . $relpath);

$filterConfig = $this->config->getAsArray("plugins.imagine.filterSets.{$filterSet}");
$filterConfig = $this->config->getAsArray("plugins.imagine.collections.{$filterSet}");
$cachePath = $this->resolveCachePath($relpath, $filterSet);

if (!empty($filterConfig['test'])) {
Expand Down
22 changes: 11 additions & 11 deletions plugins/imagine/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,22 +27,22 @@ return [
'plugins' => [
'imagine' => [
'cachePath' => 'cache/imagine',
'filterSets' => []
'collections' => []
]
]
];
~~~

## Filter sets

To use Imagine in Herbie, Filter sets must be defined, each containing one or more filters.
To use Imagine in Herbie, one or more filter collections must be defined, each containing one or more filters.

The following default filter set is always enabled.
The following default collection is always enabled.

~~~php
return [
// ...
'filterSets' => [
'collections' => [
'default' => [
'test' => true,
'filters' => [
Expand All @@ -57,11 +57,11 @@ return [
];
~~~

In the following configuration example, we see two simple filter sets for scaling and cropping an image.
In the following configuration example, we see two simple collections for scaling and cropping an image.

~~~php
'imagine'
'filterSets' => [
'collections' => [
'resize' => [
'filters' => [
'thumbnail' => [
Expand All @@ -82,10 +82,10 @@ In the following configuration example, we see two simple filter sets for scalin
],
~~~

With the above configuration you set two Imagine filters `resize` and `crop` that can be applied to images in your project.
With the above configuration you set two Imagine collections `resize` and `crop` that can be applied to images in your project.

- A resize filterSet to resize an image to a size of 280 x 280 pixels
- A crop filterSet to crop an image to a size of 560 x 560 pixels
- A resize collection to resize an image to a size of 280 x 280 pixels
- A crop collection to crop an image to a size of 560 x 560 pixels

## Usage

Expand All @@ -107,9 +107,9 @@ With the activation of the system plugin, one Twig filter and one Twig function
<td></td>
</tr>
<tr class="param">
<td>filterSet</td>
<td>collection</td>
<td>string</td>
<td>The filter set to be applied.</td>
<td>The filter collection to be applied.</td>
<td>default</td>
</tr>
<tr class="return">
Expand Down
2 changes: 1 addition & 1 deletion plugins/imagine/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
'pluginClass' => ImagineSysPlugin::class,
'pluginPath' => __DIR__,
'cachePath' => 'cache/imagine',
'filterSets' => [
'collections' => [
'default' => [
'test' => true,
'filters' => [
Expand Down
19 changes: 19 additions & 0 deletions plugins/twig/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Twig System Plugin

`Twig` is a [Herbie](http://github.com/getherbie) system plugin that brings support for several Twig filters, functions and tests.

## Installation

The plugin is installed already.

To activate it, add `twig` to the `enabledSysPlugins` configuration option.

~~~php
return [
'enabledSysPlugins' => 'twig'
];
~~~

## More Information

For more information, see <https://herbie.tebe.ch>.
Loading

0 comments on commit f75df2b

Please sign in to comment.