Skip to content

Commit 69f26b3

Browse files
Merge pull request #19 from hexadog/develop
Fix vendor views and assets path
2 parents 93280a4 + c8e8c89 commit 69f26b3

File tree

4 files changed

+93
-70
lines changed

4 files changed

+93
-70
lines changed

helpers/helpers.php

Lines changed: 33 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -3,46 +3,46 @@
33
use Illuminate\Support\Facades\View;
44

55
if (!function_exists('page_title')) {
6-
/**
7-
* Get formatted page title
8-
*
9-
* @param bool $with_app_name
10-
* @param string $separator
11-
* @return string
12-
*/
13-
function page_title(string $title, bool $withAppName = true, $separator = '-', $invert = false): string
14-
{
15-
if (View::hasSection('title')) {
16-
$title = View::getSection('title');
17-
}
6+
/**
7+
* Get formatted page title
8+
*
9+
* @param bool $with_app_name
10+
* @param string $separator
11+
* @return string
12+
*/
13+
function page_title(string $title, bool $withAppName = true, $separator = '-', $invert = false): string
14+
{
15+
if (View::hasSection('title')) {
16+
$title = View::getSection('title');
17+
}
1818

19-
if (!empty($title) && $withAppName) {
19+
if (!empty($title) && $withAppName) {
2020
if ($invert) {
2121
return $title . " " . trim(e($separator)) . " " . config('app.name');
2222
} else {
2323
return config('app.name') . " " . trim(e($separator)) . " " . $title;
2424
}
25-
} else {
25+
} else {
2626
return config('app.name');
2727
}
28-
}
28+
}
2929
}
3030

3131
if (!function_exists('theme')) {
32-
/**
33-
* Set theme.
34-
*
35-
* @param string $themeName
36-
* @return \Hexadog\ThemesManager\Theme
37-
*/
38-
function theme($themeName = null)
39-
{
40-
if ($themeName) {
41-
\Theme::set($themeName);
42-
}
43-
44-
return \Theme::current();
45-
}
32+
/**
33+
* Set theme.
34+
*
35+
* @param string $themeName
36+
* @return \Hexadog\ThemesManager\Theme
37+
*/
38+
function theme($themeName = null)
39+
{
40+
if ($themeName) {
41+
\Theme::set($themeName);
42+
}
43+
44+
return \Theme::current();
45+
}
4646
}
4747

4848
if (!function_exists('theme_asset')) {
@@ -53,7 +53,7 @@ function theme($themeName = null)
5353
* @param bool $absolutePath
5454
* @return string
5555
*/
56-
function theme_asset(string $asset, $absolutePath = false)
56+
function theme_asset(string $asset, $absolutePath = true)
5757
{
5858
return \Theme::url($asset, $absolutePath);
5959
}
@@ -67,7 +67,7 @@ function theme_asset(string $asset, $absolutePath = false)
6767
* @param bool $absolutePath
6868
* @return string
6969
*/
70-
function theme_style(string $asset, $absolutePath = false)
70+
function theme_style(string $asset, $absolutePath = true)
7171
{
7272
return \Theme::style($asset, $absolutePath);
7373
}
@@ -84,7 +84,7 @@ function theme_style(string $asset, $absolutePath = false)
8484
* @param string $level
8585
* @return string
8686
*/
87-
function theme_script(string $asset, string $mode = '', $absolutePath = false, string $type = 'text/javascript', string $level = 'functionality')
87+
function theme_script(string $asset, string $mode = '', $absolutePath = true, string $type = 'text/javascript', string $level = 'functionality')
8888
{
8989
return \Theme::script($asset, $mode, $absolutePath, $type, $level);
9090
}
@@ -98,7 +98,7 @@ function theme_script(string $asset, string $mode = '', $absolutePath = false, s
9898
* @param string $asset
9999
* @return string
100100
*/
101-
function theme_image(string $asset, string $alt = '', string $class = '', array $attributes = [], $absolutePath = false)
101+
function theme_image(string $asset, string $alt = '', string $class = '', array $attributes = [], $absolutePath = true)
102102
{
103103
return \Theme::image($asset, $alt, $class, $attributes, $absolutePath);
104104
}

src/Console/Generators/MakeTheme.php

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ protected function validateName()
122122
}
123123
}
124124

125-
if (ThemesManager::has($this->theme['name'])) {
125+
if (ThemesManager::has("{$this->theme['vendor']}/{$this->theme['name']}")) {
126126
$this->error("Theme with name {$this->theme['vendor']}/{$this->theme['name']} already exists!");
127127

128128
return false;
@@ -173,7 +173,7 @@ private function generateTheme()
173173
* Replace placeholders in generated file.
174174
*
175175
* @param \Symfony\Component\Finder\SplFileInfo $file
176-
*
176+
*
177177
* @return string
178178
*/
179179
protected function replacePlaceholders($file)
@@ -233,15 +233,9 @@ protected function askDescription()
233233
*/
234234
protected function askName()
235235
{
236-
while (empty(Arr::get($this->theme, 'name', null))) {
236+
do {
237237
$this->theme['name'] = $this->ask('Theme Name');
238-
239-
if (ThemesManager::has($this->theme['name'])) {
240-
$this->error("Theme with name {$this->theme['name']} already exists!");
241-
242-
unset($this->theme['name']);
243-
}
244-
}
238+
} while (!strlen($this->theme['name']));
245239
}
246240

247241
/**
@@ -264,7 +258,9 @@ protected function askParent()
264258
*/
265259
protected function askVendor()
266260
{
267-
$this->theme['vendor'] = mb_strtolower($this->config->get('themes-manager.composer.vendor') ?? $this->ask('Vendor name'));
261+
do {
262+
$this->theme['vendor'] = mb_strtolower($this->config->get('themes-manager.composer.vendor') ?? $this->ask('Vendor name'));
263+
} while (!strlen($this->theme['vendor']));
268264
}
269265

270266
/**
@@ -273,5 +269,9 @@ protected function askVendor()
273269
protected function askVersion()
274270
{
275271
$this->theme['version'] = $this->ask('Version number');
272+
273+
if (!strlen($this->theme['version'])) {
274+
$this->theme['version'] = null;
275+
}
276276
}
277277
}

src/Theme.php

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -390,19 +390,27 @@ protected function registerViews()
390390
$directories = scandir($vendorViewsPath);
391391
foreach ($directories as $namespace) {
392392
if ($namespace != '.' && $namespace != '..') {
393-
$path = "{$vendorViewsPath}{$namespace}";
394-
395393
if (!empty(Config::get('view.paths')) && is_array(Config::get('view.paths'))) {
396394
foreach (Config::get('view.paths') as $viewPath) {
397395
if (is_dir($appPath = $viewPath . '/vendor/' . $namespace)) {
398396
View::prependNamespace($namespace, $appPath);
399397
}
400398
}
401399
}
402-
403-
View::prependNamespace($namespace, $path);
404400
}
405401
}
406402
}
403+
404+
// Update config mail.markdown.paths to work with mail views
405+
$mailViewsPath = $this->getPath('resources/views/vendor/mail');
406+
if (File::exists($vendorViewsPath) && is_dir($mailViewsPath)) {
407+
if (is_array(Config::get('mail.markdown.paths'))) {
408+
Config::set('mail.markdown.paths', array_merge([
409+
$mailViewsPath
410+
], Config::get('mail.markdown.paths')));
411+
} else {
412+
Config::set('mail.markdown.paths', $mailViewsPath);
413+
}
414+
}
407415
}
408416
}

src/ThemesManager.php

Lines changed: 37 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -101,22 +101,13 @@ public function clearCache(): bool
101101
* Check if theme with given name exists.
102102
*
103103
* @param string $name
104+
* @param string $vendor
104105
*
105106
* @return boolean
106107
*/
107108
public function has(string $name = null)
108109
{
109-
return !is_null($this->themes->first(function ($theme) use ($name) {
110-
// normalize module name
111-
$name = str_replace(['-theme', 'theme-'], '', $name);
112-
// Check if $name contains vendor
113-
if (strpos($name, '/') !== false) {
114-
return Str::lower($theme->getName()) === Str::lower(substr($name, $pos + 1, strlen($name)));
115-
;
116-
} else {
117-
return $theme->getLowerName() === Str::lower($name);
118-
}
119-
}));
110+
return !is_null($this->findByName($name));
120111
}
121112

122113
/**
@@ -131,17 +122,7 @@ public function get(string $name = null)
131122
if (is_null($name)) {
132123
return $this->themes;
133124
} else {
134-
return $this->themes->first(function ($theme) use ($name) {
135-
// normalize module name
136-
$name = str_replace(['-theme', 'theme-'], '', $name);
137-
// Check if $name contains vendor
138-
if (strpos($name, '/') !== false) {
139-
return Str::lower($theme->getName()) === Str::lower(substr($name, $pos + 1, strlen($name)));
140-
;
141-
} else {
142-
return $theme->getLowerName() === Str::lower($name);
143-
}
144-
});
125+
return $this->findByName($name);
145126
}
146127
}
147128

@@ -373,6 +354,40 @@ private function htmlAttributes($attributes): string
373354
}, array_keys($attributes)));
374355
}
375356

357+
/**
358+
* Find a theme by given name and vendor (optional)
359+
* name can include vendor prefix (ie: hexadog/default)
360+
* If no vendor provided and name not prefixed by vendor
361+
* the first theme with given name is returned
362+
*
363+
* @param string $name
364+
* @return void
365+
*/
366+
protected function findByName(string $name = null, string $vendor = null)
367+
{
368+
if (is_null($name)) {
369+
return null;
370+
}
371+
372+
return $this->themes->first(function ($theme) use ($name, $vendor) {
373+
// normalize module name
374+
$name = str_replace(['-theme', 'theme-'], '', $name);
375+
// Check if $name contains vendor
376+
if (($pos = strpos($name, '/')) !== false) {
377+
$vendor = substr($name, 0, $pos);
378+
$name = substr($name, $pos + 1, strlen($name));
379+
380+
return Str::lower($theme->getName()) === Str::lower($name) && $theme->getLowerVendor() === Str::lower($vendor);
381+
} else {
382+
if (is_null($vendor)) {
383+
return $theme->getLowerName() === Str::lower($name);
384+
} else {
385+
return $theme->getLowerName() === Str::lower($name) && $theme->getLowerVendor() === Str::lower($vendor);
386+
}
387+
}
388+
});
389+
}
390+
376391
/**
377392
* Find all available themes.
378393
*

0 commit comments

Comments
 (0)