Skip to content

Commit

Permalink
v1.1.3
Browse files Browse the repository at this point in the history
  • Loading branch information
afbora committed May 10, 2020
1 parent 7ef82dc commit e9988d2
Show file tree
Hide file tree
Showing 10 changed files with 142 additions and 133 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ 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).

## [1.1.3] - 2020-05-10
### Fixed
- Reference full namespace path to `Theme` facade

## [1.1.2] - 2020-04-02
### Fixed
- Error pages (`errors/404.blade.php`) can now properly be overridden by your themes
Expand Down
10 changes: 8 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
{
"name": "afbora/larathemes",
"description": "Theme package for Laravel 6+",
"keywords": ["themes", "laravel", "blade", "theme", "themes-package"],
"version": "1.1.0",
"keywords": [
"themes",
"laravel",
"blade",
"theme",
"themes-package"
],
"version": "1.1.3",
"license": "MIT",
"authors": [
{
Expand Down
3 changes: 0 additions & 3 deletions resources/stubs/theme/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,5 @@
"psr-4": {
"DummyEscapedNamespace\\": "src/"
}
},
"require": {
"afbora/composer": "*"
}
}
18 changes: 9 additions & 9 deletions src/Concerns/RegistersViewLocations.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ trait RegistersViewLocations
/**
* Resolve and return the primary and parent themes.
*
* @param string $theme
* @param string $theme
* @return array
*/
protected function resolveTheme($theme)
{
$theme = $this->where('slug', $theme)->first();
$theme = $this->where('slug', $theme)->first();
$parent = null;

if ($theme->has('parent')) {
Expand All @@ -27,17 +27,17 @@ protected function resolveTheme($theme)
/**
* Remove the primary and parent theme from the view finder.
*
* @param Manifest $theme
* @param Manifest $theme
*/
protected function removeRegisteredLocation()
{
$current = $this->where('slug', $this->getCurrent())->first();
$current = $this->where('slug', $this->getCurrent())->first();
$currentLocation = $this->path('resources/views');

app('view.finder')->removeLocation($currentLocation);

if ($current->has('parent')) {
$parent = $this->where('slug', $current->get('parent'))->first();
$parent = $this->where('slug', $current->get('parent'))->first();
$parentLocation = $this->path('resources/views', $parent->slug);
app('view.finder')->removeLocation($parentLocation);
}
Expand All @@ -46,12 +46,12 @@ protected function removeRegisteredLocation()
/**
* Register the primary and parent theme with the view finder.
*
* @param Manifest $theme
* @param Manifest $parent
* @param Manifest $theme
* @param Manifest $parent
*/
protected function addRegisteredLocation($theme, $parent)
{
if (! is_null($parent)) {
if (!is_null($parent)) {
$parentLocation = $this->path('resources/views');
app('view.finder')->prependLocation($parentLocation);
}
Expand All @@ -63,7 +63,7 @@ protected function addRegisteredLocation($theme, $parent)
/**
* Format the name of the theme name to reference the correct directory.
*
* @param string $name
* @param string $name
* @return string
*/
protected function format($name)
Expand Down
42 changes: 21 additions & 21 deletions src/Console/GenerateTheme.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,27 +39,27 @@ public function __construct()
*/
public function handle()
{
$options = $this->getOptions();
$root = base_path('themes');
$stubsPath = __DIR__ . '/../../resources/stubs/theme';
$slug = $options['slug'];
$name = $this->format($slug);
$options = $this->getOptions();
$root = base_path('themes');
$stubsPath = __DIR__ . '/../../resources/stubs/theme';
$slug = $options['slug'];
$name = $this->format($slug);

if (File::isDirectory($root . '/' . $name)) {
return $this->error('Theme already exists!');
}

if (! File::isDirectory($root)) {
if (!File::isDirectory($root)) {
File::makeDirectory($root);
}

foreach (File::allFiles($stubsPath) as $file) {
$contents = $this->replacePlaceholders($file->getContents(), $options);
$subPath = $file->getRelativePathname();
$filePath = $root.'/'.$options['name'].'/'.$subPath;
$dir = dirname($filePath);
$subPath = $file->getRelativePathname();
$filePath = $root . '/' . $options['name'] . '/' . $subPath;
$dir = dirname($filePath);

if (! File::isDirectory($dir)) {
if (!File::isDirectory($dir)) {
File::makeDirectory($dir, 0755, true);
}

Expand All @@ -74,21 +74,21 @@ public function handle()
*/
protected function getOptions()
{
$slug = Str::slug($this->argument('slug'));
$name = $this->format($slug);
$quick = $this->option('quick');
$slug = Str::slug($this->argument('slug'));
$name = $this->format($slug);
$quick = $this->option('quick');
$vendor = config('themes.vendor');
$author = config('themes.author');

return [
'slug' => $slug,
'namespace' => "Themes\\$name",
'slug' => $slug,
'namespace' => "Themes\\$name",
'escaped_namespace' => "Themes\\\\$name",
'name' => $quick ? $name : $this->ask('What is your theme\'s name?', $name),
'author' => $quick ? $author : $this->ask('Who is the author of your theme?', $author),
'version' => $quick ? '1.0.0' : $this->ask('What is the version of your theme?', '1.0.0'),
'description' => $quick ? "$name theme." : $this->ask('Can you describe your theme?', "$name theme."),
'package_name' => $quick ? "{$vendor}/{$slug}" : $this->ask('What is the composer package name? [optional]', "{$vendor}/{$slug}")
'name' => $quick ? $name : $this->ask('What is your theme\'s name?', $name),
'author' => $quick ? $author : $this->ask('Who is the author of your theme?', $author),
'version' => $quick ? '1.0.0' : $this->ask('What is the version of your theme?', '1.0.0'),
'description' => $quick ? "$name theme." : $this->ask('Can you describe your theme?', "$name theme."),
'package_name' => $quick ? "{$vendor}/{$slug}" : $this->ask('What is the composer package name? [optional]', "{$vendor}/{$slug}")
];
}

Expand Down Expand Up @@ -129,7 +129,7 @@ protected function replacePlaceholders($contents, $options)
/**
* Format the given name as the directory basename.
*
* @param string $name
* @param string $name
* @return string
*/
private function format($name)
Expand Down
19 changes: 10 additions & 9 deletions src/Facades/Theme.php
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
<?php

namespace Afbora\LaraThemes\Facades;

use Illuminate\Support\Facades\Facade;

class Theme extends Facade
{
/**
* Get the registered name of the component.
*
* @return string
*/
protected static function getFacadeAccessor()
{
return 'afbora.larathemes';
}
/**
* Get the registered name of the component.
*
* @return string
*/
protected static function getFacadeAccessor()
{
return 'afbora.larathemes';
}
}
8 changes: 4 additions & 4 deletions src/Manifest.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class Manifest extends Collection
/**
* Create a new Manifest.
*
* @param null|string $path
* @param null|string $path
*/
public function __construct($path = null)
{
Expand All @@ -37,7 +37,7 @@ public function __construct($path = null)
/**
* Make a new manifest collection based on the passed file path.
*
* @param string $path
* @param string $path
* @return static
*/
public static function make($path = null)
Expand Down Expand Up @@ -94,7 +94,7 @@ protected function encode()
/**
* Set the manifest file path property.
*
* @param string $path
* @param string $path
*/
public function setPath($path)
{
Expand All @@ -114,7 +114,7 @@ public function getPath()
/**
* Set the manifest content property.
*
* @param string $content
* @param string $content
*/
public function setContent($content)
{
Expand Down
39 changes: 20 additions & 19 deletions src/Theme.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@ class Theme extends Collection
/**
* Register and set the currently active theme.
*
* @param string $theme
* @param string $theme
*/
public function set($theme)
{
list($theme, $parent) = $this->resolveTheme($theme);

if (! $this->isCurrently($theme->get('slug')) and (! is_null($this->getCurrent()))) {
if (!$this->isCurrently($theme->get('slug')) and (!is_null($this->getCurrent()))) {
$this->removeRegisteredLocation();
}

Expand All @@ -44,8 +44,8 @@ public function set($theme)
/**
* Get the path of the given theme file.
*
* @param string $file
* @param string $theme
* @param string $file
* @param string $theme
* @return string
*/
public function path($file = '', $theme = null)
Expand All @@ -72,16 +72,17 @@ public function getLayout()
/**
* Set the layout property.
*
* @param string $layout
* @param string $layout
*/
public function setLayout($layout)
{
$this->layout = $layout;
}

/**
* Set the current theme property.
*
* @param string $theme
* @param string $theme
*/
public function setCurrent($theme)
{
Expand All @@ -101,7 +102,7 @@ public function getCurrent()
/**
* Determine if the given theme is the currently set theme.
*
* @param string $theme
* @param string $theme
* @return bool
*/
public function isCurrently($theme)
Expand All @@ -112,7 +113,7 @@ public function isCurrently($theme)
/**
* Format the given name as the directory basename.
*
* @param string $name
* @param string $name
* @return string
*/
protected function format($name)
Expand All @@ -128,21 +129,21 @@ protected function format($name)
*/
protected function symlinkPublicDirectory()
{
if (! file_exists(public_path('themes/'.$this->getCurrent()))) {
if (! file_exists(public_path('themes'))) {
if (!file_exists(public_path('themes/' . $this->getCurrent()))) {
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/' . $this->getCurrent())
);
}
}

/**
* Register the theme's service provider.
*
* @param string $theme
* @param string $theme
* @return void
*/
protected function registerServiceProvider($theme)
Expand All @@ -153,22 +154,22 @@ protected function registerServiceProvider($theme)
/**
* Register the themes path as a PSR-4 reference.
*
* @param string $theme
* @param string $theme
* @return void
*/
protected function registerAutoload($theme)
{
$base = 'Themes\\'.$theme.'\\';
{
$base = 'Themes\\' . $theme . '\\';
$path = $this->path('src/');

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

if (file_exists($path.$file)) {
include($path.$file);
if (file_exists($path . $file)) {
include($path . $file);
}
});
}
}
}

0 comments on commit e9988d2

Please sign in to comment.