diff --git a/resources/stubs/_folder-structure/composer.json b/resources/stubs/_folder-structure/composer.json index 73b41fc..ad3f2d5 100644 --- a/resources/stubs/_folder-structure/composer.json +++ b/resources/stubs/_folder-structure/composer.json @@ -13,7 +13,8 @@ "extra": { "theme": { "parent": "DummyParent", - "active": true + "active": true, + "screenshot": "DummyScreenshot" } } } diff --git a/resources/stubs/_folder-structure/public/screenshot.png b/resources/stubs/_folder-structure/public/screenshot.png new file mode 100644 index 0000000..a64bf6e Binary files /dev/null and b/resources/stubs/_folder-structure/public/screenshot.png differ diff --git a/src/Console/Commands/ListThemes.php b/src/Console/Commands/ListThemes.php index ca8477a..c5ca5b5 100644 --- a/src/Console/Commands/ListThemes.php +++ b/src/Console/Commands/ListThemes.php @@ -22,7 +22,7 @@ class ListThemes extends Command /** * The table headers for the command. */ - protected $headers = ['Name', 'Vendor', 'Version', 'Description', 'Extends', 'Default', 'Active']; + protected $headers = ['Name', 'Vendor', 'Version', 'Description', 'Screenshot', 'Extends', 'Default', 'Active']; /** * List of existing themes. @@ -42,6 +42,7 @@ public function handle(): void 'vendor' => $theme->getVendor(), 'version' => $theme->getVersion(), 'description' => $theme->getDescription(), + 'screenshot' => $theme->getScreenshotName(), 'extends' => $theme->getParent() ? $theme->getParent()->getName() : '', 'default' => $theme->getName() === config('themes-manager.fallback_theme') ? 'X' : '', ]; diff --git a/src/Console/Generators/MakeTheme.php b/src/Console/Generators/MakeTheme.php index c6ddd15..fa5e859 100644 --- a/src/Console/Generators/MakeTheme.php +++ b/src/Console/Generators/MakeTheme.php @@ -132,6 +132,7 @@ protected function replacePlaceholders(\Symfony\Component\Finder\SplFileInfo $fi 'DummyParent', 'DummyVendor', 'DummyVersion', + 'DummyScreenshot', ]; $replace = [ @@ -142,6 +143,7 @@ protected function replacePlaceholders(\Symfony\Component\Finder\SplFileInfo $fi Arr::get($this->theme, 'parent', ''), Arr::get($this->theme, 'vendor', ''), Arr::get($this->theme, 'version', '1.0'), + Arr::get($this->theme, 'screenshot', 'screenshot.png'), ]; return str_replace($find, $replace, $file->getContents()); diff --git a/src/Theme.php b/src/Theme.php index a1075fc..99b8525 100644 --- a/src/Theme.php +++ b/src/Theme.php @@ -17,6 +17,7 @@ use Illuminate\Support\Facades\URL; use Illuminate\Support\Facades\View; use Illuminate\Support\Str; +use Illuminate\Support\Facades\File; final class Theme { @@ -53,6 +54,12 @@ final class Theme */ protected string|Theme|null $parent = null; + /** + * The theme screenshot. + */ + + protected string $screenshot = ""; + /** * The theme statud (enabled or not). */ @@ -219,6 +226,40 @@ public function getParent(): ?Theme return $this->parent; } + + /** + * Set theme screenshot. + */ + + public function setScreenshot(string $screenshot): self + { + + $this->screenshot = $screenshot; + + return $this; + } + + public function getScreenshotName(): string|null + { + return $this->screenshot; + } + + public function getScreenshotImageUrl(): string + { + return $this->url($this->screenshot); + } + + public function getScreenshotImageBase64(): string|null + { + $screenshotImage = $this->getAssetsPath($this->screenshot); + + if (!is_file($screenshotImage)) { + return null; + } + + return 'data:image/png;base64,' . base64_encode(File::get($screenshotImage)); + } + /** * Determine whether the current theme activated. */ diff --git a/src/ThemeFinder.php b/src/ThemeFinder.php index fe9f5cf..ba628d2 100644 --- a/src/ThemeFinder.php +++ b/src/ThemeFinder.php @@ -41,7 +41,8 @@ function ($themePackage) use ($themes): void { ->setVersion($info->get('version', '0.1')) ->setDescription($info->get('description', '')) ->setParent($info->get('extra.theme.parent')) - ->setExtra($info->get('extra.theme', [])); + ->setExtra($info->get('extra.theme', [])) + ->setScreenshot($info->get('extra.theme.screenshot', '')); $themes->put($info->get('name'), $theme); }