1212namespace App \Service \Toolkit ;
1313
1414use App \Enum \ToolkitKitId ;
15- use App \Util \ SourceCleaner ;
15+ use App \Service \ CommonMark \ Extension \ CodeBlockRenderer \ CodeBlockRenderer ;
1616use Symfony \Component \DependencyInjection \Attribute \Autowire ;
1717use Symfony \Component \Filesystem \Path ;
1818use Symfony \Component \HttpFoundation \UriSigner ;
2121use Symfony \UX \Toolkit \Installer \PoolResolver ;
2222use Symfony \UX \Toolkit \Kit \Kit ;
2323use Symfony \UX \Toolkit \Registry \RegistryFactory ;
24- use function Symfony \Component \String \s ;
2524
2625class ToolkitService
2726{
2827 public function __construct (
2928 #[Autowire(service: 'ux_toolkit.registry.registry_factory ' )]
3029 private readonly RegistryFactory $ registryFactory ,
3130 private readonly UriSigner $ uriSigner ,
32- private readonly UrlGeneratorInterface $ urlGenerator
31+ private readonly UrlGeneratorInterface $ urlGenerator,
3332 ) {
3433 }
3534
@@ -76,41 +75,41 @@ public function renderComponentPreviewCodeTabs(ToolkitKitId $kitId, string $code
7675 </div>
7776 <iframe class="Toolkit_Preview loading" src=" {$ previewUrl }" style="height: {$ height };" loading="lazy" onload="this.previousElementSibling.style.display = 'none'; this.classList.remove('loading')"></iframe>
7877 HTML ,
79- 'Code ' => $ highlightedCode
78+ 'Code ' => $ highlightedCode,
8079 ]);
8180 }
8281
8382 public function renderInstallationSteps (ToolkitKitId $ kitId , Component $ component ): string
8483 {
8584 $ kit = $ this ->getKit ($ kitId );
86- $ pool = (new PoolResolver )->resolveForComponent ($ kit , $ component );
85+ $ pool = (new PoolResolver () )->resolveForComponent ($ kit , $ component );
8786
8887 $ manual = '<p>The UX Toolkit is not mandatory to install a component. You can install it manually by following the next steps:</p> ' ;
8988 $ 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> ' ;
9190 foreach ($ pool ->getFiles () as $ file ) {
92- $ manual .= sprintf (
91+ $ manual .= \ sprintf (
9392 "<details><summary><code>%s</code></summary> \n%s \n</details> " ,
9493 $ 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 ))))
9695 );
9796 }
9897 $ manual .= '</li> ' ;
9998
10099 if ($ phpPackageDependencies = $ pool ->getPhpPackageDependencies ()) {
101100 $ 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 ' );
103102 $ manual .= '</li> ' ;
104103 }
105104
106105 $ manual .= '<li><strong>And the most important, enjoy!</strong></li> ' ;
107106 $ manual .= '</ol> ' ;
108107
109108 return $ this ->generateTabs ([
110- 'Automatic ' => sprintf (
109+ 'Automatic ' => \ sprintf (
111110 '<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 }" ),
114113 ),
115114 'Manual ' => $ manual ,
116115 ]);
@@ -130,8 +129,8 @@ private static function generateTabs(array $tabs): string
130129 $ activeTabId ??= $ tabId ;
131130 $ isActive = $ activeTabId === $ tabId ;
132131
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 );
135134 }
136135
137136 return <<<HTML
@@ -141,17 +140,4 @@ private static function generateTabs(array $tabs): string
141140</div>
142141HTML ;
143142 }
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- }
157143}
0 commit comments