Skip to content

Commit 7c86072

Browse files
committed
minor #1948 [Site] Custom TwigCsFixer config (smnandre)
This PR was merged into the 2.x branch. Discussion ---------- [Site] Custom TwigCsFixer config (will be rebased after #1947) Answering you here `@VincentLanglet` (regarding #1935 (comment)) Would this be the "good/safe" way to go... ? ...or should we create a Standard (and just customize the demo/memory thing here) ? Commits ------- 8a66e74 [Site] Custom TwigCsFixer config
2 parents e1d2f19 + 8a66e74 commit 7c86072

File tree

8 files changed

+49
-10
lines changed

8 files changed

+49
-10
lines changed
Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,44 @@
11
<?php
22

3-
$config = new TwigCsFixer\Config\Config();
3+
use TwigCsFixer\Rules\Delimiter\BlockNameSpacingRule;
4+
use TwigCsFixer\Rules\File\DirectoryNameRule;
5+
use TwigCsFixer\Rules\File\FileExtensionRule;
6+
use TwigCsFixer\Rules\File\FileNameRule;
7+
use TwigCsFixer\Rules\Function\IncludeFunctionRule;
8+
use TwigCsFixer\Rules\Punctuation\TrailingCommaSingleLineRule;
9+
use TwigCsFixer\Rules\String\SingleQuoteRule;
10+
use TwigCsFixer\Rules\Variable\VariableNameRule;
11+
use TwigCsFixer\Rules\Whitespace\EmptyLinesRule;
12+
use TwigCsFixer\Rules\Whitespace\TrailingSpaceRule;
13+
use TwigCsFixer\Ruleset\Ruleset;
14+
use TwigCsFixer\Rules\Whitespace\BlankEOFRule;
15+
use TwigCsFixer\Standard\Twig;
16+
17+
$uxRuleset = (new Ruleset())
18+
->addStandard(new Twig())
19+
// Symfony standard (customized for Symfony UX)
20+
->addRule(new DirectoryNameRule(baseDirectory: 'templates', ignoredSubDirectories: ['bundles', 'components', 'demos/live_memory/components']))
21+
->addRule(new FileNameRule(baseDirectory: 'templates', ignoredSubDirectories: ['bundles', 'components', 'demos/live_memory/components'], optionalPrefix: '_'))
22+
->addRule(new DirectoryNameRule(case: DirectoryNameRule::PASCAL_CASE, baseDirectory: 'templates/components'))
23+
->addRule(new FileNameRule(case: DirectoryNameRule::PASCAL_CASE, baseDirectory: 'templates/components'))
24+
->addRule(new DirectoryNameRule(case: DirectoryNameRule::PASCAL_CASE, baseDirectory: 'demos/live_memory/components'))
25+
->addRule(new FileNameRule(case: DirectoryNameRule::PASCAL_CASE, baseDirectory: 'demos/live_memory/components'))
26+
->addRule(new FileExtensionRule())
27+
// TwigCsFixer standard (customized for Symfony UX)
28+
->addRule(new BlankEOFRule())
29+
->addRule(new BlockNameSpacingRule())
30+
->addRule(new EmptyLinesRule())
31+
->addRule(new IncludeFunctionRule())
32+
->addRule(new SingleQuoteRule())
33+
->addRule(new TrailingSpaceRule())
34+
->addRule(new TrailingCommaSingleLineRule())
35+
->overrideRule(new VariableNameRule(VariableNameRule::SNAKE_CASE, '_'))
36+
;
37+
38+
$config = (new TwigCsFixer\Config\Config('Symfony UX'))
39+
->setRuleset($uxRuleset)
40+
->allowNonFixableRules()
41+
->setCacheFile(null)
42+
;
443

544
return $config;

ux.symfony.com/templates/components/Code/CodeLine.html.twig

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
class="IconModal__code"
55
data-controller="clipboarder"
66
>
7-
{% set __code -%}
7+
{% set _code -%}
88
{% block content -%}
99
{{ code ? code|trim|raw }}
1010
{%- endblock -%}
@@ -13,9 +13,9 @@
1313
<pre
1414
{% if height %} style="--height: {{ height }}" {% endif %}
1515
data-clipboarder-target="source"
16-
><code>{{ __code ? __code|trim|raw : code }}</code></pre>
16+
><code>{{ _code ? _code|trim|raw : code }}</code></pre>
1717

18-
<button class="btn btn-sm IconModal__copy" data-action="clipboarder#copy" data-clipboarder-target="button">
18+
<button class="btn btn-sm IconModalcopy" data-action="clipboarder#copy" data-clipboarder-target="button">
1919
<twig:Icon name="copy" />
2020
</button>
2121
</div>

ux.symfony.com/templates/ux_packages/turbo.html.twig

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
courtesy of <a class="font-white text-underline" href="https://turbo.hotwired.dev/" rel="external noopener noreferrer">Turbo</a>
1515

1616
<div style="position: absolute; bottom: 4rem; left: 50%; transform: translateX(-50%);color: white;">
17-
{{ include('ux_packages/turbo/_chatMessageCount.html.twig', {messageCount: this.messageCount}) }}
17+
{{ include('ux_packages/turbo/_chat_message_count.html.twig', {messageCount: this.messageCount}) }}
1818
</div>
1919
{% endblock %}
2020

@@ -128,14 +128,14 @@
128128
{% block content %}
129129
<div style="height: 150px; overflow: auto;">
130130
<ul class="list-unstyled" id="chat-box">
131-
{{ include('ux_packages/turbo/_chatList.html.twig') }}
131+
{{ include('ux_packages/turbo/_chat_list.html.twig') }}
132132
</ul>
133133
</div>
134134
{% endblock %}
135135
{% block content_secondary %}
136136
<div class="DemoContainer-inner p-4">
137137
<form id="chat-form" action="{{ path('app_turbo_chat') }}" method="POST">
138-
{{ include('ux_packages/turbo/_chatForm.html.twig') }}
138+
{{ include('ux_packages/turbo/_chat_form.html.twig') }}
139139
</form>
140140
</div>
141141
{% endblock %}
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
<turbo-stream action="update" target="chat-box">
22
<template>
3-
{{ include('ux_packages/turbo/_chatList.html.twig') }}
3+
{{ include('ux_packages/turbo/_chat_list.html.twig') }}
44
</template>
55
</turbo-stream>
66

77
<turbo-stream action="replace" target="message-count-header">
88
<template>
9-
{{ include('ux_packages/turbo/_chatMessageCount.html.twig') }}
9+
{{ include('ux_packages/turbo/_chat_message_count.html.twig') }}
1010
</template>
1111
</turbo-stream>
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<turbo-stream action="update" target="chat-form">
22
<template>
3-
{{ include('ux_packages/turbo/_chatForm.html.twig') }}
3+
{{ include('ux_packages/turbo/_chat_form.html.twig') }}
44
</template>
55
</turbo-stream>

0 commit comments

Comments
 (0)