Skip to content

Commit 2070d97

Browse files
Merge pull request #26 from Stillat/improve-compatibility
Improve compatibility with other component compilers
2 parents bc5d74f + d0812fc commit 2070d97

File tree

4 files changed

+41
-2
lines changed

4 files changed

+41
-2
lines changed

src/Compiler/TemplateCompiler.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ protected function isRoot(): bool
181181
/**
182182
* Replaces all raw placeholders within the provided string.
183183
*/
184-
protected function resolveBlocks(string $value): string
184+
public function resolveBlocks(string $value): string
185185
{
186186
$placeholders = array_keys($this->componentBlocks);
187187

@@ -742,7 +742,7 @@ protected function simplifyNodes(array $nodes): array
742742

743743
protected function storeComponentBlock(string $value): string
744744
{
745-
$placeholder = '__RAW::'.Utils::makeRandomString();
745+
$placeholder = '__DAGGER_RAW::'.Utils::makeRandomString();
746746
$this->componentBlocks[$placeholder] = $value;
747747

748748
return $placeholder;

src/Facades/Compiler.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
* @method static bool compiledDynamicComponentExists(string $proxyName, string $componentName)
1717
* @method static void compileDynamicComponent(array $proxyDetails, string $componentName)
1818
* @method static CompilerOptions getOptions()
19+
* @method static resolveBlocks(string $value): string
1920
* @method static cleanup()
2021
*/
2122
class Compiler extends Facade

src/Listeners/ResponsePreparedListener.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ public function __construct(ViewManifest $manifest)
1717
public function handle()
1818
{
1919
Compiler::cleanup();
20+
ViewCreatingListener::clearCheckedViews();
2021

2122
foreach ($this->manifest->getTracked() as $rootView => $tracked) {
2223
file_put_contents(

src/Listeners/ViewCreatingListener.php

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,61 @@
22

33
namespace Stillat\Dagger\Listeners;
44

5+
use Illuminate\Support\Str;
6+
use Stillat\Dagger\Facades\Compiler;
57
use Stillat\Dagger\Runtime\ViewManifest;
68

79
class ViewCreatingListener
810
{
911
protected ViewManifest $manifest;
1012

13+
protected static array $checkedViews = [];
14+
1115
public function __construct(ViewManifest $manifest)
1216
{
1317
$this->manifest = $manifest;
1418
}
1519

1620
public function create($view): void
1721
{
22+
$this->checkForBladeRenderCall($view);
23+
1824
$this->manifest->push($view);
1925

2026
$this->checkForInvalidation($view);
2127
}
2228

29+
protected function checkForBladeRenderCall($view): void
30+
{
31+
$name = $view->getName();
32+
33+
if (! Str::startsWith($name, '__components::')) {
34+
return;
35+
}
36+
37+
if (isset(static::$checkedViews[$name])) {
38+
return;
39+
}
40+
41+
static::$checkedViews[$name] = true;
42+
43+
$path = $view->getPath();
44+
45+
if (! file_exists($path)) {
46+
return;
47+
}
48+
49+
file_put_contents(
50+
$path,
51+
Compiler::resolveBlocks(file_get_contents($path))
52+
);
53+
}
54+
55+
public static function clearCheckedViews(): void
56+
{
57+
static::$checkedViews = [];
58+
}
59+
2360
protected function checkForInvalidation($view): void
2461
{
2562
$name = $view->getName();

0 commit comments

Comments
 (0)