From d0d46ed6f11070e983f1879925c0b0675a366f69 Mon Sep 17 00:00:00 2001 From: Deon George Date: Tue, 23 Nov 2021 11:49:07 +1100 Subject: [PATCH] Add back orchestra/asset --- composer.json | 3 +- src/Providers/CustomBladeServiceProvider.php | 221 ++++++++++++++++--- 2 files changed, 195 insertions(+), 29 deletions(-) diff --git a/composer.json b/composer.json index aa87ec8..27d9a0d 100644 --- a/composer.json +++ b/composer.json @@ -10,7 +10,8 @@ } ], "require": { - "creativeorange/gravatar": "^1.0" + "creativeorange/gravatar": "^1.0", + "orchestra/asset": "^6.0" }, "require-dev": { }, diff --git a/src/Providers/CustomBladeServiceProvider.php b/src/Providers/CustomBladeServiceProvider.php index d3c96ec..ffce1c9 100644 --- a/src/Providers/CustomBladeServiceProvider.php +++ b/src/Providers/CustomBladeServiceProvider.php @@ -3,7 +3,9 @@ namespace Leenooks\Providers; use Illuminate\Support\Facades\Blade; +use Illuminate\Support\Facades\Log; use Illuminate\Support\ServiceProvider; +use Ramsey\Collection\Collection; class CustomBladeServiceProvider extends ServiceProvider { @@ -15,14 +17,9 @@ class CustomBladeServiceProvider extends ServiceProvider public function boot() { Blade::directive('css',function(string $expression,array $args=[]) { - $html = ''; + return $this->resolve('css',$expression); switch (trim($expression,"'")) { - case 'datatables': - return - ''. - ''; - case 'select2': return ''; @@ -34,30 +31,13 @@ class CustomBladeServiceProvider extends ServiceProvider default: throw new \Exception('Unknown CSS: '.$expression); } - - return $html; }); - Blade::directive('js',function($expression) { - $html = ''; + Blade::directive('js',function($expression,string $options=NULL) { + Log::debug('JS: '.$expression); + return $this->resolve('js',$expression); switch (trim($expression,"'")) { - case 'datatables': - return - ''. - ''. - ''. - ''; - - case 'highcharts': - return - ''. - ''. - ''. - ''. - ''. - ''; - case 'select2': return ''. @@ -70,8 +50,193 @@ class CustomBladeServiceProvider extends ServiceProvider default: 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 ''; + + case 'js': + return ''; + } + } } \ No newline at end of file