+ component & twig function/filter for inject assets from manifest.json
This commit is contained in:
59
components/Manifest.php
Normal file
59
components/Manifest.php
Normal file
@ -0,0 +1,59 @@
|
||||
<?php namespace Wpstudio\Assetsmanifest\Components;
|
||||
|
||||
use Cms\Classes\ComponentBase;
|
||||
use Wpstudio\AssetsManifest\Classes\ManifestReader;
|
||||
|
||||
class Manifest extends ComponentBase
|
||||
{
|
||||
const LANG_PREFIX = 'wpstudio.assetsmanifest::lang.components.manifest.';
|
||||
|
||||
private ?ManifestReader $manifestReader;
|
||||
|
||||
public function componentDetails(): array
|
||||
{
|
||||
return [
|
||||
'name' => self::LANG_PREFIX . 'name',
|
||||
'description' => self::LANG_PREFIX . 'description',
|
||||
];
|
||||
}
|
||||
|
||||
public function defineProperties(): array
|
||||
{
|
||||
return [
|
||||
'path' => [
|
||||
'title' => self::LANG_PREFIX . 'properties.path.title',
|
||||
'description' => self::LANG_PREFIX . 'properties.path.description',
|
||||
'validationPattern' => '^[^/].*/manifest.json',
|
||||
'validationMessage' => self::LANG_PREFIX . 'properties.path.validationMessage',
|
||||
'placeholder' => 'assets/build/manifest.json',
|
||||
'showExternalParam' => false,
|
||||
'required' => true,
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
* @throws \Wpstudio\AssetsManifest\Classes\AssetsManifestException
|
||||
*/
|
||||
public function init(): void
|
||||
{
|
||||
app()->instance(Manifest::class, $this);
|
||||
|
||||
$this->prepareVars();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
* @throws \Wpstudio\AssetsManifest\Classes\AssetsManifestException
|
||||
*/
|
||||
private function prepareVars(): void
|
||||
{
|
||||
$this->manifestReader = new ManifestReader(base_path($this->property('path')));
|
||||
}
|
||||
|
||||
public function getManifestReader(): ManifestReader
|
||||
{
|
||||
return $this->manifestReader;
|
||||
}
|
||||
}
|
3
components/manifest/default.htm
Normal file
3
components/manifest/default.htm
Normal file
@ -0,0 +1,3 @@
|
||||
<p>This is the default markup for component manifest</p>
|
||||
|
||||
<small>You can delete this file if you want</small>
|
Reference in New Issue
Block a user