Skip to content

Commit

Permalink
Merge pull request #134 from Laravel-Backpack/allow-basset-block-to-s…
Browse files Browse the repository at this point in the history
…kip-cache

Allow basset blocks to skip cache
  • Loading branch information
pxpm authored Jul 16, 2024
2 parents dc420ca + f4779b3 commit ffa775c
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 3 deletions.
15 changes: 14 additions & 1 deletion src/BassetManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -231,10 +231,23 @@ public function basset(string $asset, bool|string $output = true, array $attribu
* @param string $code
* @return StatusEnum
*/
public function bassetBlock(string $asset, string $code, bool $output = true): StatusEnum
public function bassetBlock(string $asset, string $code, bool $output = true, bool $cache = true): StatusEnum
{
$this->loader->start();
// when cache is set to false we will just mark the asset as loaded to avoid
// loading the same asset twice and return the raw code to the browser.
if ($cache === false) {
if ($this->isloaded($asset)) {
return $this->loader->finish(StatusEnum::LOADED);
}
$this->markAsLoaded($asset);
echo $code;
return $this->loader->finish(StatusEnum::LOADED);
}
// Get asset path and url
$path = $this->getPathHashed($asset, $code);
Expand Down
2 changes: 1 addition & 1 deletion src/BassetServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ protected function registerBladeDirectives()
});

$bladeCompiler->directive('endLoadOnce', function (): string {
return '<?php Basset::bassetBlock($bassetBlock, ob_get_clean()); ?>';
return '<?php Basset::bassetBlock($bassetBlock, ob_get_clean(), true, false); ?>';
});

$bladeCompiler->directive('loadStyleOnce', function (string $parameter): string {
Expand Down
2 changes: 1 addition & 1 deletion tests/Feature/BassetTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
use Illuminate\Support\Facades\Http;

test('confirm environment is set to testing', function () {
expect(config('app.env'))->toBe('testing');
expect(config('app.env'))->toBe('workbench');
});

it('fails on invalid path', function () {
Expand Down

0 comments on commit ffa775c

Please sign in to comment.