Skip to content

Commit

Permalink
Merge pull request #61 from hexadog/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
gaetan-hexadog authored Apr 25, 2023
2 parents cd7d4fa + 2dff43d commit a456e7d
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 44 deletions.
2 changes: 2 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
],
"minimum-stability": "stable",
"require": {
"php": ">=7.4",
"ext-json": "*",
"hexadog/laravel-theme-installer": "^1.0",
"illuminate/view": "^7.0|^8.0|^9.0|^10.0"
},
Expand Down
3 changes: 2 additions & 1 deletion src/Helpers/Json.php
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,8 @@ public function save(): bool
/**
* Get the specified attribute from json file.
*
* @param null $default
* @param null $default
* @param mixed $key
*
* @return mixed
*/
Expand Down
43 changes: 0 additions & 43 deletions src/Theme.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,27 +99,6 @@ public function getAssetsPath(string $path = null): string
return Config::get('themes-manager.symlink_path', 'themes') . '/' . mb_strtolower($this->vendor) . '/' . mb_strtolower($this->name) . ($path ? '/' . $path : '');
}

/**
* Get theme views paths.
* Build Paths array.
* All paths are relative to Config::get('themes-manager.directory').
*/
public function getViewPaths(string $path = ''): array
{
$paths = [];
$theme = $this;

do {
$viewsPath = $theme->getPath('resources/views' . ($path ? "/{$path}" : ''));

if (!in_array($viewsPath, $paths)) {
$paths[] = $viewsPath;
}
} while ($theme = $theme->getParent());

return array_reverse($paths);
}

/**
* Set extra data.
*/
Expand Down Expand Up @@ -356,28 +335,6 @@ public function url(string $url, bool $absolute = true): string
return ltrim(str_replace('\\', '/', $url));
}

/**
* List theme's available layouts.
*
* @return \Illuminate\Support\Collection
*/
public function listLayouts()
{
$layouts = collect();

$layoutDirs = $this->getViewPaths('layouts');

foreach ($layoutDirs as $layoutDir) {
if ($layoutFiles = glob($layoutDir . '/{**/*,*}.php', GLOB_BRACE)) {
foreach ($layoutFiles as $layout) {
$layouts->put($layout, basename($layout, '.blade.php'));
}
}
}

return $layouts;
}

/**
* Create public assets directory path.
*/
Expand Down
43 changes: 43 additions & 0 deletions src/Traits/HasViews.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,49 @@

trait HasViews
{
/**
* Get theme views paths.
* Build Paths array.
* All paths are relative to Config::get('themes-manager.directory').
*/
public function getViewPaths(string $path = ''): array
{
$paths = [];
$theme = $this;

do {
$viewsPath = $theme->getPath('resources/views' . ($path ? "/{$path}" : ''));

if (!in_array($viewsPath, $paths)) {
$paths[] = $viewsPath;
}
} while ($theme = $theme->getParent());

return $paths;
}

/**
* List theme's available layouts.
*
* @return \Illuminate\Support\Collection
*/
public function listLayouts()
{
$layouts = collect();

$layoutDirs = $this->getViewPaths('layouts');

foreach ($layoutDirs as $layoutDir) {
if ($layoutFiles = glob($layoutDir . '/{**/*,*}.php', GLOB_BRACE)) {
foreach ($layoutFiles as $layout) {
$layouts->put($layout, basename($layout, '.blade.php'));
}
}
}

return $layouts;
}

/**
* Register theme's views in ViewFinder.
*/
Expand Down

0 comments on commit a456e7d

Please sign in to comment.