-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Tony
committed
Feb 25, 2016
0 parents
commit f05ac03
Showing
4 changed files
with
107 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
<?php namespace Tony\Themes; | ||
|
||
use Illuminate\View\FileViewFinder as IlluminateViewFinder; | ||
|
||
class FileViewFinder extends IlluminateViewFinder | ||
{ | ||
/** | ||
* This overrides the parent method and adds the location to the | ||
* beginning of the paths array vs the end. | ||
* | ||
* @param string $location | ||
* @return void | ||
*/ | ||
public function addLocation($location) | ||
{ | ||
//add location to the top of paths | ||
array_unshift($this->paths, $location); | ||
} | ||
|
||
/** | ||
* Allows us to remove view paths | ||
* | ||
* @param $location | ||
* @return void | ||
*/ | ||
public function removeLocation($location) | ||
{ | ||
//find and remove location if set | ||
if($key = array_search($location, $this->paths)) { | ||
unset($this->paths[$key]); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<?php namespace Tony\Themes; | ||
|
||
|
||
class Theme | ||
{ | ||
protected $theme = ""; | ||
|
||
/** | ||
* Set the Theme | ||
* | ||
* @param $name | ||
* @param null $absolute_path | ||
*/ | ||
public function set($name, $absolute_path = null) | ||
{ | ||
// Use default /larathemes/ directory if other is not set | ||
if(empty($absolute_path)) $absolute_path = base_path('larathemes/'.$name); | ||
// remove any other theme that was previously set | ||
if(!empty($this->theme)) app('view.finder')->removeLocation($this->theme.'/views'); | ||
//set theme and add location to view file finder | ||
if(is_dir($absolute_path)) $this->theme = $absolute_path; | ||
app('view.finder')->addLocation($absolute_path.'/views'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<?php namespace Tony\Themes; | ||
|
||
use View; | ||
use Illuminate\Support\ServiceProvider; | ||
|
||
class ThemeServiceProvider extends ServiceProvider | ||
{ | ||
|
||
/** | ||
* Register the service provider. | ||
* | ||
* @return void | ||
*/ | ||
public function register() | ||
{ | ||
$this->app['view.finder'] = $this->app->share(function($app) { | ||
$paths = View::getFinder()->getPaths(); | ||
return new FileViewFinder($app['files'], $paths); | ||
}); | ||
View::setFinder(app('view.finder')); | ||
$this->app->bind('tony.larathemes', 'Tony\Themes\Theme'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
{ | ||
"name": "codewithtony/larathemes", | ||
"description": "Theme Manager for Laravel 5", | ||
"keywords": [ "Laravel 5", "Themes", "Laravel Theme", "Theme Manager" ], | ||
"homepage": "https://github.com/codewithtony/larathemes", | ||
"type": "library", | ||
"license": "MIT", | ||
"authors": [ | ||
{ | ||
"name": "Tony.", | ||
"email": "tony@codewithtony.com", | ||
"homepage": "http://www.codewithtony.com" | ||
} | ||
], | ||
"support": { | ||
"issues": "https://github.com/codewithtony/larathemes/issues" | ||
}, | ||
"require": { | ||
"php": ">=5.4.0", | ||
"laravel/framework": "5.*" | ||
}, | ||
"autoload": { | ||
"psr-4": { | ||
"Tony\\Themes\\": "src/Tony/Themes/" | ||
} | ||
} | ||
} |