Skip to content

Commit 7cf0041

Browse files
authored
Merge pull request #38 from Paneon/master
Update master
2 parents 2a78d16 + d4d57a8 commit 7cf0041

11 files changed

+69
-18
lines changed

.github/workflows/php.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@ jobs:
2626
restore-keys: |
2727
${{ runner.os }}-php-
2828
29+
- name: Composer update
30+
run: composer update
31+
2932
- name: Install dependencies
3033
if: steps.composer-cache.outputs.cache-hit != 'true'
3134
run: composer install --prefer-dist --no-progress --no-suggest

src/Compiler.php

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -232,10 +232,7 @@ public function convert(): string
232232
}
233233

234234
$this->rawBlocks[] = $this->createVariableBlock();
235-
236-
if (count($this->rawBlocks)) {
237-
$html = implode("\n", $this->rawBlocks) . "\n" . $html;
238-
}
235+
$html = implode("\n", $this->rawBlocks) . "\n" . $html;
239236

240237
$html = $this->replacePlaceholders($html);
241238
$html = $this->replaceScopedPlaceholders($html);
@@ -440,13 +437,20 @@ private function preparePropertiesForInclude(array $variables, bool $isRootNode
440437
} elseif ($name === '__DATA_SCOPED_STYLE_ATTRIBUTE__') {
441438
unset($variables[$key]);
442439
if ($hasScopedStyleAttribute) {
443-
continue;
440+
foreach ($variables as $variable) {
441+
if ($variable->getName() === 'dataScopedStyleAttribute') {
442+
$variable->setValue(
443+
$variable->getValue() . ' ~ " " ~ dataScopedStyleAttribute|default(\'\')'
444+
);
445+
}
446+
}
447+
} else {
448+
$variables[] = new Property(
449+
'dataScopedStyleAttribute',
450+
'dataScopedStyleAttribute|default(\'\')',
451+
false
452+
);
444453
}
445-
$variables[] = new Property(
446-
'dataScopedStyleAttribute',
447-
'dataScopedStyleAttribute|default(\'\')',
448-
false
449-
);
450454
} elseif ($name === 'vBind') {
451455
$this->vBind = $value;
452456
unset($variables[$key]);
@@ -458,17 +462,13 @@ private function preparePropertiesForInclude(array $variables, bool $isRootNode
458462
if ($attribute === 'style') {
459463
$glue = ' ~ "; " ~ ';
460464
}
461-
$value = $values[$attribute] ?? null ? implode($glue, $values[$attribute]) : '""';
462465
if ($isRootNode) {
463-
$value = $value . $glue . $attribute . '|default(\'\')';
466+
$values[$attribute][] = $attribute . '|default(\'\')';
464467
}
468+
$value = $values[$attribute] ?? null ? implode($glue, $values[$attribute]) : '""';
465469
$variables[] = new Property($attribute, $value, false);
466470
}
467471

468-
if ($isRootNode) {
469-
$variables[] = new Property('dataScopedStyleAttribute', 'dataScopedStyleAttribute|default(\'\')', false);
470-
}
471-
472472
return $variables;
473473
}
474474

src/Models/Property.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,12 @@ public function getValue(): string
5858
return $this->value;
5959
}
6060

61+
public function setValue(string $value): Property
62+
{
63+
$this->value = $value;
64+
return $this;
65+
}
66+
6167
public function isBinding(): bool
6268
{
6369
return $this->isBinding;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
<style> .foo[data-v-858c11a91dcdf48f12d9b6c5ca636873] { color: purple; }</style>
2+
{% include "/templates/ChildComponent.twig" with { 'slot_default': "", 'dataScopedStyleAttribute': "data-v-858c11a91dcdf48f12d9b6c5ca636873" ~ " " ~ dataScopedStyleAttribute|default(''), 'class': "foo" ~ " " ~ class|default(''), 'style': "color: black" ~ "; " ~ style|default('') } %}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<template>
2+
<ChildComponent class="foo" style="color: black" />
3+
</template>
4+
5+
<script>
6+
export default {
7+
name: 'ComponentWithComponentOnRoot',
8+
component: {
9+
ChildComponent,
10+
}
11+
};
12+
</script>
13+
14+
<style scoped>
15+
.foo {
16+
color: purple;
17+
}
18+
</style>
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{% include "/templates/ChildComponent.twig" with { 'slot_default': "", 'dataScopedStyleAttribute': dataScopedStyleAttribute|default(''), 'class': "foo" ~ " " ~ class|default(''), 'style': "color: black" ~ "; " ~ style|default('') } %}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
<style> .foo[data-v-858c11a91dcdf48f12d9b6c5ca636873] { color: purple; }</style>
2+
<div data-v-858c11a91dcdf48f12d9b6c5ca636873 {{ dataScopedStyleAttribute|default('') }} class="{{ class|default('') }}" style="{{ style|default('') }}">{% include "/templates/ChildComponent.twig" with { 'slot_default': "", 'dataScopedStyleAttribute': "data-v-858c11a91dcdf48f12d9b6c5ca636873", 'class': "foo", 'style': "color: black" } %}</div>
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<template>
2+
<div>
3+
<ChildComponent class="foo" style="color: black" />
4+
</div>
5+
</template>
6+
7+
<script>
8+
export default {
9+
name: 'ComponentWithComponentOnRoot',
10+
component: {
11+
ChildComponent,
12+
}
13+
};
14+
</script>
15+
16+
<style scoped>
17+
.foo {
18+
color: purple;
19+
}
20+
</style>

tests/fixtures/vue-slot/include-child-component-with-component-on-root.twig

Lines changed: 0 additions & 1 deletion
This file was deleted.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
{% set text = text|default('foo') %}
22
{% set slot_default_fallback %}{{ text }}{% endset %}
33
{% set slot_default_value %}{{ slot_default|default(slot_default_fallback) }}{% endset %}
4-
{% include "/templates/ChildComponent.twig" with { 'slot_default': slot_default_value, 'class': "", 'style': "" } %}
4+
{% include "/templates/ChildComponent.twig" with { 'slot_default': slot_default_value, 'class': class|default(''), 'style': style|default('') } %}

0 commit comments

Comments
 (0)