Alexander Demidov (Vostro)
3 years ago
8 changed files with 149 additions and 6 deletions
-
22Plugin.php
-
6classes/AssetsManifestException.php
-
14classes/ManifestReader.php
-
15classes/TwigFilters.php
-
59components/Manifest.php
-
3components/manifest/default.htm
-
18lang/en/lang.php
-
18lang/ru/lang.php
@ -0,0 +1,6 @@ |
|||
<?php namespace Wpstudio\AssetsManifest\Classes; |
|||
|
|||
class AssetsManifestException extends \ErrorException |
|||
{ |
|||
|
|||
} |
@ -0,0 +1,15 @@ |
|||
<?php namespace Wpstudio\AssetsManifest\Classes; |
|||
|
|||
use Wpstudio\Assetsmanifest\Components\Manifest; |
|||
|
|||
class TwigFilters |
|||
{ |
|||
public static function manifest($assetName): string |
|||
{ |
|||
$manifest = app()->get(Manifest::class); |
|||
|
|||
assert($manifest instanceof Manifest); |
|||
|
|||
return $manifest->getManifestReader()->get($assetName); |
|||
} |
|||
} |
@ -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; |
|||
} |
|||
} |
@ -0,0 +1,3 @@ |
|||
<p>This is the default markup for component manifest</p> |
|||
|
|||
<small>You can delete this file if you want</small> |
@ -0,0 +1,18 @@ |
|||
<?php |
|||
|
|||
return [ |
|||
'components' => [ |
|||
'manifest' => [ |
|||
'name' => 'Manifest path', |
|||
'description' => 'Accept manifest.json path', |
|||
'properties' => [ |
|||
'path' => [ |
|||
'title' => 'Manifest relative basepath', |
|||
'description' => |
|||
'manifest.json path relative from basepath. Example: themes/demo/assets/build/manifest.json', |
|||
'validationMessage' => 'Incorrect manifest.json path', |
|||
] |
|||
] |
|||
] |
|||
] |
|||
]; |
@ -0,0 +1,18 @@ |
|||
<?php |
|||
|
|||
return [ |
|||
'components' => [ |
|||
'manifest' => [ |
|||
'name' => 'Manifest path', |
|||
'description' => 'Устанавливает путь к manifest.json', |
|||
'properties' => [ |
|||
'path' => [ |
|||
'title' => 'Manifest относительно корня', |
|||
'description' => |
|||
'Путь к файлу manifest.json относительно корня проекта. Например: themes/demo/assets/build/manifest.json', |
|||
'validationMessage' => 'Неправильный формат пути к файлу manifest.json', |
|||
] |
|||
] |
|||
] |
|||
] |
|||
]; |
Write
Preview
Loading…
Cancel
Save
Reference in new issue