Skip to content

Commit 6a2282d

Browse files
committed
fix: implemented impormap sections
1 parent c366e3e commit 6a2282d

File tree

3 files changed

+76
-24
lines changed

3 files changed

+76
-24
lines changed

web/landing/composer.lock

Lines changed: 28 additions & 24 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

web/landing/config/services.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,10 @@ services:
5353
arguments:
5454
$dslPath: '%dsl_definitions_path%'
5555

56+
Flow\Website\Twig\ImportMapExtension:
57+
arguments:
58+
$importMapRenderer: '@asset_mapper.importmap.renderer'
59+
5660
Flow\Website\Command\GenerateDSLCompleterCommand:
5761
arguments:
5862
$projectDir: '%kernel.project_dir%'
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Flow\Website\Twig;
6+
7+
use Symfony\Component\AssetMapper\ImportMap\ImportMapRenderer;
8+
use Twig\Extension\AbstractExtension;
9+
use Twig\TwigFunction;
10+
11+
final class ImportMapExtension extends AbstractExtension
12+
{
13+
public function __construct(private readonly ImportMapRenderer $importMapRenderer)
14+
{
15+
}
16+
17+
public function getFunctions() : array
18+
{
19+
return [
20+
new TwigFunction('importmap', $this->renderImportmap(...), ['is_safe' => ['html']]),
21+
];
22+
}
23+
24+
public function renderImportmap(string $entryPoint = 'app') : string
25+
{
26+
$html = $this->importMapRenderer->render($entryPoint);
27+
28+
// Add scopes to fix Stimulus controller relative imports
29+
$html = \str_replace(
30+
' }
31+
}',
32+
' },
33+
"scopes": {
34+
"/assets/@symfony/stimulus-bundle/": {
35+
"../../controllers/": "/assets/controllers/"
36+
}
37+
}
38+
}',
39+
$html
40+
);
41+
42+
return $html;
43+
}
44+
}

0 commit comments

Comments
 (0)