Skip to content
This repository was archived by the owner on Mar 14, 2021. It is now read-only.

Commit 98ea75a

Browse files
author
Kerem
committed
Initial Commit
0 parents  commit 98ea75a

File tree

14 files changed

+466
-0
lines changed

14 files changed

+466
-0
lines changed

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
composer.lock
2+
.DS_Store
3+
.idea
4+
vendor

CHANGELOG.md

Whitespace-only changes.

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2019 Kerem Bahcivan
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
![Laravel Theme](http://kerembahcivan.com/opensource/laravel-theme.jpg)
2+
3+
# Laravel Template Builder
4+
This package creates multiple managed theme infrastructure for Laravel.
5+
6+
7+
## Getting Started
8+
9+
### 1. Install
10+
11+
Run the install command:
12+
13+
```bash
14+
composer require bkeremm/laravel-theme dev-master
15+
```
16+
17+
### 2. Register (for Laravel < 5.5)
18+
19+
Register the service provider in `config/app.php`
20+
21+
```php
22+
Cankod\Theme\ServiceProvider::class,
23+
```
24+
25+
Add alias if you want to use the facade.
26+
27+
```php
28+
'Theme' => Cankod\Theme\Facade::class,
29+
```
30+
31+
### 3. Publish
32+
33+
Publish config file.
34+
35+
```bash
36+
php artisan vendor:publish --tag=theme
37+
```
38+
39+
### 4. Configure
40+
41+
You can change the options of your app from `config/theme.php` file
42+
43+
## Usage
44+
45+
```php
46+
Theme::asset('app.css');
47+
Theme::asset('app.js');
48+
```
49+
50+
### What's next?
51+
- [ ] Advanced View Files
52+
- [ ] Webpack Build
53+
54+
### Changelog
55+
56+
Please see [CHANGELOG](CHANGELOG.md) for more information what has changed recently.
57+
58+
## Credits
59+
60+
- [Kerem Bahcivan](https://kerembahcivan.com)
61+
62+
## License
63+
64+
The MIT License (MIT). Please see [LICENSE](LICENSE.md) for more information.

composer.json

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
{
2+
"name": "bkeremm/laravel-theme",
3+
"description": "This package creates multiple managed theme infrastructure for Laravel.\n",
4+
"keywords": [
5+
"laravel",
6+
"theme",
7+
"laravel-theme",
8+
"laravel theme generator"
9+
],
10+
"license": "MIT",
11+
"authors": [
12+
{
13+
"name": "Kerem Bahcivan",
14+
"email": "[email protected]"
15+
}
16+
],
17+
"autoload": {
18+
"psr-4": {
19+
"Cankod\\Theme\\": "src/"
20+
}
21+
},
22+
"extra": {
23+
"laravel": {
24+
"providers": [
25+
"Cankod\\Theme\\ServiceProvider"
26+
],
27+
"aliases": {
28+
"Theme": "Cankod\\Theme\\Facade"
29+
}
30+
}
31+
},
32+
"minimum-stability": "dev",
33+
"prefer-stable": true,
34+
"require": {
35+
"php": ">=5.6.4",
36+
"laravel/framework": ">=5.3"
37+
},
38+
"require-dev": {
39+
"laravel/framework": ">=5.3"
40+
}
41+
}
Lines changed: 188 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,188 @@
1+
<?php
2+
namespace Cankod\Theme\Commands;
3+
4+
use Illuminate\Console\Command;
5+
USE Illuminate\Support\Facades\File;
6+
use Illuminate\Support\Facades\Validator;
7+
8+
class ThemeGeneratorCommand extends Command {
9+
10+
protected $signature = 'theme:generate';
11+
12+
protected $description = 'Generate New Theme';
13+
14+
protected $config;
15+
16+
17+
public function __construct()
18+
{
19+
$this->config = config('theme');
20+
parent::__construct();
21+
}
22+
23+
public function handle()
24+
{
25+
$name = $this->ask('Theme Name');
26+
27+
$validator = Validator::make([
28+
'name' => $name,
29+
], [
30+
'name' => ['required'],
31+
]);
32+
33+
if ($validator->fails()) {
34+
$this->info('Failed to create theme. You must enter the following fields:');
35+
36+
foreach ($validator->errors()->all() as $error) {
37+
$this->error($error);
38+
}
39+
return $this->handle();
40+
}
41+
42+
if (!File::exists($this->getDirectory('resources')))
43+
{
44+
File::makeDirectory($this->getDirectory('resources'));
45+
}
46+
47+
if (!File::exists($this->getDirectory('resources',$name)))
48+
{
49+
// Themes altına klasör oluştur.
50+
File::makeDirectory($this->getDirectory('resources',$name));
51+
File::makeDirectory($this->getDirectory('resources',$name.'/views'));
52+
53+
if ($this->confirm('Create a default theme folder structure?',true)) {
54+
$this->template($name);
55+
}
56+
if ($this->confirm('Create a default asset folder structure?',true)) {
57+
$this->assets($name);
58+
}
59+
60+
$this->info("Theme Generator Successful. Now add your default theme from the config/theme settings.");
61+
return;
62+
}
63+
64+
$this->error('Theme Folder Previously Created!');
65+
66+
return $this->handle();
67+
68+
}
69+
70+
protected function template($themeName)
71+
{
72+
$this->setFolder('resources',$themeName.'/views/'.$this->config['views_folder']['layout']);
73+
$this->setFolder('resources',$themeName.'/views/'.$this->config['views_folder']['component']);
74+
75+
$layoutTemplate = str_replace(
76+
[
77+
'{{header}}',
78+
'{{footer}}'
79+
],
80+
[
81+
$this->config['views_folder']['component'].'.'.$this->config['views_blade']['header'],
82+
$this->config['views_folder']['component'].'.'.$this->config['views_blade']['footer']
83+
],
84+
$this->getStub('layout')
85+
);
86+
87+
$indexTemplate = str_replace(
88+
[
89+
'{{layoutName}}'
90+
],
91+
[
92+
$this->config['views_folder']['layout'].'.'.$this->config['views_blade']['layout'],
93+
],
94+
$this->getStub('index')
95+
);
96+
97+
$this->setFile('resources',$themeName.'/views/'.$this->config['views_folder']['layout'],$this->config['views_blade']['layout'].'.blade.php',$layoutTemplate);
98+
$this->setFile('resources',$themeName.'/views/'.$this->config['views_folder']['component'],$this->config['views_blade']['header'].'.blade.php');
99+
$this->setFile('resources',$themeName.'/views/'.$this->config['views_folder']['component'],$this->config['views_blade']['footer'].'.blade.php');
100+
$this->setFile('resources',$themeName.'/views/',$this->config['views_blade']['index'].'.blade.php',$indexTemplate);
101+
102+
$this->info("Theme view files created!");
103+
}
104+
105+
protected function assets($themeName)
106+
{
107+
108+
if (!File::exists($this->getDirectory('public')))
109+
{
110+
// Default Asset Theme Folder Create
111+
$this->setFolder('public');
112+
}
113+
114+
if (!File::exists($this->getDirectory('public',$themeName)))
115+
{
116+
$this->setFolder('public',$themeName);
117+
$this->setFolder('public',$themeName.'/css');
118+
$this->setFolder('public',$themeName.'/js');
119+
120+
$this->setFile('public',$themeName.'/css','app.css');
121+
$this->setFile('public',$themeName.'/js','app.js');
122+
123+
$this->info("Theme asset files created!");
124+
125+
return;
126+
}
127+
128+
}
129+
130+
protected function getStub($fileName)
131+
{
132+
return File::get(__DIR__.'/../Template/'.$fileName.'.stub');
133+
}
134+
135+
protected function getDirectory($folder,$path = NULL)
136+
{
137+
if ($folder === 'resources')
138+
{
139+
if ($path === NULL)
140+
{
141+
return resource_path($this->config['theme_path']);
142+
}
143+
return resource_path($this->config['theme_path'].'/'.$path);
144+
}
145+
146+
if ($folder === 'public')
147+
{
148+
if ($path === NULL)
149+
{
150+
return public_path($this->config['asset_path']);
151+
}
152+
return public_path($this->config['asset_path'].'/'.$path);
153+
}
154+
155+
}
156+
157+
protected function setFile($directory,$folder,$file,$content = NULL)
158+
{
159+
if ($directory === 'resources')
160+
{
161+
return File::put($this->getDirectory('resources',$folder).'/'.$file,$content);
162+
}
163+
if ($directory === 'public')
164+
{
165+
return File::put($this->getDirectory('public',$folder).'/'.$file,$content);
166+
}
167+
}
168+
169+
protected function setFolder($directory,$path = null)
170+
{
171+
if ($directory === 'resources')
172+
{
173+
if ($path == null)
174+
{
175+
return File::makeDirectory(resource_path($this->config['theme_path']));
176+
}
177+
return File::makeDirectory(resource_path($this->config['theme_path']).'/'.$path);
178+
}
179+
if ($directory === 'public')
180+
{
181+
if ($path == null)
182+
{
183+
return File::makeDirectory(public_path($this->config['theme_path']));
184+
}
185+
return File::makeDirectory(public_path($this->config['theme_path']).'/'.$path);
186+
}
187+
}
188+
}

src/Config/theme.php

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<?php
2+
3+
return [
4+
// Current Theme
5+
'current_theme' => 'default',
6+
7+
/*
8+
* Theme Folder Names
9+
*/
10+
'views_folder' => [
11+
'layout' => 'layouts',
12+
'component' => 'components',
13+
],
14+
/*
15+
* Theme Blade File Names
16+
*/
17+
'views_blade' => [
18+
'index' => 'index',
19+
'header' => 'header',
20+
'footer' => 'footer',
21+
'layout' => 'main'
22+
],
23+
24+
/*
25+
|--------------------------------------------------------------------------
26+
| Theme Settings
27+
|--------------------------------------------------------------------------
28+
|
29+
|
30+
*/
31+
32+
'theme_path' => 'themes',
33+
34+
'asset_path' => 'themes',
35+
36+
];

src/Facade.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?php
2+
3+
namespace Cankod\Theme;
4+
5+
class Facade extends \Illuminate\Support\Facades\Facade
6+
{
7+
protected static function getFacadeAccessor()
8+
{
9+
return 'theme';
10+
}
11+
}

0 commit comments

Comments
 (0)