Add back orchestra/asset

This commit is contained in:
Deon George 2021-11-23 11:49:07 +11:00
parent 7df5a2c1d9
commit d0d46ed6f1
No known key found for this signature in database
GPG Key ID: 7670E8DC27415254
2 changed files with 195 additions and 29 deletions

View File

@ -10,7 +10,8 @@
} }
], ],
"require": { "require": {
"creativeorange/gravatar": "^1.0" "creativeorange/gravatar": "^1.0",
"orchestra/asset": "^6.0"
}, },
"require-dev": { "require-dev": {
}, },

View File

@ -3,7 +3,9 @@
namespace Leenooks\Providers; namespace Leenooks\Providers;
use Illuminate\Support\Facades\Blade; use Illuminate\Support\Facades\Blade;
use Illuminate\Support\Facades\Log;
use Illuminate\Support\ServiceProvider; use Illuminate\Support\ServiceProvider;
use Ramsey\Collection\Collection;
class CustomBladeServiceProvider extends ServiceProvider class CustomBladeServiceProvider extends ServiceProvider
{ {
@ -15,14 +17,9 @@ class CustomBladeServiceProvider extends ServiceProvider
public function boot() public function boot()
{ {
Blade::directive('css',function(string $expression,array $args=[]) { Blade::directive('css',function(string $expression,array $args=[]) {
$html = ''; return $this->resolve('css',$expression);
switch (trim($expression,"'")) { switch (trim($expression,"'")) {
case 'datatables':
return
'<link type="text/css" rel="stylesheet" href="https://cdn.datatables.net/1.10.25/css/dataTables.bootstrap5.min.css" media="screen">'.
'<link type="text/css" rel="stylesheet" href="'.asset('plugin/dataTables/dataTables.bootstrap5.css').'" media="screen">';
case 'select2': case 'select2':
return return
'<link type="text/css" rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.13/css/select2.min.css">'; '<link type="text/css" rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.13/css/select2.min.css">';
@ -34,30 +31,13 @@ class CustomBladeServiceProvider extends ServiceProvider
default: default:
throw new \Exception('Unknown CSS: '.$expression); throw new \Exception('Unknown CSS: '.$expression);
} }
return $html;
}); });
Blade::directive('js',function($expression) { Blade::directive('js',function($expression,string $options=NULL) {
$html = ''; Log::debug('JS: '.$expression);
return $this->resolve('js',$expression);
switch (trim($expression,"'")) { switch (trim($expression,"'")) {
case 'datatables':
return
'<script type="text/javascript" src="https://cdn.datatables.net/1.10.25/js/jquery.dataTables.min.js"></script>'.
'<script type="text/javascript" src="'.asset('plugin/dataTables/dataTables.conditionalPaging.js').'"></script>'.
'<script type="text/javascript" src="https://cdn.datatables.net/rowgroup/1.1.2/js/dataTables.rowGroup.min.js"></script>'.
'<script type="text/javascript" src="https://cdn.datatables.net/1.10.25/js/dataTables.bootstrap5.min.js"></script>';
case 'highcharts':
return
'<script type="text/javascript" src="https://code.highcharts.com/highcharts.js"></script>'.
'<script type="text/javascript" src="https://code.highcharts.com/modules/data.js"></script>'.
'<script type="text/javascript" src="https://code.highcharts.com/modules/drilldown.js"></script>'.
'<script type="text/javascript" src="https://code.highcharts.com/modules/exporting.js"></script>'.
'<script type="text/javascript" src="https://code.highcharts.com/modules/export-data.js"></script>'.
'<script type="text/javascript" src="https://code.highcharts.com/themes/dark-unica.js"></script>';
case 'select2': case 'select2':
return return
'<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.13/js/select2.min.js"></script>'. '<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.13/js/select2.min.js"></script>'.
@ -70,8 +50,193 @@ class CustomBladeServiceProvider extends ServiceProvider
default: default:
throw new \Exception('Unknown JS: '.$expression); throw new \Exception('Unknown JS: '.$expression);
} }
return $html;
}); });
} }
private function resolve(string $content,string $expression): string
{
if (str_contains($expression,','))
[$type,$arguments] = explode(',',$expression,2);
else {
$type = $expression;
$arguments = '';
}
$arguments = explode('|',trim($arguments,"'"));
$return = collect();
switch ($x=trim($type,"'")) {
case '':
Log::debug('Render ...');
dd(__METHOD__,'here');
break;
case 'datatables':
switch ($content) {
case 'css':
// Base
$return->push('https://cdn.datatables.net/1.10.23/css/jquery.dataTables.min.css');
foreach ($arguments as $option) {
switch ($option) {
case '':
break;
case 'bootstrap4':
$return->push('/plugin/dataTables/dataTables.bootstrap4.css');
break;
case 'buttons':
$return->push('https://cdn.datatables.net/buttons/1.6.5/css/buttons.dataTables.min.css');
break;
case 'fixedheader':
$return->push('https://cdn.datatables.net/fixedheader/3.1.7/css/fixedHeader.dataTables.min.css');
break;
case 'rowgroup':
$return->push('https://cdn.datatables.net/rowgroup/1.1.2/css/rowGroup.dataTables.min.css');
break;
case 'responsive':
$return->push('http://cdn.datatables.net/responsive/2.2.6/css/responsive.dataTables.min.css');
break;
case 'searchpanes':
$return->push('https://cdn.datatables.net/searchpanes/1.2.1/css/searchPanes.dataTables.min.css');
break;
case 'searchpanes-left':
$return->push('/plugin/dataTables/leftSearchPanes.css');
break;
case 'select':
$return->push('https://cdn.datatables.net/select/1.3.1/css/select.dataTables.min.css');
break;
default:
throw new \Exception(sprintf('Unknown [%s] option: [%s:%s]',$x,$content,$option));
}
}
break;
case 'js':
// Base
$return->push('https://cdn.datatables.net/1.10.23/js/jquery.dataTables.min.js');
foreach ($arguments as $option) {
switch ($option) {
case 'bootstrap4':
$return->push('/plugin/dataTables/dataTables.bootstrap4.js');
break;
case 'buttons':
$return->push('https://cdn.datatables.net/buttons/1.6.5/js/dataTables.buttons.min.js');
$return->push('https://cdn.datatables.net/buttons/1.6.5/js/buttons.html5.min.js');
$return->push('https://cdnjs.cloudflare.com/ajax/libs/jszip/3.2.0/jszip.min.js');
break;
case 'fixedheader':
$return->push('https://cdn.datatables.net/fixedheader/3.1.7/js/dataTables.fixedHeader.min.js');
break;
case 'responsive':
$return->push('https://cdn.datatables.net/responsive/2.2.6/js/dataTables.responsive.min.js');
break;
case 'rowgroup':
$return->push('https://cdn.datatables.net/rowgroup/1.1.2/js/dataTables.rowGroup.min.js');
break;
case 'searchpanes':
$return->push('https://cdn.datatables.net/searchpanes/1.2.1/js/dataTables.searchPanes.min.js');
break;
case 'select':
$return->push('https://cdn.datatables.net/select/1.3.1/js/dataTables.select.min.js');
break;
case 'default':
$return->push('');
break;
default:
throw new \Exception(sprintf('Unknown [%s] option: [%s:%s]',$x,$content,$option));
}
}
}
break;
case 'datepick':
switch ($content) {
case 'css':
$return->push('https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datepicker/1.9.0/css/bootstrap-datepicker.min.css');
break;
case 'js':
$return->push('https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datepicker/1.9.0/js/bootstrap-datepicker.min.js');
}
break;
case 'highcharts':
switch ($content) {
case 'js':
// Base
$return->push('https://code.highcharts.com/highcharts.js');
foreach ($arguments as $option) {
switch ($option) {
case '':
break;
case 'data':
$return->push('https://code.highcharts.com/modules/data.js');
break;
case 'defaults':
$return->push('/plugin/highcharts/defaults.js');
break;
case 'drilldown':
$return->push('https://code.highcharts.com/modules/drilldown.js');
break;
case 'heatmap':
$return->push('https://code.highcharts.com/modules/heatmap.js');
break;
case 'export':
$return->push('https://code.highcharts.com/modules/exporting.js');
$return->push('https://code.highcharts.com/modules/export-data.js');
break;
case 'theme-dark':
$return->push('https://code.highcharts.com/themes/dark-unica.js');
break;
default:
throw new \Exception(sprintf('Unknown [%s] option: [%s:%s]',$x,$content,$option));
}
}
}
break;
default:
throw new \Exception(sprintf('Unknown Expression: [%s]',$expression));
}
switch ($content) {
case 'css':
return '<link type="text/css" rel="stylesheet" href="'.$return->join('"><link type="text/css" rel="stylesheet" href="').'">';
case 'js':
return '<script type="text/javascript" src="'.$return->join('"></script><script type="text/javascript" src="').'"></script>';
}
}
} }