From 836af9a7cc457bc89a0d763bdca2a616eeab965a Mon Sep 17 00:00:00 2001 From: Martin Ficzel Date: Thu, 6 Jul 2017 11:21:02 +0200 Subject: [PATCH 1/3] TASK: Add `PackageFactory.AtomicFusion:Augmenter` fusion-prototype This prototype can augment the given html with additional attributes and can be used as standalone component or as processor. --- .../FusionObjects/AugmenterImplementation.php | 66 +++++++++++++++++++ README.md | 48 ++++++++++++++ .../Fusion/Prototypes/Augmenter.fusion | 6 ++ 3 files changed, 120 insertions(+) create mode 100644 Classes/PackageFactory/AtomicFusion/FusionObjects/AugmenterImplementation.php create mode 100644 Resources/Private/Fusion/Prototypes/Augmenter.fusion diff --git a/Classes/PackageFactory/AtomicFusion/FusionObjects/AugmenterImplementation.php b/Classes/PackageFactory/AtomicFusion/FusionObjects/AugmenterImplementation.php new file mode 100644 index 0000000..69e14cf --- /dev/null +++ b/Classes/PackageFactory/AtomicFusion/FusionObjects/AugmenterImplementation.php @@ -0,0 +1,66 @@ + + * Martin Ficzel + * + * 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; + } + } +} diff --git a/README.md b/README.md index 1d8447a..7a2bbf9 100644 --- a/README.md +++ b/README.md @@ -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 @@ -93,6 +94,53 @@ 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 +# +augmentatedContent = PackageFactory.AtomicFusion:Augmenter { + + # + # The content that shall be augmented. + # !The result has to be html. + # + 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 +# +augmentatedContent = 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`. diff --git a/Resources/Private/Fusion/Prototypes/Augmenter.fusion b/Resources/Private/Fusion/Prototypes/Augmenter.fusion new file mode 100644 index 0000000..15e5c94 --- /dev/null +++ b/Resources/Private/Fusion/Prototypes/Augmenter.fusion @@ -0,0 +1,6 @@ +prototype(PackageFactory.AtomicFusion:Augmenter) < prototype(PackageFactory.AtomicFusion:Component) { + @class = 'PackageFactory\\AtomicFusion\\FusionObjects\\AugmenterImplementation' + + fallbackTagName = "div" + content = ${value} +} From 08ce45f1b4283876fd84125aa3c32f2630af6d6c Mon Sep 17 00:00:00 2001 From: Martin Ficzel Date: Tue, 11 Jul 2017 15:00:29 +0200 Subject: [PATCH 2/3] DOCS: Fix typo --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 7a2bbf9..72fa3e1 100644 --- a/README.md +++ b/README.md @@ -102,7 +102,7 @@ The Augmenter-component can be used as processor or as a standalone prototype # # Standalone-Augmenter # -augmentatedContent = PackageFactory.AtomicFusion:Augmenter { +augmentedContent = PackageFactory.AtomicFusion:Augmenter { # # The content that shall be augmented. @@ -131,7 +131,7 @@ augmentatedContent = PackageFactory.AtomicFusion:Augmenter { # # Processor-Augmenter # -augmentatedContent = Neos.Fusion:Tag { +augmentedContent = Neos.Fusion:Tag { tagName = 'h2' content = 'Lorem Ipsum' @process.augment = PackageFactory.AtomicFusion:Augmenter { From 898e535e89cd837bce84ef41983fbd6c4cdff385 Mon Sep 17 00:00:00 2001 From: Martin Ficzel Date: Mon, 17 Jul 2017 13:49:28 +0200 Subject: [PATCH 3/3] Update README.md --- README.md | 1 - 1 file changed, 1 deletion(-) diff --git a/README.md b/README.md index 72fa3e1..d7c9cc4 100644 --- a/README.md +++ b/README.md @@ -106,7 +106,6 @@ augmentedContent = PackageFactory.AtomicFusion:Augmenter { # # The content that shall be augmented. - # !The result has to be html. # content = Neos.Fusion:Tag { tagName = 'h2'