Skip to content
This repository has been archived by the owner on Sep 12, 2019. It is now read-only.

Commit

Permalink
Merge pull request #11 from PackageFactory/feature/addAugmenterPrototype
Browse files Browse the repository at this point in the history
FEATURE: Add `PackageFactory.AtomicFusion:Augmenter` fusion-prototype
  • Loading branch information
mficzel authored Jul 17, 2017
2 parents 37d08c5 + 898e535 commit 66e1b3b
Show file tree
Hide file tree
Showing 3 changed files with 119 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
<?php
namespace PackageFactory\AtomicFusion\FusionObjects;

/**
* This file is part of the PackageFactory.AtomicFusion package
*
* (c) 2016
* Wilhelm Behncke <wilhelm.behncke@googlemail.com>
* Martin Ficzel <martin.ficzel@gmx.de>
*
* This package is Open Source Software. For the full copyright and license
* information, please view the LICENSE file which was distributed with this
* source code.
*/

use Neos\Flow\Annotations as Flow;
use Neos\Fusion\FusionObjects\ArrayImplementation;
use Neos\Neos\Service\HtmlAugmenter;

/**
* A Fusion Augmenter-Object
*
* The fusion object can be used to add html-attributes to the rendererd content
*
* @api
*/
class AugmenterImplementation extends ArrayImplementation
{

/**
* @var HtmlAugmenter
* @Flow\Inject
*/
protected $htmlAugmenter;

/**
* Properties that are ignored
*
* @var array
*/
protected $ignoreProperties = ['__meta', 'fallbackTagName', 'content'];

/**
* @return void|string
*/
public function evaluate()
{
$content = $this->fusionValue('content');
$fallbackTagName = $this->fusionValue('fallbackTagName');

$sortedChildFusionKeys = $this->sortNestedFusionKeys();

$attributes = [];
foreach ($sortedChildFusionKeys as $key) {
if ($fusionValue = $this->fusionValue($key)) {
$attributes[$key] = $fusionValue;
}
}

if ($attributes && is_array($attributes) && count($attributes) > 0) {
return $this->htmlAugmenter->addAttributes($content, $attributes, $fallbackTagName);
} else {
return $content;
}
}
}
47 changes: 47 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ and afterwards evaluetes the `renderer`
- `PackageFactory.AtomicFusion:ClassNames`: create conditional class-names from fusion-keys
- `PackageFactory.AtomicFusion:Editable`: create and editable tag for a property
- `PackageFactory.AtomicFusion:Content`: component base-prototype for inline editable content nodes
- `PackageFactory.AtomicFusion:Augmenter`: add html-attributes to the rendered children

## Usage

Expand Down Expand Up @@ -93,6 +94,52 @@ prototype(Vendor.Site:ExampleContent) < prototype(PackageFactory.AtomicFusion:Co
}
```

### 3. Content Augmentation

The Augmenter-component can be used as processor or as a standalone prototype

```
#
# Standalone-Augmenter
#
augmentedContent = PackageFactory.AtomicFusion:Augmenter {
#
# The content that shall be augmented.
#
content = Neos.Fusion:Tag {
tagName = 'h2'
content = 'Lorem Ipsum'
}
#
# If more than one tag is found the content is wrapped in the
# fallback-Tag before augmentation wich has "div" as default
#
fallbackTagName = 'div'
#
# All other fusion properties are added to the html-content
# as html-attributes.
#
class="foo"
data-example="data"
}
#
# Processor-Augmenter
#
augmentedContent = Neos.Fusion:Tag {
tagName = 'h2'
content = 'Lorem Ipsum'
@process.augment = PackageFactory.AtomicFusion:Augmenter {
class = "foo"
data-example="data"
}
}
```

## Installation

PackageFactory.AtomicFusion is available via packagist. Just run `composer require packagefactory/atomicfusion`.
Expand Down
6 changes: 6 additions & 0 deletions Resources/Private/Fusion/Prototypes/Augmenter.fusion
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
prototype(PackageFactory.AtomicFusion:Augmenter) < prototype(PackageFactory.AtomicFusion:Component) {
@class = 'PackageFactory\\AtomicFusion\\FusionObjects\\AugmenterImplementation'

fallbackTagName = "div"
content = ${value}
}

0 comments on commit 66e1b3b

Please sign in to comment.