mirror of
https://codeberg.org/vegvisir/website.git
synced 2025-09-14 00:43:42 +02:00
57 lines
No EOL
1.3 KiB
PHP
57 lines
No EOL
1.3 KiB
PHP
<?php
|
|
|
|
use const VVWebsite\ICONS_DIR;
|
|
|
|
require_once VV::root("src/Consts.php");
|
|
|
|
$HTMLCodeDemoElement = new class {
|
|
public bool $valid = false;
|
|
|
|
public readonly array $files;
|
|
private readonly string $dir;
|
|
private readonly string $namespace;
|
|
|
|
public function __construct() {
|
|
$this->namespace = array_key_exists("id", $_GET) ? $_GET["id"] : null;
|
|
|
|
if ($this->namespace) {
|
|
$this->dir = "snippets/HTMLCodeDemoElement/{$this->namespace}/";
|
|
|
|
if (is_dir(VV::root($this->dir))) {
|
|
// Strip "." and ".."
|
|
$this->files = array_filter(scandir(VV::root($this->dir)), function (string $item) {
|
|
return substr($item, 0, 1) !== ".";
|
|
});
|
|
|
|
$this->valid = true;
|
|
}
|
|
}
|
|
}
|
|
|
|
public function file_path(string $file): string {
|
|
return $this->dir . $file;
|
|
}
|
|
}
|
|
|
|
?>
|
|
<code-demo>
|
|
<div class="header">
|
|
<?php foreach ($HTMLCodeDemoElement->files as $file): ?>
|
|
<button class="inline">
|
|
<?= VV::embed(ICONS_DIR . "languages/" . $file) ?>
|
|
<p><?= substr($file, 0, strlen($file) - 4) ?></p>
|
|
</button>
|
|
<?php endforeach; ?>
|
|
|
|
</div>
|
|
<div class="body">
|
|
|
|
<?php foreach ($HTMLCodeDemoElement->files as $file): ?>
|
|
<div>
|
|
<?= VV::include($HTMLCodeDemoElement->file_path($file)) ?>
|
|
</div>
|
|
<?php endforeach; ?>
|
|
|
|
</div>
|
|
</code-demo>
|
|
<script type="module" src="/assets/js/elements/HTMLCodeDemoElement.mjs"></script>
|