From decea5a22609116a7f214dd69e782bfcffdcbfbb Mon Sep 17 00:00:00 2001 From: igaster Date: Thu, 26 Feb 2015 10:18:25 +0200 Subject: [PATCH] Theme::url() --- README.md | 27 +++++++++++++-------------- src/config.php | 18 ++++++++++++++---- src/themeServiceProvider.php | 15 ++++++++------- 3 files changed, 35 insertions(+), 25 deletions(-) diff --git a/README.md b/README.md index 839a814..6e5ac33 100644 --- a/README.md +++ b/README.md @@ -60,7 +60,14 @@ Simple define your themes in the `themes` array in `config\theme.php`. The forma ], ``` -all settings are optional and can be ommited. +all settings are optional and can be ommited. Check the example in the configuration file... + +## Extending themes + +You can set a theme to extend an other. When you are requesting a view/asset that doesn't exist in your active theme, then it will be resolved from it's parent theme. You can easily create variations of your theme by simply overiding your views/themes that are different. + +All themes fall back to the default laravel folders if a resource is not found on the theme folders. So for example you can leave your common libraries (jquery/bootstrap ...) in your `public` folder and use them from all themes. No need to dublicate common assets for each theme! + ## Switching Themes @@ -82,13 +89,6 @@ class themeSelectServiceProvider extends ServiceProvider { } ``` - -## Extending themes - -You can set a theme to extend an other. When you are requesting a view/asset that doesn't exist in your active theme, then it will be resolved from it's parent theme. You can easily create variations of your theme by simply overiding your views/themes that are different. - -All themes fall back to the default laravel folders if a resource is not found on the theme folders. So for example you can leave your common libraries (jquery/bootstrap ...) in your `public` folder and use them from all themes. No need to dublicate common assets for each theme! - ## Building your views Whenever you need to link to a local file (image/css/js etc) you can retreive its path with: @@ -101,9 +101,9 @@ The path is relative to Theme Folder (NOT to pubic!). For example, if you have p When you are refering to a local file it will be looked-up in the current theme hierarcy, and the correct path will be returned. If the file is not found on the current theme or its parents then an exception will be thrown. -## Assets Managment +## Assets Managment (by Orchestra/ASset) -This package provides intergration with [Orchestra/Asset](http://orchestraplatform.com/docs/3.0/components/asset) component. All the features are explained in the official documentation. The use of this package is optional. +This package provides intergration with [Orchestra/Asset](http://orchestraplatform.com/docs/3.0/components/asset) component. All the features are explained in the official documentation. Although Orchestra/Asset is installed along with this package, it's use is optional. To use the Orchestra\Asset you need to add in your Providers array: @@ -114,7 +114,7 @@ and add the Asset facade in your `Facades` array in `app/config/app.php` 'Asset' => 'Orchestra\Support\Facades\Asset', -Now you can leverage all the power of Orchestra\Asset package. Some Blade-specific sugar has been added to ease your work. So here how to build your views: +Now you can leverage all the power of Orchestra\Asset package. However the syntax can become painful when you are using Themes + Orchestra/Asset, so some Blade-specific sugar has been added to ease your work. So here how to build your views: In any blade file when you need to refer to a script or css: (dont use single/double quotes) @@ -126,7 +126,7 @@ Please note that you are just defining your css/js files but not actually dumpin {!! Asset::styles() !!} {!! Asset::scripts() !!} -exactly where you want write your declerations (usualy on HEAD and footer of the page). +exactly where you want write your declerations (usualy on Head and Footer of the page respectively). ## Assets dependencies @@ -135,12 +135,11 @@ Well this is an [Orchestra/Asset](http://orchestraplatform.com/docs/3.0/componen @css (filename, alias, depends-on) @js (filename, alias, depends-on) -and your assets dependencies will be auto resolved. Your assets will be exported in the correct order. A short example: +and your assets dependencies will be auto resolved. Your assets will be exported in the correct order. The biggest benefit of this approach is that you don't have to move all your declerations in your master layout file. Each sub-view can define it's requirements and they will auto-resolved in the correct order with no dublications. Awesome! A short example: @js (jquery.js, jq) @js (bootstrap.js, bs, jq) - ## Important Note: Laravel is compiling your views every-time you make an edit. A compiled view will not recompile if you switch to another theme unless you make any edit to your view. Keep this in mind while you are developing themes... \ No newline at end of file diff --git a/src/config.php b/src/config.php index b28357a..e686bf8 100644 --- a/src/config.php +++ b/src/config.php @@ -34,17 +34,27 @@ // Add your themes here... - /*--------------[Example Structre]------------- + /*--------------[ Example Structre ]------------- + // Recomended (all defaults) : Assets -> \public\BasicTheme , Views -> \resources\views\BasicTheme + 'BasicTheme', + + // This theme shares the views with BasicTheme but defines its own assets in \public\SomeTheme + 'SomeTheme' => [ - 'extends' => 'BasicTheme', + 'views-path' => 'BasicTheme', ], - 'AnOtherTheme', + + // This theme extends BasicTheme and ovverides SOME views\assets in its folders + + 'AnOtherTheme' => [ + 'extends' => 'BasicTheme', + ], - ----------------------------------------------*/ + ------------------------------------------------*/ ], ]; \ No newline at end of file diff --git a/src/themeServiceProvider.php b/src/themeServiceProvider.php index b73c6ae..fcecbd4 100644 --- a/src/themeServiceProvider.php +++ b/src/themeServiceProvider.php @@ -3,7 +3,6 @@ use Illuminate\Support\ServiceProvider; use Illuminate\Support\Facades\Config; use Illuminate\Support\Facades\Blade; -use igaster\laravelTheme\Themes; class themeServiceProvider extends ServiceProvider { @@ -47,11 +46,14 @@ public function register(){ if (!$Themes->activeTheme) $Themes->set(Config::get('themes.active')); } - } public function boot(){ + /*-------------------------------------------------------------------------- + | Pulish configuration file + |--------------------------------------------------------------------------*/ + $this->publishes([ __DIR__.'/config.php' => config_path('themes.php'), ]); @@ -69,7 +71,7 @@ public function boot(){ { return preg_replace_callback('/\@js\s*\(\s*([\w\-\._:\\/]*)\s*(?:,\s*([\w\-\._:\\/]*)\s*,?\s*(.*))?\)/', function($match){ - $p1 = Themes::url($match[1]); + $p1 = \Theme::url($match[1]); $p2 = empty($match[2]) ? $match[1] : $match[2]; $p3 = empty($match[3]) ? '' : $match[3]; @@ -78,7 +80,7 @@ public function boot(){ elseif(empty($p3)) return ""; else - return ""; // ToDo : Support for array of dependencies + return ""; },$value); }); @@ -87,7 +89,7 @@ public function boot(){ { return preg_replace_callback('/\@css\s*\(\s*([\w\-\._:\\/]*)\s*(?:,\s*([\w\-\._:\\/]*)\s*,?\s*(.*))?\)/', function($match){ - $p1 = Themes::url($match[1]); + $p1 = \Theme::url($match[1]); $p2 = empty($match[2]) ? $match[1] : $match[2]; $p3 = empty($match[3]) ? '' : $match[3]; @@ -96,10 +98,9 @@ public function boot(){ elseif(empty($p3)) return ""; else - return ""; // ToDo : Support for array of dependencies + return ""; },$value); }); - }