Skip to content

Commit 60ac244

Browse files
Merge pull request #71 from minhkhoablieu/feat/add-screenshot
Add screenshot
2 parents 36d0a21 + 3ed6eb8 commit 60ac244

File tree

6 files changed

+49
-3
lines changed

6 files changed

+49
-3
lines changed

resources/stubs/_folder-structure/composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@
1313
"extra": {
1414
"theme": {
1515
"parent": "DummyParent",
16-
"active": true
16+
"active": true,
17+
"screenshot": "DummyScreenshot"
1718
}
1819
}
1920
}
Loading

src/Console/Commands/ListThemes.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ class ListThemes extends Command
2222
/**
2323
* The table headers for the command.
2424
*/
25-
protected $headers = ['Name', 'Vendor', 'Version', 'Description', 'Extends', 'Default', 'Active'];
25+
protected $headers = ['Name', 'Vendor', 'Version', 'Description', 'Screenshot', 'Extends', 'Default', 'Active'];
2626

2727
/**
2828
* List of existing themes.
@@ -42,6 +42,7 @@ public function handle(): void
4242
'vendor' => $theme->getVendor(),
4343
'version' => $theme->getVersion(),
4444
'description' => $theme->getDescription(),
45+
'screenshot' => $theme->getScreenshotName(),
4546
'extends' => $theme->getParent() ? $theme->getParent()->getName() : '',
4647
'default' => $theme->getName() === config('themes-manager.fallback_theme') ? 'X' : '',
4748
];

src/Console/Generators/MakeTheme.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ protected function replacePlaceholders(\Symfony\Component\Finder\SplFileInfo $fi
132132
'DummyParent',
133133
'DummyVendor',
134134
'DummyVersion',
135+
'DummyScreenshot',
135136
];
136137

137138
$replace = [
@@ -142,6 +143,7 @@ protected function replacePlaceholders(\Symfony\Component\Finder\SplFileInfo $fi
142143
Arr::get($this->theme, 'parent', ''),
143144
Arr::get($this->theme, 'vendor', ''),
144145
Arr::get($this->theme, 'version', '1.0'),
146+
Arr::get($this->theme, 'screenshot', 'screenshot.png'),
145147
];
146148

147149
return str_replace($find, $replace, $file->getContents());

src/Theme.php

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
use Illuminate\Support\Facades\URL;
1818
use Illuminate\Support\Facades\View;
1919
use Illuminate\Support\Str;
20+
use Illuminate\Support\Facades\File;
2021

2122
final class Theme
2223
{
@@ -53,6 +54,12 @@ final class Theme
5354
*/
5455
protected string|Theme|null $parent = null;
5556

57+
/**
58+
* The theme screenshot.
59+
*/
60+
61+
protected string $screenshot = "";
62+
5663
/**
5764
* The theme statud (enabled or not).
5865
*/
@@ -219,6 +226,40 @@ public function getParent(): ?Theme
219226
return $this->parent;
220227
}
221228

229+
230+
/**
231+
* Set theme screenshot.
232+
*/
233+
234+
public function setScreenshot(string $screenshot): self
235+
{
236+
237+
$this->screenshot = $screenshot;
238+
239+
return $this;
240+
}
241+
242+
public function getScreenshotName(): string|null
243+
{
244+
return $this->screenshot;
245+
}
246+
247+
public function getScreenshotImageUrl(): string
248+
{
249+
return $this->url($this->screenshot);
250+
}
251+
252+
public function getScreenshotImageBase64(): string|null
253+
{
254+
$screenshotImage = $this->getAssetsPath($this->screenshot);
255+
256+
if (!is_file($screenshotImage)) {
257+
return null;
258+
}
259+
260+
return 'data:image/png;base64,' . base64_encode(File::get($screenshotImage));
261+
}
262+
222263
/**
223264
* Determine whether the current theme activated.
224265
*/

src/ThemeFinder.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,8 @@ function ($themePackage) use ($themes): void {
4141
->setVersion($info->get('version', '0.1'))
4242
->setDescription($info->get('description', ''))
4343
->setParent($info->get('extra.theme.parent'))
44-
->setExtra($info->get('extra.theme', []));
44+
->setExtra($info->get('extra.theme', []))
45+
->setScreenshot($info->get('extra.theme.screenshot', ''));
4546

4647
$themes->put($info->get('name'), $theme);
4748
}

0 commit comments

Comments
 (0)