Skip to content

Commit 6ccc2ef

Browse files
committed
Merge branch 'master' into develop
# Conflicts: # src/Utils/TwigBuilder.php
2 parents 3a6b887 + ec1b371 commit 6ccc2ef

File tree

4 files changed

+63
-2
lines changed

4 files changed

+63
-2
lines changed

src/Utils/TwigBuilder.php

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,9 @@ public function createBlock($content)
9696

9797
/**
9898
* @param string $partialPath
99-
* @param Property[] $variables
99+
* @param Property[] $variables
100+
*
101+
* @return string
100102
*/
101103
public function createIncludePartial(string $partialPath, array $variables = [])
102104
{
@@ -108,12 +110,29 @@ public function createIncludePartial(string $partialPath, array $variables = [])
108110

109111
/** @var Property $property */
110112
foreach ($variables as $property) {
111-
$props[] = $property->getName().': '.$property->getValue();
113+
if($property->getName() !== 'key') {
114+
$value = $this->checkPropertyValue($property->getValue());
115+
$props[] = $property->getName().': '.$value;
116+
}
112117
}
113118

114119
return $this->createBlock('include "'.$partialPath.'" with { '.implode(', ', $props).' }');
115120
}
116121

122+
public function checkPropertyValue($value)
123+
{
124+
if (preg_match('/^`(?P<content>.+)`$/', $value, $matches)) {
125+
$templateStringContent = '"'.$matches['content'].'"';
126+
$value = preg_replace(
127+
'/\$\{(.+)\}/',
128+
'{{ $1 }}',
129+
$templateStringContent
130+
);
131+
}
132+
133+
return $value;
134+
}
135+
117136
public function refactorCondition(string $condition): string
118137
{
119138
$condition = str_replace('===', '==', $condition);

tests/VueComponentBindingTest.php

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?php
2+
3+
namespace Paneon\VueToTwig\Tests;
4+
5+
class VueComponentBindingTest extends AbstractTestCase
6+
{
7+
/**
8+
* @dataProvider dataProvider
9+
* @throws \Exception
10+
*/
11+
public function testComponentBinding($html, $expected)
12+
{
13+
$compiler = $this->createCompiler($html);
14+
15+
$compiler->registerComponent('ChildComponent', '/templates/ChildComponent.twig');
16+
17+
$actual = $compiler->convert();
18+
19+
$this->assertEqualHtml($expected, $actual);
20+
}
21+
22+
public function dataProvider()
23+
{
24+
return $this->loadFixturesFromDir('vue-component');
25+
}
26+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<div>
2+
{% include "/templates/ChildComponent.twig" with { style: "fill:{{ color }};", test: "test" } %}
3+
</div>
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<template>
2+
<div>
3+
<ChildComponent :style="`fill:${color};`" :key=testkey test="test" />
4+
</div>
5+
</template>
6+
<script>
7+
export default {
8+
name: 'component-with-child-binding.vue',
9+
component: {
10+
ChildComponent,
11+
}
12+
};
13+
</script>

0 commit comments

Comments
 (0)