Skip to content

Commit e0a9d5c

Browse files
committed
Add twig config block
1 parent a60d841 commit e0a9d5c

File tree

3 files changed

+10
-6
lines changed

3 files changed

+10
-6
lines changed

src/Compiler.php

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ class Compiler
108108
/**
109109
* @var string[]
110110
*/
111-
protected $ifAttributes = ['checked', 'selected', 'disabled'];
111+
protected $attributesWithIf = ['checked', 'selected', 'disabled'];
112112

113113

114114

@@ -231,8 +231,12 @@ public function convert(): string
231231
private function handleTwigConfig(string $twigConfig): void
232232
{
233233
$config = parse_ini_string($twigConfig);
234-
if ($config['if-attributes'] ?? false) {
235-
$this->ifAttributes = array_merge($this->ifAttributes, explode(',', $config['if-attributes']));
234+
if ($config['attributes-with-if'] ?? false) {
235+
$attributes = explode(',', $config['attributes-with-if']);
236+
foreach ($attributes as &$attribute) {
237+
$attribute = trim($attribute);
238+
}
239+
$this->attributesWithIf = array_merge($this->attributesWithIf, $attributes);
236240
}
237241
}
238242

@@ -545,7 +549,7 @@ private function handleAttributeBinding(DOMElement $node): void
545549

546550
$dynamicValues = $this->handleBinding($value, $name, $node);
547551

548-
$addIfAroundAttribute = in_array($name, $this->ifAttributes);
552+
$addIfAroundAttribute = in_array($name, $this->attributesWithIf);
549553

550554
/* @see https://gitlab.gnome.org/GNOME/libxml2/-/blob/LIBXML2.6.32/HTMLtree.c#L657 */
551555
switch ($name) {

tests/fixtures/twig-config/attribute-if-2.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
</template>
1111

1212
<twig-config>
13-
if-attributes = foo,bar
13+
attributes-with-if = foo,bar
1414
</twig-config>
1515

1616
<script>

tests/fixtures/twig-config/attribute-if.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
</template>
1111

1212
<twig-config>
13-
if-attributes = foo
13+
attributes-with-if = foo
1414
</twig-config>
1515

1616
<script>

0 commit comments

Comments
 (0)