12
12
namespace App \Service \Toolkit ;
13
13
14
14
use App \Enum \ToolkitKitId ;
15
- use App \Util \ SourceCleaner ;
15
+ use App \Service \ CommonMark \ Extension \ CodeBlockRenderer \ CodeBlockRenderer ;
16
16
use Symfony \Component \DependencyInjection \Attribute \Autowire ;
17
17
use Symfony \Component \Filesystem \Path ;
18
18
use Symfony \Component \HttpFoundation \UriSigner ;
21
21
use Symfony \UX \Toolkit \Installer \PoolResolver ;
22
22
use Symfony \UX \Toolkit \Kit \Kit ;
23
23
use Symfony \UX \Toolkit \Registry \RegistryFactory ;
24
- use function Symfony \Component \String \s ;
25
24
26
25
class ToolkitService
27
26
{
28
27
public function __construct (
29
28
#[Autowire(service: 'ux_toolkit.registry.registry_factory ' )]
30
29
private readonly RegistryFactory $ registryFactory ,
31
30
private readonly UriSigner $ uriSigner ,
32
- private readonly UrlGeneratorInterface $ urlGenerator
31
+ private readonly UrlGeneratorInterface $ urlGenerator,
33
32
) {
34
33
}
35
34
@@ -76,41 +75,41 @@ public function renderComponentPreviewCodeTabs(ToolkitKitId $kitId, string $code
76
75
</div>
77
76
<iframe class="Toolkit_Preview loading" src=" {$ previewUrl }" style="height: {$ height };" loading="lazy" onload="this.previousElementSibling.style.display = 'none'; this.classList.remove('loading')"></iframe>
78
77
HTML ,
79
- 'Code ' => $ highlightedCode
78
+ 'Code ' => $ highlightedCode,
80
79
]);
81
80
}
82
81
83
82
public function renderInstallationSteps (ToolkitKitId $ kitId , Component $ component ): string
84
83
{
85
84
$ kit = $ this ->getKit ($ kitId );
86
- $ pool = (new PoolResolver )->resolveForComponent ($ kit , $ component );
85
+ $ pool = (new PoolResolver () )->resolveForComponent ($ kit , $ component );
87
86
88
87
$ manual = '<p>The UX Toolkit is not mandatory to install a component. You can install it manually by following the next steps:</p> ' ;
89
88
$ manual .= '<ol style="display: grid; gap: 1rem;"> ' ;
90
- $ manual .= '<li><strong>Copy the files into your Symfony app:</strong> ' ;
89
+ $ manual .= '<li><strong>Copy the following file(s) into your Symfony app:</strong> ' ;
91
90
foreach ($ pool ->getFiles () as $ file ) {
92
- $ manual .= sprintf (
91
+ $ manual .= \ sprintf (
93
92
"<details><summary><code>%s</code></summary> \n%s \n</details> " ,
94
93
$ file ->relativePathNameToKit ,
95
- sprintf ("\n```%s \n%s \n``` " , pathinfo ($ file ->relativePathNameToKit , PATHINFO_EXTENSION ), trim (file_get_contents (Path::join ($ kit ->path , $ file ->relativePathNameToKit ))))
94
+ \ sprintf ("\n```%s \n%s \n``` " , pathinfo ($ file ->relativePathNameToKit , \ PATHINFO_EXTENSION ), trim (file_get_contents (Path::join ($ kit ->path , $ file ->relativePathNameToKit ))))
96
95
);
97
96
}
98
97
$ manual .= '</li> ' ;
99
98
100
99
if ($ phpPackageDependencies = $ pool ->getPhpPackageDependencies ()) {
101
100
$ manual .= '<li><strong>If necessary, install the following Composer dependencies:</strong> ' ;
102
- $ manual .= self :: generateTerminal ('shell ' , SourceCleaner:: processTerminalLines ( ' composer require ' . implode (' ' , $ phpPackageDependencies )) );
101
+ $ manual .= CodeBlockRenderer:: highlightCode ('shell ' , ' $ composer require '. implode (' ' , $ phpPackageDependencies ), ' margin-bottom: 0 ' );
103
102
$ manual .= '</li> ' ;
104
103
}
105
104
106
105
$ manual .= '<li><strong>And the most important, enjoy!</strong></li> ' ;
107
106
$ manual .= '</ol> ' ;
108
107
109
108
return $ this ->generateTabs ([
110
- 'Automatic ' => sprintf (
109
+ 'Automatic ' => \ sprintf (
111
110
'<p>Ensure the Symfony UX Toolkit is installed in your Symfony app:</p>%s<p>Then, run the following command to install the component and its dependencies:</p>%s ' ,
112
- self :: generateTerminal ('shell ' , SourceCleaner:: processTerminalLines ( ' composer require --dev symfony/ux-toolkit ' ), ' margin-bottom: 1rem ' ),
113
- self :: generateTerminal ('shell ' , SourceCleaner:: processTerminalLines ( " bin/console ux:toolkit:install-component {$ component ->name } --kit {$ kitId ->value }"), ' margin-bottom: 1rem ' ),
111
+ CodeBlockRenderer:: highlightCode ('shell ' , ' $ composer require --dev symfony/ux-toolkit ' ),
112
+ CodeBlockRenderer:: highlightCode ('shell ' , " $ bin/console ux:toolkit:install-component {$ component ->name } --kit {$ kitId ->value }" ),
114
113
),
115
114
'Manual ' => $ manual ,
116
115
]);
@@ -130,8 +129,8 @@ private static function generateTabs(array $tabs): string
130
129
$ activeTabId ??= $ tabId ;
131
130
$ isActive = $ activeTabId === $ tabId ;
132
131
133
- $ tabsControls .= sprintf ('<button class="Toolkit_TabControl" data-action="tabs#show" data-tabs-target="control" data-tabs-tab-param="%s" role="tab" aria-selected="%s">%s</button> ' , $ tabId , $ isActive ? 'true ' : 'false ' , trim ($ tabText ));
134
- $ tabsPanels .= sprintf ('<div class="Toolkit_TabPanel %s" data-tabs-target="tab" data-tab="%s" role="tabpanel">%s</div> ' , $ isActive ? 'active ' : '' , $ tabId , $ tabContent );
132
+ $ tabsControls .= \ sprintf ('<button class="Toolkit_TabControl" data-action="tabs#show" data-tabs-target="control" data-tabs-tab-param="%s" role="tab" aria-selected="%s">%s</button> ' , $ tabId , $ isActive ? 'true ' : 'false ' , trim ($ tabText ));
133
+ $ tabsPanels .= \ sprintf ('<div class="Toolkit_TabPanel %s" data-tabs-target="tab" data-tab="%s" role="tabpanel">%s</div> ' , $ isActive ? 'active ' : '' , $ tabId , $ tabContent );
135
134
}
136
135
137
136
return <<<HTML
@@ -141,17 +140,4 @@ private static function generateTabs(array $tabs): string
141
140
</div>
142
141
HTML ;
143
142
}
144
-
145
- private static function generateTerminal (string $ language , string $ content , string $ style = '' ): string
146
- {
147
- return <<<HTML
148
- <div class="Terminal terminal-code" style=" $ style">
149
- <div class="Terminal_body">
150
- <div class="Terminal_content">
151
- <pre><code class="language- {$ language }"> {$ content }</code></pre>
152
- </div>
153
- </div>
154
- </div>
155
- HTML ;
156
- }
157
143
}
0 commit comments