1717
1818class ConfigurationBlockDirective extends SubDirective
1919{
20+ private const LANGUAGE_LABELS = [
21+ 'env ' => 'Bash ' ,
22+ 'html+jinja ' => 'Twig ' ,
23+ 'html+php ' => 'PHP ' ,
24+ 'html+twig ' => 'Twig ' ,
25+ 'jinja ' => 'Twig ' ,
26+ 'php ' => 'PHP ' ,
27+ 'php-annotations ' => 'Annotations ' ,
28+ 'php-attributes ' => 'Attributes ' ,
29+ 'php-standalone ' => 'Standalone PHP apps ' ,
30+ 'php-symfony ' => 'Symfony apps ' ,
31+ 'rst ' => 'RST ' ,
32+ 'terminal ' => 'Bash ' ,
33+ 'varnish3 ' => 'Varnish 3 ' ,
34+ 'varnish4 ' => 'Varnish 4 ' ,
35+ 'vcl ' => 'VCL ' ,
36+ 'xml ' => 'XML ' ,
37+ 'xml+php ' => 'XML ' ,
38+ 'yaml ' => 'YAML ' ,
39+ ];
40+
2041 public function getName (): string
2142 {
2243 return 'configuration-block ' ;
@@ -33,7 +54,8 @@ public function processSub(Parser $parser, ?Node $document, string $variable, st
3354 $ language = $ node ->getLanguage () ?? 'Unknown ' ;
3455
3556 $ blocks [] = [
36- 'language ' => $ this ->formatLanguageTab ($ language ),
57+ 'language_label ' => self ::LANGUAGE_LABELS [$ language ] ?? ucfirst (str_replace ('- ' , ' ' , $ language )),
58+ 'language ' => $ language ,
3759 'code ' => $ node ->render (),
3860 ];
3961 }
@@ -47,23 +69,4 @@ public function processSub(Parser $parser, ?Node $document, string $variable, st
4769
4870 return $ parser ->getNodeFactory ()->createWrapperNode (null , $ wrapperDiv , '</div> ' );
4971 }
50-
51- /**
52- * A hack to print exactly what we want in the tab of a configuration block.
53- */
54- private function formatLanguageTab (string $ language ): string
55- {
56- switch ($ language ) {
57- case 'php-annotations ' :
58- return 'Annotations ' ;
59- case 'php-attributes ' :
60- return 'Attributes ' ;
61- case 'xml ' :
62- case 'yaml ' :
63- case 'php ' :
64- return strtoupper ($ language );
65- default :
66- return $ language ;
67- }
68- }
6972}
0 commit comments