17
17
18
18
class ConfigurationBlockDirective extends SubDirective
19
19
{
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
+
20
41
public function getName (): string
21
42
{
22
43
return 'configuration-block ' ;
@@ -33,7 +54,8 @@ public function processSub(Parser $parser, ?Node $document, string $variable, st
33
54
$ language = $ node ->getLanguage () ?? 'Unknown ' ;
34
55
35
56
$ blocks [] = [
36
- 'language ' => $ this ->formatLanguageTab ($ language ),
57
+ 'language_label ' => self ::LANGUAGE_LABELS [$ language ] ?? ucfirst (str_replace ('- ' , ' ' , $ language )),
58
+ 'language ' => $ language ,
37
59
'code ' => $ node ->render (),
38
60
];
39
61
}
@@ -47,23 +69,4 @@ public function processSub(Parser $parser, ?Node $document, string $variable, st
47
69
48
70
return $ parser ->getNodeFactory ()->createWrapperNode (null , $ wrapperDiv , '</div> ' );
49
71
}
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
- }
69
72
}
0 commit comments