Skip to content

Commit

Permalink
v2.0.0
Browse files Browse the repository at this point in the history
- Switched `themes` directory to `Themes`
  • Loading branch information
afbora committed Jan 30, 2021
1 parent ba34511 commit 7694a0a
Show file tree
Hide file tree
Showing 9 changed files with 115 additions and 83 deletions.
15 changes: 15 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# This file is for unifying the coding style for different editors and IDEs
# editorconfig.org

# PHP PSR-2 Coding Standards
# http://www.php-fig.org/psr/psr-2/

root = true

[*.php]
charset = utf-8
end_of_line = lf
insert_final_newline = true
trim_trailing_whitespace = true
indent_style = space
indent_size = 4
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ All notable changes to this package will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this package adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [2.0.0] - 2021-01-31
- Breaking change: Switched `themes` directory to `Themes`

## [1.2.0] - 2021-01-03
- PHP 8 support with drop PHP 7.2
- Laravel 8 support with drop Laravel 6
Expand Down
78 changes: 39 additions & 39 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,43 +1,43 @@
{
"name": "afbora/larathemes",
"description": "Theme package for Laravel 7+|8+",
"keywords": [
"themes",
"laravel",
"blade",
"theme",
"themes-package"
],
"version": "1.2.0",
"license": "MIT",
"authors": [
{
"name": "Ahmet Bora",
"email": "byybora@gmail.com"
}
"name": "afbora/larathemes",
"description": "Theme package for Laravel 7+|8+",
"keywords": [
"themes",
"laravel",
"blade",
"theme",
"themes-package"
],
"version": "2.0.0",
"license": "MIT",
"authors": [
{
"name": "Ahmet Bora",
"email": "byybora@gmail.com"
}
],
"minimum-stability": "dev",
"prefer-stable": true,
"require": {
"php": "^7.3|^8.0",
"illuminate/support": "^7.0|^8.0"
},
"autoload": {
"files": [
"helpers/themes.php"
],
"minimum-stability": "dev",
"prefer-stable": true,
"require": {
"php": "^7.3|^8.0",
"illuminate/support": "^7.0|^8.0"
},
"autoload": {
"files": [
"helpers/themes.php"
],
"psr-4": {
"Afbora\\LaraThemes\\": "src/"
}
},
"extra": {
"laravel": {
"providers": [
"Afbora\\LaraThemes\\ThemesServiceProvider"
],
"aliases": {
"Theme": "Afbora\\LaraThemes\\Facades\\Theme"
}
}
"psr-4": {
"Afbora\\LaraThemes\\": "src/"
}
},
"extra": {
"laravel": {
"providers": [
"Afbora\\LaraThemes\\ThemesServiceProvider"
],
"aliases": {
"Theme": "Afbora\\LaraThemes\\Facades\\Theme"
}
}
}
}
2 changes: 1 addition & 1 deletion config/themes.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
| may register your themes as a composer package as well.
|
*/

'vendor' => 'vendor',

];
21 changes: 13 additions & 8 deletions helpers/themes.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
/**
* Return the path to the given theme file.
*
* @param string $file
* @param string $theme
* @return string
* @param string|null $file
* @param string|null $theme
* @return string|null
*/
function theme_path($file = '', $theme = null)
function theme_path(string $file = null, string $theme = null): ?string
{
return Theme::path($file, $theme);
}
Expand All @@ -19,13 +19,18 @@ function theme_path($file = '', $theme = null)
* Return the asset url to the given theme file.
*
* @param string $file
* @param string $theme
* @return string
* @param string|null $theme
* @return string|null
* @author Ahmet Bora
*/
function theme_asset($file = '', $theme = null)
function theme_asset(string $file, string $theme = null): ?string
{
$theme = $theme ?? Theme::getCurrent();
return asset('themes/' . $theme . '/' . $file);

if (empty($theme) === false) {
return asset('Themes/' . $theme . '/' . $file);
}

return null;
}
}
5 changes: 0 additions & 5 deletions resources/stubs/theme/src/Providers/RouteServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@ class RouteServiceProvider extends ServiceProvider
*/
public function boot()
{
//

parent::boot();
}

Expand All @@ -36,10 +34,7 @@ public function boot()
public function map()
{
$this->mapApiRoutes();

$this->mapWebRoutes();

//
}

/**
Expand Down
4 changes: 2 additions & 2 deletions src/Console/GenerateTheme.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public function __construct()
public function handle()
{
$options = $this->getOptions();
$root = base_path('themes');
$root = base_path('Themes');
$stubsPath = __DIR__ . '/../../resources/stubs/theme';
$slug = $options['slug'];
$name = $this->format($slug);
Expand Down Expand Up @@ -132,7 +132,7 @@ protected function replacePlaceholders($contents, $options)
* @param string $name
* @return string
*/
private function format($name)
private function format(string $name): string
{
return ucfirst(Str::camel($name));
}
Expand Down
66 changes: 40 additions & 26 deletions src/Theme.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,22 @@ class Theme extends Collection
use RegistersViewLocations;

/**
* @var string
* @var string|null
*/
protected $current;

/**
* @var string|null
*/
protected $layout = null;
protected $layout;

/**
* Register and set the currently active theme.
*
* @param string $theme
* @return self
*/
public function set($theme)
public function set(string $theme): self
{
list($theme, $parent) = $this->resolveTheme($theme);

Expand All @@ -39,32 +40,38 @@ public function set($theme)
$this->addRegisteredLocation($theme, $parent);
$this->symlinkPublicDirectory();
$this->registerServiceProvider($this->format($theme->get('slug')));

return $this;
}

/**
* Get the path of the given theme file.
*
* @param string $file
* @param string $theme
* @return string
* @param string|null $file
* @param string|null $theme
* @return string|null
*/
public function path($file = '', $theme = null)
public function path(string $file = null, string $theme = null): ?string
{
if (is_null($theme)) {
if (empty($theme) === true) {
$theme = $this->getCurrent();
}

$theme = $this->format($theme);
if (empty($theme) === false) {
$theme = $this->format($theme);

return base_path('Themes/' . $theme . (empty($file) === false ? '/' . $file : null));
}

return base_path("themes/{$theme}/{$file}");
return null;
}

/**
* Get the layout property.
*
* @return string
* @return string|null
*/
public function getLayout()
public function getLayout(): ?string
{
return $this->layout;
}
Expand All @@ -73,28 +80,33 @@ public function getLayout()
* Set the layout property.
*
* @param string $layout
* @return self
*/
public function setLayout($layout)
public function setLayout(string $layout): self
{
$this->layout = $layout;

return $this;
}

/**
* Set the current theme property.
*
* @param string $theme
*/
public function setCurrent($theme)
public function setCurrent(string $theme): self
{
$this->current = $theme;

return $this;
}

/**
* Get the current theme property.
*
* @return string
*/
public function getCurrent()
public function getCurrent(): ?string
{
return $this->current;
}
Expand All @@ -105,7 +117,7 @@ public function getCurrent()
* @param string $theme
* @return bool
*/
public function isCurrently($theme)
public function isCurrently(string $theme): bool
{
return $this->current === $theme;
}
Expand All @@ -116,26 +128,28 @@ public function isCurrently($theme)
* @param string $name
* @return string
*/
protected function format($name)
protected function format(string $name): string
{
return ucfirst(Str::camel($name));
}

/**
* Symlink the themes public directory so its accesible
* Symlink the themes public directory so its accessible
* by the web.
*
* @return void
*/
protected function symlinkPublicDirectory()
protected function symlinkPublicDirectory(): void
{
if (!file_exists(public_path('themes/' . $this->getCurrent()))) {
if (!file_exists(public_path('themes'))) {
app()->make('files')->makeDirectory(public_path('themes'));
$theme = $this->format($this->getCurrent());

if (!file_exists(public_path('Themes/' . $theme))) {
if (!file_exists(public_path('Themes'))) {
app()->make('files')->makeDirectory(public_path('Themes'));
}

app()->make('files')->link(
$this->path('public'), public_path('themes/' . $this->getCurrent())
$this->path('public'), public_path('Themes/' . $theme)
);
}
}
Expand All @@ -146,7 +160,7 @@ protected function symlinkPublicDirectory()
* @param string $theme
* @return void
*/
protected function registerServiceProvider($theme)
protected function registerServiceProvider(string $theme): void
{
app()->register("Themes\\$theme\\Providers\\ThemeServiceProvider");
}
Expand All @@ -157,15 +171,15 @@ protected function registerServiceProvider($theme)
* @param string $theme
* @return void
*/
protected function registerAutoload($theme)
protected function registerAutoload(string $theme): void
{
$base = 'Themes\\' . $theme . '\\';
$path = $this->path('src/');

spl_autoload_register(function ($class) use ($base, $path) {
$file = str_replace($base, '', $class);
$file = str_replace('\\', '/', $file);
$file .= '.php';
$file = $file . '.php';

if (file_exists($path . $file)) {
include($path . $file);
Expand Down
4 changes: 2 additions & 2 deletions src/ThemesServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,10 @@ public function provides()
protected function registerServices()
{
$this->app->singleton('afbora.larathemes', function ($app) {
$themes = [];
$items = [];
$themes = [];

if ($path = base_path('themes')) {
if ($path = base_path('Themes')) {
if (file_exists($path) && is_dir($path)) {
$themes = $this->app['files']->directories($path);
}
Expand Down

0 comments on commit 7694a0a

Please sign in to comment.