Skip to content

Commit

Permalink
Merge pull request #71 from minhkhoablieu/feat/add-screenshot
Browse files Browse the repository at this point in the history
Add screenshot
  • Loading branch information
gaetan-hexadog authored Oct 23, 2023
2 parents 36d0a21 + 3ed6eb8 commit 60ac244
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 3 deletions.
3 changes: 2 additions & 1 deletion resources/stubs/_folder-structure/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
"extra": {
"theme": {
"parent": "DummyParent",
"active": true
"active": true,
"screenshot": "DummyScreenshot"
}
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 2 additions & 1 deletion src/Console/Commands/ListThemes.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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' : '',
];
Expand Down
2 changes: 2 additions & 0 deletions src/Console/Generators/MakeTheme.php
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ protected function replacePlaceholders(\Symfony\Component\Finder\SplFileInfo $fi
'DummyParent',
'DummyVendor',
'DummyVersion',
'DummyScreenshot',
];

$replace = [
Expand All @@ -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());
Expand Down
41 changes: 41 additions & 0 deletions src/Theme.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -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).
*/
Expand Down Expand Up @@ -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.
*/
Expand Down
3 changes: 2 additions & 1 deletion src/ThemeFinder.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down

0 comments on commit 60ac244

Please sign in to comment.