Skip to content

Commit 60bdd78

Browse files
Merge pull request #1 from hexadog/develop
Develop
2 parents 03062f9 + 33f2943 commit 60bdd78

File tree

8 files changed

+383
-102
lines changed

8 files changed

+383
-102
lines changed

README.md

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,8 @@ Themes Manager has many features to help you working with themes
5757
- [Artisan Commands](#artisan-commands)
5858
- [Create Theme](#create-theme)
5959
- [List Themes](#list-themes)
60+
- [Activate Theme](#activate-theme)
61+
- [Deactivate Theme](#deactivate-theme)
6062
- [View flow](#view-flow)
6163
- [Errors views](#errors-views)
6264
- [Package views](#package-views)
@@ -374,12 +376,22 @@ List all existing themes in your application with their details.
374376
```shell
375377
php artisan theme:list
376378

377-
+-----------+---------+---------+------------------------------------+-----------+---------+
378-
| Name | Vendor | Version | Description | Extends | Default |
379-
+-----------+---------+---------+------------------------------------+-----------+---------+
380-
| theme-one | hexadog | 1.0 | Default Hexadog CMS frontend theme | | X |
381-
| theme-two | hexadog | 1.0 | Default Hexadog CMS frontend theme | theme-one | |
382-
+-----------+---------+---------+------------------------------------+-----------+---------+
379+
+-----------+---------+---------+------------------------------------+-----------+---------+--------+
380+
| Name | Vendor | Version | Description | Extends | Default | Active |
381+
+-----------+---------+---------+------------------------------------+-----------+---------+--------+
382+
| theme-one | hexadog | 1.0 | Default Hexadog CMS frontend theme | | X | Yes |
383+
| theme-two | hexadog | 1.0 | Default Hexadog CMS frontend theme | theme-one | | Yes |
384+
+-----------+---------+---------+------------------------------------+-----------+---------+--------+
385+
```
386+
387+
#### Activate Theme
388+
```shell
389+
php artisan theme:activate hexadog/default
390+
```
391+
392+
#### Deactivate Theme
393+
```shell
394+
php artisan theme:deactivate hexadog/default
383395
```
384396

385397
### View flow
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
<?php
2+
3+
namespace Hexadog\ThemesManager\Console\Commands;
4+
5+
use Hexadog\ThemesManager\Console\Commands\Traits\BlockMessage;
6+
use Hexadog\ThemesManager\Console\Commands\Traits\SectionMessage;
7+
use Hexadog\ThemesManager\Facades\ThemesManager;
8+
use Illuminate\Console\Command;
9+
10+
class ActivateTheme extends Command
11+
{
12+
use BlockMessage;
13+
use SectionMessage;
14+
15+
/**
16+
* The console command signature.
17+
*
18+
* @var string
19+
*/
20+
protected $signature = 'theme:activate {name}';
21+
22+
/**
23+
* The console command description.
24+
*
25+
* @var string
26+
*/
27+
protected $description = 'Activate a theme';
28+
29+
/**
30+
* Create a new command instance.
31+
*
32+
* @return void
33+
*/
34+
public function __construct()
35+
{
36+
parent::__construct();
37+
}
38+
39+
/**
40+
* Prompt for module's alias name
41+
*
42+
*/
43+
public function handle()
44+
{
45+
if (!ThemesManager::has($this->argument('name'))) {
46+
$this->error("Theme with name {$this->argument('name')} does not exists!");
47+
48+
return false;
49+
}
50+
51+
$theme = ThemesManager::get($this->argument('name'));
52+
53+
if ($theme->isActive()) {
54+
$this->error("Theme with name {$this->argument('name')} is already active!");
55+
56+
return false;
57+
}
58+
59+
$this->sectionMessage('Themes Manager', 'Activating theme...');
60+
if ($theme->activate()) {
61+
$this->sectionMessage('Themes Manager', 'Theme deactivated succefully');
62+
} else {
63+
$this->error("Error while activating Theme with name {$this->argument('name')}!");
64+
}
65+
$this->sectionMessage('Themes Manager', 'Theme activated succefully');
66+
}
67+
}
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
<?php
2+
3+
namespace Hexadog\ThemesManager\Console\Commands;
4+
5+
use Hexadog\ThemesManager\Console\Commands\Traits\BlockMessage;
6+
use Hexadog\ThemesManager\Console\Commands\Traits\SectionMessage;
7+
use Hexadog\ThemesManager\Facades\ThemesManager;
8+
use Illuminate\Console\Command;
9+
10+
class DeactivateTheme extends Command
11+
{
12+
use BlockMessage;
13+
use SectionMessage;
14+
15+
/**
16+
* The console command signature.
17+
*
18+
* @var string
19+
*/
20+
protected $signature = 'theme:deactivate {name}';
21+
22+
/**
23+
* The console command description.
24+
*
25+
* @var string
26+
*/
27+
protected $description = 'Deactivate a theme';
28+
29+
/**
30+
* Create a new command instance.
31+
*
32+
* @return void
33+
*/
34+
public function __construct()
35+
{
36+
parent::__construct();
37+
}
38+
39+
/**
40+
* Prompt for module's alias name
41+
*
42+
*/
43+
public function handle()
44+
{
45+
if (!ThemesManager::has($this->argument('name'))) {
46+
$this->error("Theme with name {$this->argument('name')} does not exists!");
47+
48+
return false;
49+
}
50+
51+
$theme = ThemesManager::get($this->argument('name'));
52+
53+
if (!$theme->isActive()) {
54+
$this->error("Theme with name {$this->argument('name')} is already deactivated!");
55+
56+
return false;
57+
}
58+
59+
$this->sectionMessage('Themes Manager', 'Deactivating theme...');
60+
61+
if ($theme->deactivate()) {
62+
$this->sectionMessage('Themes Manager', 'Theme deactivated succefully');
63+
} else {
64+
$this->error("Error while deactivating Theme with name {$this->argument('name')}!");
65+
}
66+
}
67+
}

src/Console/Commands/ListThemes.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ class ListThemes extends Command
2525
*
2626
* @var array
2727
*/
28-
protected $headers = ['Name', 'Vendor', 'Version', 'Description', 'Extends', 'Default'];
28+
protected $headers = ['Name', 'Vendor', 'Version', 'Description', 'Extends', 'Default', 'Active'];
2929

3030
/**
3131
* Create a new command instance.
@@ -55,6 +55,7 @@ public function handle()
5555
'description' => $theme->get('description'),
5656
'extends' => $theme->getParent() ? $theme->getParent() : '',
5757
'default' => $theme->getName() === config('themes-manager.fallback_theme') ? 'X' : '',
58+
'active' => $theme->isActive() ? 'Yes' : 'No',
5859
];
5960
}
6061

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?php
2+
3+
namespace Hexadog\ThemesManager\Exceptions;
4+
5+
class ThemeNotActiveException extends \Exception
6+
{
7+
public function __construct($name = null, $code = 0)
8+
{
9+
parent::__construct("Theme with name '{$name}' is not active", $code);
10+
}
11+
}

src/Providers/PackageServiceProvider.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,8 @@ protected function strapCommands()
127127
{
128128
if ($this->app->runningInConsole() || config('app.env') == 'testing') {
129129
$this->commands([
130+
Commands\ActivateTheme::class,
131+
Commands\DeactivateTheme::class,
130132
Commands\ListThemes::class,
131133
Generators\MakeTheme::class,
132134
]);

0 commit comments

Comments
 (0)