Skip to content

Commit

Permalink
use fluent string helpers
Browse files Browse the repository at this point in the history
  • Loading branch information
tabacitu committed Nov 24, 2021
1 parent 12b5058 commit 9d6c891
Showing 1 changed file with 8 additions and 10 deletions.
18 changes: 8 additions & 10 deletions src/blade_directives.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,15 @@

Blade::directive('loadOnce', function ($parameter) {
// determine if it's a CSS or JS file
$filePath = $parameter;
$filePath = trim($filePath, "'");
$filePath = trim($filePath, '"');
$filePath = trim($filePath, '`');
$filePath = Str::before($filePath, '?');
$filePath = Str::before($filePath, '#');
$cleanParameter = Str::of($parameter)->trim("'")->trim('"')->trim('`');
$filePath = Str::of($cleanParameter)->before('?')->before('#');
$extension = substr($filePath, -3);

// mey be useful to get the second parameter
// if (Str::contains($parameter, ',')) {
// $secondParameter = Str::of($parameter)->after(',')->trim(' ');
// }

switch ($extension) {
case 'css':
return "<?php Assets::echoCss({$parameter}); ?>";
Expand All @@ -31,11 +32,8 @@

default:
// it's a block start
$parameter = trim($parameter, "'");
$parameter = trim($parameter, '"');
$parameter = trim($parameter, '`');

return "<?php if(! Assets::isAssetLoaded('".$parameter."')) { Assets::markAssetAsLoaded('".$parameter."'); ?>";
return "<?php if(! Assets::isAssetLoaded('".$cleanParameter."')) { Assets::markAssetAsLoaded('".$cleanParameter."'); ?>";
break;
}
});
Expand Down

0 comments on commit 9d6c891

Please sign in to comment.