Skip to content

Commit

Permalink
Merge pull request #86 from sitegeist/feature/dataUriPrototypes
Browse files Browse the repository at this point in the history
FEATURE: Add data-uri prototypes
  • Loading branch information
mficzel authored Jul 24, 2018
2 parents 2f3d933 + e098338 commit 481cf74
Show file tree
Hide file tree
Showing 5 changed files with 95 additions and 0 deletions.
42 changes: 42 additions & 0 deletions Classes/Sitegeist/Monocle/FusionObjects/DataUriImplementation.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?php
namespace Sitegeist\Monocle\FusionObjects;

use Neos\Flow\Annotations as Flow;
use Neos\Fusion\FusionObjects\AbstractFusionObject;

/**
* Renderer props for a prototype Object
*/
class DataUriImplementation extends AbstractFusionObject
{

/**
* @return string
*/
public function getType()
{
return $this->fusionValue('type');
}

/**
* @return string
*/
public function getContent()
{
return $this->fusionValue('content');
}

/**
* Render a prototype
*
* @return mixed
*/
public function evaluate()
{
$type = $this->getType();
$content = $this->getContent();
if ($type && $content) {
return 'data:' . $type . ';base64,' . base64_encode($content);
}
}
}
31 changes: 31 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,37 @@ therefore highly reusable.
The distinction between rendering- and mapping-prototypes can be compared to
presentational-components vs. container-components in the ReactJS world.

### Simulate API-Endpoints

Monocle has fusion-prototypes to simulate json api responses for components.

- `Sitegeist.Monocle:DataUri`: Generic data uri implementation that expects `type` and `content` as string
- `Sitegeist.Monocle:DataUri.Json`: And endpoint-mock with media-type `application/json` that will pass `content` trough Json.stringify
- `Sitegeist.Monocle:DataUri.Text`: And endpoint-mock with media-type `text/plain`

The DataUri-Prototypes will encode the content as base64.

```
prototype(Vendor.Package:Component.SearchExample) < prototype(Neos.Fusion:Component) {
@styleguide {
props {
endpointUrl = Sitegeist.Monocle:DataUri.Json {
content = Neos.Fusion:RawArray {
term = 'hamburch'
suggestedTerm = 'hamburg'
}
}
}
}
endpointUrl = null
renderer = afx`
<div data-endpoint-url={props.endpointUrl} />
`
}
```

### Preview Configuration

Some configuration is available to configure the preview.
Expand Down
6 changes: 6 additions & 0 deletions Resources/Private/Fusion/Prototypes/DataUri/DataUri.fusion
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
prototype(Sitegeist.Monocle:DataUri) {
@class = 'Sitegeist\\Monocle\\FusionObjects\\DataUriImplementation'

type = null
content = null
}
8 changes: 8 additions & 0 deletions Resources/Private/Fusion/Prototypes/DataUri/Json.fusion
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
prototype(Sitegeist.Monocle:DataUri.Json) < prototype(Neos.Fusion:Component) {
content = null

renderer = Sitegeist.Monocle:DataUri {
type = 'application/json'
content = ${Json.stringify(props.content)}
}
}
8 changes: 8 additions & 0 deletions Resources/Private/Fusion/Prototypes/DataUri/Text.fusion
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
prototype(Sitegeist.Monocle:DataUri.Text) < prototype(Neos.Fusion:Component) {
content = null

renderer = Sitegeist.Monocle:DataUri {
type = 'text/plain'
content = ${props.content}
}
}

0 comments on commit 481cf74

Please sign in to comment.