Files
fewo-stommer/app/Console/Commands/MakeTheme.php
Lars StommerandClaude Opus 5.5 7d0bc93abc Offers by their own rules, seasonal photos per section, theme authoring tooling
- Special offers: kinds (rule, fixed dates, gap filler), package price, priority, highlight;
  GapFinder detects calendar gaps (optionally waiving the minimum stay); OfferShowcase decides
  what the website advertises and prices fixed dates/gaps with PriceCalculator; offers section
  shows them side by side, as a list or rotating; hero can show the top offer. Appearances no
  longer carry a featured offer.
- Sections get stable ids; appearances set photos per section ("Bilder je Baustein") and
  sections can be limited to appearances. Photo pickers show thumbnails everywhere.
- Themes: themes:make (scaffold, never overwrites), themes:check (contract, build, markup,
  colours, external resources, WCAG contrast), themes:preview (signed links per page and
  appearance), signed ?theme= preview and preview action in the site form, inherited colour
  tokens in the admin. Base CSS split into theme.css + reusable theme-base.css.
- docs/THEME-ERSTELLUNG.md: binding guide for building additional themes elsewhere.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-22 18:51:38 +02:00

144 lines
5.8 KiB
PHP
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<?php
namespace App\Console\Commands;
use App\Themes\ThemeManifest;
use App\Themes\ThemeRegistry;
use Illuminate\Console\Attributes\Description;
use Illuminate\Console\Attributes\Signature;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\File;
#[Signature('themes:make {key : Ordner/Key, z. B. ostsee-nacht} {--name= : Anzeigename} {--parent= : Eltern-Theme (Standard: Basis-Theme)} {--description= : Beschreibung für die Theme-Auswahl}')]
#[Description('Create a new theme next to the existing ones (never overwrites) – inherits everything until views are added')]
class MakeTheme extends Command
{
/**
* Execute the console command.
*/
public function handle(ThemeRegistry $registry): int
{
$key = (string) $this->argument('key');
$parent = (string) ($this->option('parent') ?: config('themes.base'));
$themesPath = rtrim((string) (config('themes.paths')[0] ?? resource_path('themes')), '/\\');
$path = "{$themesPath}/{$key}";
$folder = str_replace('\\', '/', ltrim(substr($path, strlen(base_path())), '/\\'));
if (! preg_match('/^[a-z0-9]+(-[a-z0-9]+)*$/', $key)) {
$this->error('Key: nur Kleinbuchstaben, Ziffern und Bindestriche, z. B. ostsee-nacht.');
return self::FAILURE;
}
if (File::exists($path) || isset($registry->all()[$key])) {
$this->error("Theme „{$key}“ gibt es schon – es wird nichts überschrieben.");
return self::FAILURE;
}
if (! isset($registry->all()[$parent])) {
$this->error("Eltern-Theme „{$parent}“ ist nicht installiert.");
return self::FAILURE;
}
$name = (string) ($this->option('name') ?: str($key)->replace('-', ' ')->title());
$manifest = [
'key' => $key,
'name' => $name,
'version' => '0.1.0',
'parent' => $parent,
'description' => (string) ($this->option('description') ?: "Neues Theme auf Basis von „{$registry->get($parent)->name}“."),
'assets' => ['css' => "{$folder}/theme.css", 'js' => "{$folder}/theme.js"],
'tokens' => $registry->tokens($parent),
];
File::ensureDirectoryExists("{$path}/views/sections");
File::ensureDirectoryExists("{$path}/views/partials");
File::put("{$path}/views/sections/.gitkeep", '');
File::put("{$path}/views/partials/.gitkeep", '');
File::put("{$path}/theme.json", json_encode($manifest, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE)."\n");
File::put("{$path}/theme.css", $this->css($name, $parent, $path, $registry));
File::put("{$path}/theme.js", $this->js($name, ThemeManifest::relativePath($path, $registry->get($parent)->path).'/theme.js'));
File::put("{$path}/README.md", $this->readme($name, $key, $parent));
$this->info("Theme „{$name}“ angelegt: {$folder}");
$this->line('Es erbt zunächst alles von „'.$parent.'“. Vorlagen nach views/ kopieren und umgestalten – Anleitung: docs/THEME-ERSTELLUNG.md');
$this->line("Prüfen: php artisan themes:check {$key} · Bauen: npm run build · Auswählen: Admin › System › Websites › Theme (dort „Vorschau“).");
return self::SUCCESS;
}
/**
* Child theme CSS: Tailwind, the reusable styles of the nearest ancestor that has a theme-base.css,
* and the template sources of all ancestors, the booking forms and the theme itself.
*/
private function css(string $name, string $parent, string $path, ThemeRegistry $registry): string
{
$ancestors = $registry->chain($parent);
$base = collect($ancestors)->first(fn (ThemeManifest $theme): bool => is_file($theme->path.'/theme-base.css')) ?? $ancestors[0];
$import = ThemeManifest::relativePath($path, $base->path).'/theme-base.css';
$sources = collect($ancestors)
->map(fn (ThemeManifest $theme): string => "@source '".ThemeManifest::relativePath($path, $theme->viewsPath())."';")
->push("@source '".ThemeManifest::relativePath($path, resource_path('views/livewire'))."';")
->push("@source './views';")
->implode("\n");
return <<<CSS
/*
* Theme „{$name}“ – Child von „{$parent}“ (Anleitung: docs/THEME-ERSTELLUNG.md).
* theme-base.css des Eltern-Themes bringt Schriften, Token-Mapping und Basis-Klassen (.eyebrow,
* .heading-display, .btn-primary, .btn-accent, .prose-theme, .reveal). Hier nur Abweichungen ergänzen.
*/
@import 'tailwindcss';
@import '{$import}';
/* Eigene Schriften selbst hosten: npm install @fontsource/<schrift> und hier importieren, z. B.
@import '@fontsource/fraunces/400.css';
*/
/* Vorlagen, deren Klassen gebaut werden: geerbte, Buchungsformulare, eigene. */
{$sources}
@theme inline {
/* --font-display: 'Fraunces', Georgia, serif; */
/* --font-sans: 'Inter', ui-sans-serif, system-ui, sans-serif; */
}
@layer components {
}
CSS;
}
private function js(string $name, string $import): string
{
return <<<JS
/**
* Theme „{$name}“: übernimmt Lightbox, Verfügbarkeitssuche und rollierende Angebote vom Eltern-Theme.
* Eigene Verbesserungen darunter – alles muss auch ohne JavaScript funktionieren.
*/
import '{$import}';
JS;
}
private function readme(string $name, string $key, string $parent): string
{
return <<<MD
# Theme „{$name}“ (`{$key}`)
Child-Theme von `{$parent}`. Vorlagen, die hier fehlen, kommen vom Eltern-Theme.
- Anleitung und Vorlagen-Vertrag: `docs/THEME-ERSTELLUNG.md`, `docs/THEMES.md` §5
- Prüfen: `php artisan themes:check {$key}`
- Ansehen ohne Umschalten: Admin › System › Websites › Theme „{$name}“ wählen › „Vorschau“ (erst danach speichern)
## Eigene Vorlagen
| Datei | Zweck |
|---|---|
| | |
MD;
}
}