MAPG-187 refactor view parsing and linking
This commit is contained in:
parent
71b1e28aa9
commit
e883d184b7
@ -108,7 +108,7 @@ class Linker
|
|||||||
private function generateAssets(ParsedFragment $fragment, array &$sections)
|
private function generateAssets(ParsedFragment $fragment, array &$sections)
|
||||||
{
|
{
|
||||||
foreach ($fragment->getCss() as $cssFile) {
|
foreach ($fragment->getCss() as $cssFile) {
|
||||||
$asset = $this->parseAsset($cssFile, 'css');
|
$asset = $this->parseAsset($cssFile);
|
||||||
if (isset($asset['code'])) {
|
if (isset($asset['code'])) {
|
||||||
$sections['inlineCss'] .= '<style>' . PHP_EOL;
|
$sections['inlineCss'] .= '<style>' . PHP_EOL;
|
||||||
$sections['inlineCss'] .= $asset['code'];
|
$sections['inlineCss'] .= $asset['code'];
|
||||||
@ -119,7 +119,7 @@ class Linker
|
|||||||
}
|
}
|
||||||
|
|
||||||
foreach ($fragment->getJs() as $jsFile) {
|
foreach ($fragment->getJs() as $jsFile) {
|
||||||
$asset = $this->parseAsset($jsFile, 'js');
|
$asset = $this->parseAsset($jsFile);
|
||||||
if (isset($asset['code'])) {
|
if (isset($asset['code'])) {
|
||||||
$sections['inlineJs'] .= '<script>' . PHP_EOL;
|
$sections['inlineJs'] .= '<script>' . PHP_EOL;
|
||||||
$sections['inlineJs'] .= $asset['code'];
|
$sections['inlineJs'] .= $asset['code'];
|
||||||
@ -130,24 +130,21 @@ class Linker
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private function parseAsset(string $asset, string $type): array
|
private function parseAsset(string $asset): array
|
||||||
{
|
{
|
||||||
$output = [];
|
$output = [];
|
||||||
|
|
||||||
eval('$asset = ' . $asset . ';');
|
if (preg_match('/^[\w\/\.]+$/', $asset)) {
|
||||||
|
if (
|
||||||
if (
|
empty($_ENV['DEV']) &&
|
||||||
empty($_ENV['DEV']) &&
|
filesize(ROOT . '/public/static/' . $asset) < self::INLINE_ASSET_LIMIT
|
||||||
preg_match('/^' . $type . '\/.*/', $asset) &&
|
) {
|
||||||
filesize(ROOT . '/public/static/' . $asset) < self::INLINE_ASSET_LIMIT
|
$output['code'] = file_get_contents(ROOT . '/public/static/' . $asset);
|
||||||
) {
|
|
||||||
$output['code'] = file_get_contents(ROOT . '/public/static/' . $asset);
|
|
||||||
} else {
|
|
||||||
if (!preg_match('/^http(s)?/', $asset)) {
|
|
||||||
$output['file'] = $_ENV['STATIC_ROOT'] . '/' . $asset . '?rev=<?= REVISION ?>';
|
|
||||||
} else {
|
} else {
|
||||||
$output['file'] = $asset;
|
$output['file'] = '<?= $_ENV[\'STATIC_ROOT\'] ?>/' . $asset . '?rev=<?= REVISION ?>';
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
$output['file'] = $asset;
|
||||||
}
|
}
|
||||||
|
|
||||||
return $output;
|
return $output;
|
||||||
|
@ -126,7 +126,7 @@ class Parser
|
|||||||
|
|
||||||
private function matchExtends(string $line): ?string
|
private function matchExtends(string $line): ?string
|
||||||
{
|
{
|
||||||
if (preg_match('/^\s*@extends\(\'([\w\/]+)\'\)\s*$/', $line, $matches)) {
|
if (preg_match('/^\s*@extends\(([\w\/]+)\)\s*$/', $line, $matches)) {
|
||||||
return $matches[1];
|
return $matches[1];
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -135,7 +135,7 @@ class Parser
|
|||||||
|
|
||||||
private function matchSection(string $line): ?string
|
private function matchSection(string $line): ?string
|
||||||
{
|
{
|
||||||
if (preg_match('/^\s*@section\(\'(\w+)\'\)\s*$/', $line, $matches)) {
|
if (preg_match('/^\s*@section\((\w+)\)\s*$/', $line, $matches)) {
|
||||||
return $matches[1];
|
return $matches[1];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user