Skip to content

Commit

Permalink
Theme::url()
Browse files Browse the repository at this point in the history
  • Loading branch information
igaster committed Feb 26, 2015
1 parent 6d2f496 commit decea5a
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 25 deletions.
27 changes: 13 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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:
Expand All @@ -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:

Expand All @@ -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)

Expand All @@ -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

Expand All @@ -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...
18 changes: 14 additions & 4 deletions src/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
],
----------------------------------------------*/
------------------------------------------------*/
],

];
15 changes: 8 additions & 7 deletions src/themeServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand Down Expand Up @@ -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'),
]);
Expand All @@ -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];

Expand All @@ -78,7 +80,7 @@ public function boot(){
elseif(empty($p3))
return "<?php Asset::script('$p2', '$p1');?>";
else
return "<?php Asset::script('$p2', '$p1', '$p3');?>"; // ToDo : Support for array of dependencies
return "<?php Asset::script('$p2', '$p1', '$p3');?>";
},$value);
});

Expand All @@ -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];

Expand All @@ -96,10 +98,9 @@ public function boot(){
elseif(empty($p3))
return "<?php Asset::style('$p2', '$p1');?>";
else
return "<?php Asset::style('$p2', '$p1', '$p3');?>"; // ToDo : Support for array of dependencies
return "<?php Asset::style('$p2', '$p1', '$p3');?>";
},$value);
});

}


Expand Down

0 comments on commit decea5a

Please sign in to comment.