Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions src/Unblaze.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,14 @@ public static function storeScope($token, $scope = [])
static::$unblazeScopes[$token] = $scope;
}

/**
* Store runtime replacement content for an @unblaze token.
*/
public static function storeReplacement(string $token, string $replacement)
{
static::$unblazeReplacements[$token] ??= base64_decode($replacement);
}

/**
* Check if a template contains @unblaze directives.
*/
Expand Down Expand Up @@ -60,6 +68,7 @@ public static function processUnblazeDirectives(string $template)
return ''
. '[STARTCOMPILEDUNBLAZE:'.$token.']'
. '<'.'?php \Livewire\Blaze\Unblaze::storeScope("'.$token.'", '.$expression.') ?>'
. '<'.'?php \Livewire\Blaze\Unblaze::storeReplacement("'.$token.'", "'.base64_encode($innerContent).'") ?>'
. '[ENDCOMPILEDUNBLAZE:'.$token.']';
}, $result);

Expand Down
20 changes: 20 additions & 0 deletions tests/Folder/UnblazeTest.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
<?php

use Illuminate\Support\Facades\Artisan;
use Livewire\Blaze\BladeRenderer;
use Livewire\Blaze\BladeService;
use Livewire\Blaze\Folder\Foldable;
use Livewire\Blaze\Parser\Parser;
use Livewire\Blaze\Unblaze;

beforeEach(fn () => Artisan::call('view:clear'));

test('compiles unblaze blocks', function () {
$input = '<x-foldable.input-unblaze name="address" />';
Expand Down Expand Up @@ -52,3 +56,19 @@
]))
);
});

test('processes replacements in compiled files', function () {
$path = fixture_path('views/components/foldable/input-unblaze.blade.php');
$node = app(Parser::class)->parse('<x-foldable.input-unblaze name="address" />')[0];

// Force compilation and store replacements...
$before = app(BladeRenderer::class)->render($node, $path);

// Flush replacements to simulate a separate process...
Unblaze::flushState();

// Ensure we can restore replacements from the compiled file...
$after = app(BladeRenderer::class)->render($node, $path);

expect($before)->toBe($after);
});
Loading