Skip to content

Commit

Permalink
Merge pull request #151 from sitegeist/feature/previewForNonSitePackages
Browse files Browse the repository at this point in the history
FEATURE: Preview for non site packages
  • Loading branch information
mficzel authored Jun 23, 2021
2 parents 668aa35 + 7954576 commit f03ac3e
Show file tree
Hide file tree
Showing 4 changed files with 85 additions and 23 deletions.
28 changes: 21 additions & 7 deletions Classes/Fusion/FusionService.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
*/

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

/**
Expand All @@ -30,6 +31,12 @@ 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
*
Expand All @@ -53,15 +60,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
43 changes: 38 additions & 5 deletions Classes/Service/PackageKeyTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
use Neos\Flow\Annotations as Flow;
use Neos\Flow\Package\PackageManager;
use Neos\Flow\Package\PackageInterface;
use Neos\Neos\Domain\Repository\DomainRepository;

/**
* Utility trait to determine package keys
Expand All @@ -17,29 +18,61 @@ trait PackageKeyTrait
*/
protected $packageManager;

/**
* @Flow\Inject
* @var Neos\Neos\Domain\Repository\DomainRepository
*/
protected $domainRepository;

/**
* @Flow\InjectConfiguration("defaultPackageKey")
* @var string|null
*/
protected $defaultPackageKey;

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

/**
* Determine the default site package key
*
* @return string
*/
protected function getDefaultSitePackageKey()
{
try {
$domain = $this->domainRepository->findOneByActiveRequest();
if ($domain && $domain->getSite()) {
return $domain->getSite()->getSiteResourcesPackageKey();
}
} catch (\Exception $e) {
// ignore errors that may occur if no database is present
}

if ($this->defaultPackageKey) {
return $this->defaultPackageKey;
}

$sitePackageKeys = $this->getActiveSitePackageKeys();
return reset($sitePackageKeys);
}

/**
* 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));
}
}
2 changes: 2 additions & 0 deletions Configuration/Settings.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ Sitegeist:
fusion:
enableObjectTreeCache: true

defaultPackageKey: null

packages: { }

ui:
Expand Down
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 f03ac3e

Please sign in to comment.