Skip to content

Commit

Permalink
FEATURE: Preview for non site packages
Browse files Browse the repository at this point in the history
The `packages` configuration can now be used to configure non-site packages for previewing in the styleguide.

When a prototyope of a non-site package is rendered Monocle will only load the Root.fusion of this specific package and the Monocle Root.fusion. Every other fusion including the default fusion has to be included explicitly. This mimics the behavior of the classic FusionView that is used for FusionRendering of Flow Controller Actions.

```YAML
Sitegeist:
  Monocle:
    packages:
      #add a key to the package list without package specific configuration
      'Vendor.Example': {}
```
  • Loading branch information
mficzel committed Jun 10, 2021
1 parent 668aa35 commit c964170
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 26 deletions.
35 changes: 25 additions & 10 deletions Classes/Fusion/FusionService.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
*/

use Neos\Flow\Annotations as Flow;
use Neos\Flow\Package\PackageManager;
use Neos\Flow\Persistence\Aspect\EmbeddedValueObjectPointcutFilter;
use \Neos\Neos\Domain\Service\FusionService as NeosFusionService;

/**
Expand All @@ -30,17 +32,23 @@ class FusionService extends NeosFusionService
*/
protected $autoIncludeConfiguration = array();

/**
* @Flow\Inject
* @var PackageManager
*/
protected $packageManager;

/**
* Returns a merged fusion object tree in the context of the given site-package
*
* @param string $siteResourcesPackageKey
* @param string $packageKey
* @return array The merged object tree as of the given node
* @throws \Neos\Neos\Domain\Exception
* @deprecated
*/
public function getMergedTypoScriptObjectTreeForSitePackage($siteResourcesPackageKey)
public function getMergedTypoScriptObjectTreeForSitePackage($packageKey)
{
return $this->getMergedFusionObjectTreeForSitePackage($siteResourcesPackageKey);
return $this->getMergedFusionObjectTreeForSitePackage($packageKey);
}

/**
Expand All @@ -53,15 +61,22 @@ public function getMergedTypoScriptObjectTreeForSitePackage($siteResourcesPackag
public function getMergedFusionObjectTreeForSitePackage($siteResourcesPackageKey)
{
$siteRootFusionPathAndFilename = sprintf($this->siteRootFusionPattern, $siteResourcesPackageKey);
$package = $this->packageManager->getPackage($siteResourcesPackageKey);

$mergedFusionCode = '';
$mergedFusionCode .= $this->generateNodeTypeDefinitions();
$mergedFusionCode .= $this->getFusionIncludes($this->prepareAutoIncludeFusion());
$mergedFusionCode .= $this->getFusionIncludes($this->prependFusionIncludes);
$mergedFusionCode .= $this->readExternalFusionFile($siteRootFusionPathAndFilename);
$mergedFusionCode .= $this->getFusionIncludes($this->appendFusionIncludes);
$fusionCode = '';

if ($package->getComposerManifest('type') == 'neos-site') {
$fusionCode .= $this->generateNodeTypeDefinitions();
$fusionCode .= $this->getFusionIncludes($this->prepareAutoIncludeFusion());
$fusionCode .= $this->getFusionIncludes($this->prependFusionIncludes);
$fusionCode .= $this->readExternalFusionFile($siteRootFusionPathAndFilename);
$fusionCode .= $this->getFusionIncludes($this->appendFusionIncludes);
} else {
$fusionCode .= 'include: resource://Sitegeist.Monocle/Private/Fusion/Root.fusion' . PHP_EOL;
$fusionCode .= 'include: resource://' . $siteResourcesPackageKey . '/Private/Fusion/Root.fusion' . PHP_EOL;
}

return $this->fusionParser->parse($mergedFusionCode, $siteRootFusionPathAndFilename);
return $this->fusionParser->parse($fusionCode, $siteRootFusionPathAndFilename);
}


Expand Down
17 changes: 12 additions & 5 deletions Classes/Service/PackageKeyTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@ trait PackageKeyTrait
*/
protected $packageManager;

/**
* @Flow\InjectConfiguration("packages")
* @var mixed[]
*/
protected $packageConfigurations;

/**
* Determine the default site package key
*
Expand All @@ -30,16 +36,17 @@ protected function getDefaultSitePackageKey()

/**
* Get a list of all active site package keys
* @return array
* @return string[]
*/
protected function getActiveSitePackageKeys()
protected function getActiveSitePackageKeys(): array
{
$sitePackages = $this->packageManager->getFilteredPackages('available', null, 'neos-site');
$result = [];
$sitePackageKeys = [];
foreach ($sitePackages as $sitePackage) {
$packageKey = $sitePackage->getPackageKey();
$result[] = $packageKey;
$sitePackageKeys[] = $packageKey;
}
return $result;
$configuredPackageKeys = $this->packageConfigurations ? array_keys($this->packageConfigurations) : [];
return array_unique(array_merge($sitePackageKeys, $configuredPackageKeys));
}
}
35 changes: 24 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,7 @@ Sitegeist:

This allows for including prototypes of packages selectively.

### Site-specific configuration
### Package-specific configuration

All configurations can be overwritten for each selected site package.

Expand All @@ -369,6 +369,19 @@ Sitegeist:
height: 1000
```

This packages configuration can also be used to configure non-site packages for previewing in the styleguide.

When a prototyope of a non-site package is rendered Monocle will only load the Root.fusion of this specific package and the Monocle Root.fusion. Every other fusion including the default fusion has to be included
explicitly. This mimics the behavior of the classic FusionView that is used for FusionRendering of Flow Controller Actions.

```YAML
Sitegeist:
Monocle:
packages:
#add a key to the package list without package specific configuration
'Vendor.Example': {}
```

### Fusion

Sitegeist.Monocle brings some fusion-prototypes that you can use or adjust to your needs.
Expand All @@ -384,19 +397,19 @@ prototype(Sitegeist.Monocle:Preview.Page) {
metaViewport = '<meta name="viewport" content="width=device-width">'

stylesheets.main = Neos.Fusion:Tag {
tagName = 'link'
attributes.rel = 'stylesheet'
attributes.href = Neos.Fusion:ResourceUri {
path = 'resource://Vendor.Site/Public/Styles/main.css'
}
tagName = 'link'
attributes.rel = 'stylesheet'
attributes.href = Neos.Fusion:ResourceUri {
path = 'resource://Vendor.Site/Public/Styles/main.css'
}
}

javascripts.main = Neos.Fusion:Tag {
tagName = 'script'
attributes.src = Neos.Fusion:ResourceUri {
path = 'resource://Vendor.Site/Public/JavaScript/main.js'
}
}
tagName = 'script'
attributes.src = Neos.Fusion:ResourceUri {
path = 'resource://Vendor.Site/Public/JavaScript/main.js'
}
}
}
}
```
Expand Down

0 comments on commit c964170

Please sign in to comment.