Skip to content

Commit d957d41

Browse files
committed
Devfront: internalisation de la library semantic-ui
1 parent fbd602c commit d957d41

File tree

8 files changed

+87
-3
lines changed

8 files changed

+87
-3
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,3 +54,4 @@ js_dist
5454
/assets/vendor/
5555
drivers
5656
chromedriver.log
57+
/htdocs/dist

app/config/packages/asset_mapper.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ framework:
55
- '%kernel.project_dir%/../assets/'
66
importmap_path: '%kernel.project_dir%/../importmap.php'
77
missing_import_mode: strict
8+
vendor_dir: '%kernel.project_dir%/../assets/vendor'
89

910
when@prod:
1011
framework:

app/config/services.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,3 +240,12 @@ services:
240240
autowire: true
241241
arguments:
242242
$transports: !tagged_iterator app.social_network.transport
243+
244+
asset_mapper.local_public_assets_filesystem:
245+
class: AppBundle\AssetMapper\PostCompilationCopyHandler
246+
autowire: true
247+
248+
asset_mapper.compiled_asset_mapper_config_reader:
249+
class: Symfony\Component\AssetMapper\CompiledAssetMapperConfigReader
250+
arguments:
251+
$directory: '%kernel.project_dir%/../htdocs/dist'

htdocs/.htaccess

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,4 +54,6 @@ RewriteRule ^ask/forum/? https://event.afup.org [R=301,L]
5454
RewriteRule ^ask/? / [R=301,L]
5555

5656
## This url are handled by symfony
57+
RewriteCond %{ENV:APP_ENV} ^dev$
58+
RewriteRule (dist)/? /index.php [L] # Asset in local development
5759
RewriteRule (event|connect|_|association|talks|meetups|blog|admin|p|home|news|techno_watch|member|login|logout|password-reset|rss.xml)/? /index.php [END]

importmap.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,11 @@
1616
'path' => './assets/app.js',
1717
'entrypoint' => true,
1818
],
19+
'semantic-ui/dist/semantic.min.css' => [
20+
'version' => '2.5.0',
21+
'type' => 'css'
22+
],
23+
'semantic-ui/dist/semantic.min.js' => [
24+
'version' => '2.5.0'
25+
],
1926
];
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace AppBundle\AssetMapper;
6+
7+
use Symfony\Component\AssetMapper\Compressor\CompressorInterface;
8+
use Symfony\Component\AssetMapper\Path\PublicAssetsFilesystemInterface;
9+
use Symfony\Component\DependencyInjection\Attribute\Autowire;
10+
use Symfony\Component\Filesystem\Filesystem;
11+
12+
/**
13+
* cf. https://symfony.com/doc/current/frontend/asset_mapper.html#serving-assets-in-dev-vs-prod
14+
*/
15+
class PostCompilationCopyHandler implements PublicAssetsFilesystemInterface
16+
{
17+
private Filesystem $filesystem;
18+
19+
/**
20+
* @param string[] $extensionsToCompress
21+
*/
22+
public function __construct(
23+
#[Autowire('%kernel.project_dir%/../htdocs')]
24+
private readonly string $publicDir,
25+
private readonly ?CompressorInterface $compressor = null,
26+
private readonly array $extensionsToCompress = [],
27+
) {
28+
$this->filesystem = new Filesystem();
29+
}
30+
31+
public function write(string $path, string $contents): void
32+
{
33+
$targetPath = $this->publicDir . '/' . ltrim($path, '/');
34+
35+
$this->filesystem->dumpFile($targetPath, $contents);
36+
$this->compress($targetPath);
37+
}
38+
39+
public function copy(string $originPath, string $path): void
40+
{
41+
$targetPath = $this->publicDir . '/' . ltrim($path, '/');
42+
43+
$this->filesystem->copy($originPath, $targetPath, true);
44+
$this->compress($targetPath);
45+
}
46+
47+
public function getDestinationPath(): string
48+
{
49+
return $this->publicDir;
50+
}
51+
52+
private function compress(string $targetPath): void
53+
{
54+
foreach ($this->extensionsToCompress as $ext) {
55+
if (!str_ends_with($targetPath, ".$ext")) {
56+
continue;
57+
}
58+
59+
$this->compressor?->compress($targetPath);
60+
61+
return;
62+
}
63+
}
64+
}

templates/admin/base_with_header.html.twig

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<meta charset="utf-8">
55
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
66
<title>Administration AFUP</title>
7-
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/semantic-ui@2.4.2/dist/semantic.min.css">
7+
<link rel="stylesheet" href="{{ asset('vendor/semantic-ui/dist/semantic.min.css') }}">
88
<link rel="icon" type="image/png" href="/templates/administration/images/favicon-96x96.png" sizes="96x96" />
99
<link rel="icon" type="image/svg+xml" href="/templates/administration/images/favicon.svg" />
1010
<link rel="shortcut icon" href="/templates/administration/images/favicon.ico" />
@@ -133,7 +133,7 @@
133133

134134
{% block javascript %}
135135
<script src="https://code.jquery.com/jquery-3.1.1.min.js" crossorigin="anonymous"></script>
136-
<script src="https://cdn.jsdelivr.net/npm/semantic-ui@2.4.2/dist/semantic.min.js"></script>
136+
<script src="{{ asset('vendor/semantic-ui/dist/semantic.min.js') }}"></script>
137137

138138
<link rel="stylesheet" href="https://cdn.jsdelivr.net/simplemde/latest/simplemde.min.css">
139139
<script src="https://cdn.jsdelivr.net/simplemde/latest/simplemde.min.js"></script>

templates/base.html.twig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,6 @@
5858

5959
{% block footer '' %}
6060
{% block javascripts '' %}
61-
{# {% block importmap %}{{ importmap('app') }}{% endblock %}#}
61+
{% block importmap %}{{ importmap('app') }}{% endblock %}
6262
</body>
6363
</html>

0 commit comments

Comments
 (0)