Skip to content

Commit

Permalink
Merge pull request #129 from Laravel-Backpack/loadOnce-fix
Browse files Browse the repository at this point in the history
Fix @loadOnce directive
  • Loading branch information
pxpm authored May 1, 2024
2 parents b8784c1 + 41d0141 commit dc420ca
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/BassetServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ protected function registerBladeDirectives()
return '<?php Basset::bassetBlock($bassetBlock, ob_get_clean()); ?>';
});

// DEPRECATED - Please use `@basset`. Will be completely removed in Backpack v7.
// DEPRECATED - Please use `@basset` or `@bassetBlock`. @loadOnce Will be completely removed in Backpack v7.
$bladeCompiler->directive('loadOnce', function (string $parameter): string {
// determine if it's a CSS or JS file
$cleanParameter = Str::of($parameter)->trim("'")->trim('"')->trim('`');
Expand All @@ -120,8 +120,13 @@ protected function registerBladeDirectives()
return "<?php Basset::basset({$parameter}); ?>";
}

// in case it's not js or css, we assume it's a block of code.
return "<?php \$bassetBlock = {$parameter}; ob_start(); ?>";
// in case it's not js or css specifically, we assume it's a block of javascript code.
// this is to keep backward compatibility with our previous usage of @loadOnce to load blocks of JS.
// we never used it for css and the recommended way was always to @loadOnce(file.css) or @loadOnce(file.js)
// this is a temporary solution until we remove @loadOnce completely.
$filePath = Str::of($filePath)->finish('.js')->value();

return "<?php \$bassetBlock = '{$filePath}'; ob_start(); ?>";
});

$bladeCompiler->directive('endLoadOnce', function (): string {
Expand Down
3 changes: 3 additions & 0 deletions src/Console/Commands/BassetCache.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ class BassetCache extends Command
public function handle(): void
{
$starttime = microtime(true);
/**
* @var \Backpack\Basset\BassetManager $basset
*/
$basset = app('basset');

$viewPaths = $basset->getViewPaths();
Expand Down

0 comments on commit dc420ca

Please sign in to comment.