Skip to content

Commit

Permalink
Merge branch 'release/v0.18.13'
Browse files Browse the repository at this point in the history
  • Loading branch information
betterthanclay committed Apr 29, 2024
2 parents 63049e4 + b39d58c commit 2393326
Show file tree
Hide file tree
Showing 35 changed files with 2,473 additions and 229 deletions.
8 changes: 8 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,11 @@ indent_size = 2

[*.md]
trim_trailing_whitespace = false

[src/Glitch/Renderer/assets/**]
generated_code = true
end_of_line = unset
insert_final_newline = unset
trim_trailing_whitespace = unset
indent_style = unset
indent_size = unset
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ phpstan.neon export-ignore
phpunit.xml.dist export-ignore
docs/ export-ignore
tests/ export-ignore
zest/ export-ignore
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,6 @@ composer.lock
Thumbs.db
/phpunit.xml
/.idea
node_modules

effigy.json
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
## v0.18.13 (2024-04-29)
* Converted theme to Vite

## v0.18.12 (2024-04-29)
* Updated dependency list
* Fixed Veneer stubs in gitattributes
Expand Down
3 changes: 3 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
},
"require-dev": {
"decodelabs/phpstan-decodelabs": "^0.6.1",
"decodelabs/zest": "^0.2.15",

"symfony/var-dumper": "^5|^6",
"php-ds/php-ds": "~1.2"
Expand All @@ -39,5 +40,7 @@
"branch-alias": {
"dev-develop": "0.18.x-dev"
}
},
"repositories": {
}
}
2 changes: 1 addition & 1 deletion src/Glitch/Context.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@

class Context implements LoggerAwareInterface
{
public const VERSION = 'v0.18.12';
public const VERSION = 'v0.18.13';

protected float $startTime;
protected string $runMode = 'development';
Expand Down
152 changes: 65 additions & 87 deletions src/Glitch/Renderer/Html.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
use DecodeLabs\Glitch\Stack\Frame;
use DecodeLabs\Glitch\Stack\Trace;
use DecodeLabs\Glitch\Stat;
use DecodeLabs\Zest\Manifest;

use Throwable;

Expand All @@ -44,8 +45,6 @@ class Html implements Renderer

public const RENDER_STACK = true;

public const DEV = false;

public const HTTP_STATUSES = [
100 => 'Continue',
101 => 'Switching Protocols',
Expand Down Expand Up @@ -209,44 +208,75 @@ protected function renderHeader(

// Meta
$output[] = '<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">';
$css = $js = [];

// Zest
if (
class_exists(Manifest::class) &&
file_exists(__DIR__ . '/assets/.vite/manifest.json.php')
) {
$manifest = Manifest::load(__DIR__ . '/assets/.vite/manifest.json');

// Css
$sassCss = $vendor . '/decodelabs/glitch/src/Glitch/Renderer/assets/glitch.css';
$this->buildScss($sassCss);
foreach ($manifest->getCssData() as $file => $attrs) {
$css[$file] = $attrs;
}

foreach ($manifest->getHeadJsData() as $file => $attrs) {
$js[$file] = $attrs;
}

$css = [
'glitch' => $sassCss
];
foreach ($manifest->getBodyJsData() as $file => $attrs) {
$js[$file] = $attrs;
}
} else {
$css[__DIR__ . '/assets/style.css'] = [
'id' => 'style-glitch'
];

$js[__DIR__ . '/assets/main.js'] = [
'id' => 'script-glitch',
'type' => 'module'
];

//$css['glitch'] = $vendor . '/decodelabs/glitch/src/Glitch/Renderer/assets/style.css';
}


// Css
if (isset($this->customCssFile)) {
$css['custom'] = $this->customCssFile;
$css[$this->customCssFile] = [
'id' => 'style-custom'
];
}

foreach ($css as $name => $cssPath) {
foreach ($css as $cssPath => $attrs) {
if (file_exists($cssPath)) {
$output[] = '<style id="style-' . $name . '">';
$output[] = '<style' . $this->prepareAttrs($attrs) . '>';
$output[] = file_get_contents($cssPath);
$output[] = '</style>';
} elseif (
str_starts_with($cssPath, 'http://') ||
str_starts_with($cssPath, 'https://')
) {
$output[] = '<link rel="stylesheet" href="' . $cssPath . '"' . $this->prepareAttrs($attrs) . ' />';
}
}

// Js
if ($this->shouldRender()) {
$js = [
'jQuery' => $vendor . '/components/jquery/jquery.min.js',
'glitch' => __DIR__ . '/assets/glitch.js'
];

foreach ($js as $name => $jsPath) {
if (file_exists($jsPath)) {
$output[] = '<script id="script-' . $name . '">';
$output[] = file_get_contents($jsPath);
$output[] = '</script>';
}
//if ($this->shouldRender()) {
foreach ($js as $jsPath => $attrs) {
if (file_exists($jsPath)) {
$output[] = '<script' . $this->prepareAttrs($attrs) . '>';
$output[] = file_get_contents($jsPath);
$output[] = '</script>';
} elseif (
str_starts_with($jsPath, 'http://') ||
str_starts_with($jsPath, 'https://')
) {
$output[] = '<script src="' . $jsPath . '"' . $this->prepareAttrs($attrs) . '></script>';
}
}
//}


$output[] = '</head>';
Expand All @@ -257,78 +287,26 @@ protected function renderHeader(
}

/**
* Build scss files
* @param array<string, mixed> $attrs
* @return string
*/
protected function buildScss(
string $cssPath
): void {
$vendor = $this->context->getVendorPath();
$isDev = is_link($vendor . '/decodelabs/glitch');

if (!static::DEV || !$isDev) {
return;
}


$enlightenPath = $vendor . '/decodelabs/enlighten/src/resources/styles.css';
$_sourcePath = $vendor . '/decodelabs/glitch/src/Glitch/Renderer/assets/scss/auto/_source.scss';
file_put_contents($_sourcePath, file_get_contents($enlightenPath));



$scssPath = substr($cssPath, 0, -3) . 'scss';
protected function prepareAttrs(
array $attrs
): string {
$output = [];

if (!file_exists($scssPath)) {
return;
foreach ($attrs as $key => $value) {
$output[] = $key . '="' . $value . '"';
}

$build = false;

if (file_exists($cssPath)) {
$cssTime = filemtime($cssPath);
$scssTime = filemtime($scssPath);

if ($scssTime > $cssTime) {
$build = true;
}
} else {
$cssTime = 0;
$build = true;
if (!empty($output)) {
return ' ' . implode(' ', $output);
}

if (!$build) {
if (false === ($test = scandir(__DIR__ . '/assets/scss/'))) {
$test = [];
}

foreach ($test as $testFileName) {
if ($testFileName === '.' || $testFileName === '..') {
continue;
}

$testFilePath = __DIR__ . '/assets/scss/' . $testFileName;

if (is_file($testFilePath)) {
$scssTime = filemtime($testFilePath);

if ($scssTime > $cssTime) {
$build = true;
break;
}
}
}
}


if ($build) {
exec('cd ' . $vendor . '; sassc --style=compressed ' . $scssPath . ' ' . $cssPath . ' 2>&1', $execOut);

if (!empty($execOut)) {
die('<pre>' . print_r($execOut, true));
}
}
return '';
}


/**
* Render exception message
*/
Expand Down
1 change: 0 additions & 1 deletion src/Glitch/Renderer/assets/glitch.css

This file was deleted.

105 changes: 0 additions & 105 deletions src/Glitch/Renderer/assets/glitch.js

This file was deleted.

21 changes: 0 additions & 21 deletions src/Glitch/Renderer/assets/glitch.scss

This file was deleted.

13 changes: 13 additions & 0 deletions src/Glitch/Renderer/assets/main.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions src/Glitch/Renderer/assets/style.css

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions zest/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
.sass-cache
node_modules
Loading

0 comments on commit 2393326

Please sign in to comment.