Skip to content

Commit

Permalink
Fix issue #93: @css('path/to/file.css') no longer working
Browse files Browse the repository at this point in the history
  • Loading branch information
igaster committed May 24, 2018
1 parent b37c530 commit 6cb6925
Showing 1 changed file with 109 additions and 106 deletions.
215 changes: 109 additions & 106 deletions src/themeServiceProvider.php
Original file line number Diff line number Diff line change
@@ -1,67 +1,71 @@
<?php namespace Igaster\LaravelTheme;

use Illuminate\Support\ServiceProvider;
use Illuminate\Support\Facades\Config;
use Illuminate\Support\Facades\Blade;
use Igaster\LaravelTheme\Facades\Theme;
use Illuminate\Support\Facades\Config;
use Illuminate\Support\ServiceProvider;

class themeServiceProvider extends ServiceProvider {
class themeServiceProvider extends ServiceProvider
{

public function register(){
public function register()
{

/*--------------------------------------------------------------------------
| Bind in IOC
|--------------------------------------------------------------------------*/
/*--------------------------------------------------------------------------
| Bind in IOC
|--------------------------------------------------------------------------*/

$this->app->singleton('igaster.themes', function(){
return new Themes();
});
$this->app->singleton('igaster.themes', function () {
return new Themes();
});

/*--------------------------------------------------------------------------
| Replace FileViewFinder
|--------------------------------------------------------------------------*/
/*--------------------------------------------------------------------------
| Replace FileViewFinder
|--------------------------------------------------------------------------*/

$this->app->singleton('view.finder', function($app) {
$this->app->singleton('view.finder', function ($app) {
return new \Igaster\LaravelTheme\themeViewFinder(
$app['files'],
$app['config']['view.paths'],
null
);
});

/*--------------------------------------------------------------------------
| Register helpers.php functions
|--------------------------------------------------------------------------*/
/*--------------------------------------------------------------------------
| Register helpers.php functions
|--------------------------------------------------------------------------*/

require_once 'Helpers/helpers.php';

/*--------------------------------------------------------------------------
| Initialize Themes
|--------------------------------------------------------------------------*/
/*--------------------------------------------------------------------------
| Initialize Themes
|--------------------------------------------------------------------------*/

$themes = $this->app->make('igaster.themes');
$themes = $this->app->make('igaster.themes');
$themes->scanThemes();

/*--------------------------------------------------------------------------
| Activate default theme
|--------------------------------------------------------------------------*/
if (!$themes->current() && \Config::get('themes.default'))
$themes->set(\Config::get('themes.default'));
/*--------------------------------------------------------------------------
| Activate default theme
|--------------------------------------------------------------------------*/
if (!$themes->current() && \Config::get('themes.default')) {
$themes->set(\Config::get('themes.default'));
}

}

public function boot(){
public function boot()
{

/*--------------------------------------------------------------------------
| Pulish configuration file
|--------------------------------------------------------------------------*/
/*--------------------------------------------------------------------------
| Pulish configuration file
|--------------------------------------------------------------------------*/

$this->publishes([
__DIR__.'/Config/themes.php' => config_path('themes.php'),
], 'laravel-theme');
$this->publishes([
__DIR__ . '/Config/themes.php' => config_path('themes.php'),
], 'laravel-theme');

/*--------------------------------------------------------------------------
| Register Console Commands
|--------------------------------------------------------------------------*/
/*--------------------------------------------------------------------------
| Register Console Commands
|--------------------------------------------------------------------------*/
if ($this->app->runningInConsole()) {
$this->commands([
\Igaster\LaravelTheme\Commands\listThemes::class,
Expand All @@ -73,74 +77,73 @@ public function boot(){
]);
}

/*--------------------------------------------------------------------------
| Register custom Blade Directives
|--------------------------------------------------------------------------*/

$this->registerBladeDirectives();
}

protected function registerBladeDirectives(){
/*--------------------------------------------------------------------------
| Extend Blade to support Orcherstra\Asset (Asset Managment)
|
| Syntax:
|
| @css (filename, alias, depends-on-alias)
| @js (filename, alias, depends-on-alias)
|--------------------------------------------------------------------------*/

Blade::extend(function($value)
{
return preg_replace_callback('/\@js\s*\(\s*([^),]*)(?:,\s*([^),]*))?(?:,\s*([^),]*))?\)/', function($match){

$p1 = trim($match[1], " \t\n\r\0\x0B\"'");
$p2 = trim(empty($match[2]) ? $p1 : $match[2], " \t\n\r\0\x0B\"'");
$p3 = trim(empty($match[3]) ? '' : $match[3], " \t\n\r\0\x0B\"'");

if(empty($p3))
return "<?php Asset::script('$p2', theme_url('$p1'));?>";
else
return "<?php Asset::script('$p2', theme_url('$p1'), '$p3');?>";

},$value);
});

\Blade::extend(function ($value)
{
return preg_replace_callback('/\@jsIn\s*\(\s*([^),]*)(?:,\s*([^),]*))?(?:,\s*([^),]*))?(?:,\s*([^),]*))?\)/',
function ($match) {

$p1 = trim($match[1], " \t\n\r\0\x0B\"'");
$p2 = trim($match[2], " \t\n\r\0\x0B\"'");
$p3 = trim(empty($match[3]) ? $p2 : $match[3], " \t\n\r\0\x0B\"'");
$p4 = trim(empty($match[4]) ? '' : $match[4], " \t\n\r\0\x0B\"'");

if (empty($p4)) {
return "<?php Asset::container('$p1')->script('$p3', theme_url('$p2'));?>";
} else {
return "<?php Asset::container('$p1')->script('$p3', theme_url('$p2'), '$p4');?>";
}

}, $value);
});


Blade::extend(function($value)
{
return preg_replace_callback('/\@css\s*\(\stheme_url([^),]*)(?:,\s*([^),]*))?(?:,\s*([^),]*))?\)/', function($match){

$p1 = trim($match[1], " \t\n\r\0\x0B\"'");
$p2 = trim(empty($match[2]) ? $p1 : $match[2], " \t\n\r\0\x0B\"'");
$p3 = trim(empty($match[3]) ? '' : $match[3], " \t\n\r\0\x0B\"'");

if(empty($p3))
return "<?php Asset::style('$p2', theme_url('$p1'));?>";
else
return "<?php Asset::style('$p2', theme_url('$p1'), '$p3');?>";

},$value);
});
}
/*--------------------------------------------------------------------------
| Register custom Blade Directives
|--------------------------------------------------------------------------*/

$this->registerBladeDirectives();
}

protected function registerBladeDirectives()
{
/*--------------------------------------------------------------------------
| Extend Blade to support Orcherstra\Asset (Asset Managment)
|
| Syntax:
|
| @css (filename, alias, depends-on-alias)
| @js (filename, alias, depends-on-alias)
|--------------------------------------------------------------------------*/

Blade::extend(function ($value) {
return preg_replace_callback('/\@js\s*\(\s*([^),]*)(?:,\s*([^),]*))?(?:,\s*([^),]*))?\)/', function ($match) {

$p1 = trim($match[1], " \t\n\r\0\x0B\"'");
$p2 = trim(empty($match[2]) ? $p1 : $match[2], " \t\n\r\0\x0B\"'");
$p3 = trim(empty($match[3]) ? '' : $match[3], " \t\n\r\0\x0B\"'");

if (empty($p3)) {
return "<?php Asset::script('$p2', theme_url('$p1'));?>";
} else {
return "<?php Asset::script('$p2', theme_url('$p1'), '$p3');?>";
}

}, $value);
});

Blade::extend(function ($value) {
return preg_replace_callback('/\@jsIn\s*\(\s*([^),]*)(?:,\s*([^),]*))?(?:,\s*([^),]*))?(?:,\s*([^),]*))?\)/',
function ($match) {

$p1 = trim($match[1], " \t\n\r\0\x0B\"'");
$p2 = trim($match[2], " \t\n\r\0\x0B\"'");
$p3 = trim(empty($match[3]) ? $p2 : $match[3], " \t\n\r\0\x0B\"'");
$p4 = trim(empty($match[4]) ? '' : $match[4], " \t\n\r\0\x0B\"'");

if (empty($p4)) {
return "<?php Asset::container('$p1')->script('$p3', theme_url('$p2'));?>";
} else {
return "<?php Asset::container('$p1')->script('$p3', theme_url('$p2'), '$p4');?>";
}

}, $value);
});

Blade::extend(function ($value) {
return preg_replace_callback('/\@css\s*\(\s*([^),]*)(?:,\s*([^),]*))?(?:,\s*([^),]*))?\)/', function ($match) {

$p1 = trim($match[1], " \t\n\r\0\x0B\"'");
$p2 = trim(empty($match[2]) ? $p1 : $match[2], " \t\n\r\0\x0B\"'");
$p3 = trim(empty($match[3]) ? '' : $match[3], " \t\n\r\0\x0B\"'");

if (empty($p3)) {
return "<?php Asset::style('$p2', theme_url('$p1'));?>";
} else {
return "<?php Asset::style('$p2', theme_url('$p1'), '$p3');?>";
}

}, $value);
});
}

}

0 comments on commit 6cb6925

Please sign in to comment.