Skip to content

Commit 471c065

Browse files
committed
Merge branch 'feature/include-style' into feature/named-slots
2 parents a5ece2b + 3ddb7a7 commit 471c065

File tree

7 files changed

+26
-20
lines changed

7 files changed

+26
-20
lines changed

src/Compiler.php

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -301,25 +301,26 @@ private function preparePropertiesForInclude(array $variables): array
301301
{
302302
$values = [];
303303
foreach ($variables as $key => $variable) {
304-
if (in_array($variable->getName(), $this->includeAttributes)) {
304+
$name = $variable->getName();
305+
$value = $variable->getValue();
306+
if (in_array($name, $this->includeAttributes)) {
305307
if ($variable->isBinding()) {
306-
$values[$variable->getName()][] = $this->handleBinding(
307-
$variable->getValue(),
308-
$variable->getName(),
309-
null,
310-
false
311-
)[0];
308+
$values[$name][] = $this->handleBinding($value, $name, null, false)[0];
312309
} else {
313-
$values[$variable->getName()][] = $variable->getValue();
310+
$values[$name][] = $value;
314311
}
315312
unset($variables[$key]);
316313
}
317314
}
318315

319316
foreach ($this->includeAttributes as $attribute) {
317+
$glue = ' ~ " " ~ ';
318+
if ($attribute === 'style') {
319+
$glue = ' ~ "; " ~ ';
320+
}
320321
$variables[] = new Property(
321322
$attribute,
322-
$values[$attribute] ?? null ? implode(' ~ " " ~ ', $values[$attribute]) : '""',
323+
$values[$attribute] ?? null ? implode($glue, $values[$attribute]) : '""',
323324
false
324325
);
325326
}
@@ -709,17 +710,20 @@ private function stripEventHandlers(DOMElement $node): void
709710
*/
710711
protected function implodeAttributeValue(string $attribute, array $values, string $oldValue): string
711712
{
712-
$glue = ' ';
713-
714713
if ($attribute === 'style') {
715-
$glue = '; ';
714+
if (!empty($oldValue)) {
715+
$oldValue = trim($oldValue, ';') . ';';
716+
}
717+
foreach ($values as &$value) {
718+
$value = trim($value, ';') . ';';
719+
}
716720
}
717721

718722
if (!empty($oldValue)) {
719723
$values = array_merge([$oldValue], $values);
720724
}
721725

722-
return implode($glue, $values);
726+
return trim(implode(' ', $values));
723727
}
724728

725729
/**
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<div class="block {{ class|default('') }}" style="{{ style|default('') }}">
2-
<div class="block block--{{ modifier }}" style="fill: {{ color }}; height: {{ height }}">
2+
<div class="block block--{{ modifier }}" style="fill: {{ color }}; height: {{ height }};">
33
Hello World
44
</div>
55
</div>
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<div class="block {{ class|default('') }}" style="{{ style|default('') }}">
2-
<div class="block block--{{ modifier }}" style="fill: {{ color }}">
2+
<div class="block block--{{ modifier }}" style="fill: {{ color }};">
33
Hello World
44
</div>
55
<div class="{{ isTrue ? 'a' : 'b' }}"></div>
6-
<div style="{{ isTrue ? 'display: block;' : 'display: none !important;' }}"></div>
6+
<div style="{{ isTrue ? 'display: block' : 'display: none !important' }};"></div>
77
</div>

tests/fixtures/vue-bind/binding-with-template-string.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
Hello World
55
</div>
66
<div :class="`${isTrue ? 'a' : 'b'}`"></div>
7-
<div :style="`${isTrue ? 'display: block;' : 'display: none !important;'}`"></div>
7+
<div :style="`${isTrue ? 'display: block' : 'display: none !important'}`"></div>
88
</div>
99
</template>
1010

tests/fixtures/vue-bind/bindings.twig

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@
66
<div class="a b c"></div>
77
<div title="Title" class="category-filter-list categories {{ isSomething ? 'block ' }} {{ not isSomething ? 'block2 ' }}"></div>
88
<div class="{{ getClasses(not hasSomething) }}"></div>
9-
<div style="{{ 'display: none !important' }}">Hidden</div>
10-
<div style="color: red; {{ 'display: none !important' }}">Hidden</div>
11-
<div style="border: 1px solid #000000; {{ isSomething ? 'color: red ' }}; {{ not isSomething ? 'color: blue ' }}">Hidden</div>
9+
<div style="{{ 'display: none !important' }};">Hidden</div>
10+
<div style="color: red; {{ 'display: none !important' }};">Hidden</div>
11+
<div style="border: 1px solid #000000; {{ isSomething ? 'color: red ' }}; {{ not isSomething ? 'color: blue ' }};">Hidden</div>
1212
<div class="{{ bar ? 'foo ' }}"></div>
1313
<div class="{{ bar ? 'foo ' }}"></div>
1414
</div>

tests/fixtures/vue-component/component-with-child-binding.twig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<div class="{{ class|default('') }}" style="{{ style|default('') }}">
22
{% include "/templates/ChildComponent.twig" with { 'test': "test", 'class': "", 'style': ( "fill:" ~ ( color ) ~ ";" ) } %}
3+
{% include "/templates/ChildComponent.twig" with { 'class': "", 'style': "color: red" ~ "; " ~ ( "fill:" ~ ( color ) ~ ";" ) } %}
34
{% include "/templates/ChildComponent.twig" with { 'class': "foo" ~ " " ~ ( "bar" ), 'style': "" } %}
45
{% include "/templates/ChildComponent.twig" with { 'class': "foo" ~ " " ~ ( bar ), 'style': "" } %}
56
{% include "/templates/ChildComponent.twig" with { 'class': "product-column__tile" ~ " " ~ ( isSingleProductTile ? 'product-column__tile--large ' ), 'style': "" } %}

tests/fixtures/vue-component/component-with-child-binding.vue

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<template>
22
<div>
33
<ChildComponent :style="`fill:${color};`" :key=testkey test="test" />
4+
<ChildComponent style="color: red" :style="`fill:${color};`" />
45
<ChildComponent class="foo" :class="`bar`" />
56
<ChildComponent class="foo" :class="bar" />
67
<ChildComponent class="product-column__tile" :class="{'product-column__tile--large': isSingleProductTile }" />

0 commit comments

Comments
 (0)