Skip to content

Commit 681e03b

Browse files
authored
Merge pull request #16 from Paneon/feature/template-strings
Feature/template strings
2 parents 4fa9a19 + dfd89b4 commit 681e03b

File tree

5 files changed

+30
-1
lines changed

5 files changed

+30
-1
lines changed

src/Compiler.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ private function handleAttributeBinding(DOMElement $node)
224224
$templateStringContent = $matches['content'];
225225

226226
$templateStringContent = preg_replace(
227-
'/\$\{(.+)\}/',
227+
'/\$\{([^}]+)\}/',
228228
'{{ $1 }}',
229229
$templateStringContent
230230
);
@@ -398,6 +398,8 @@ protected function sanitizeCondition(string $condition)
398398
{
399399
$condition = str_replace('&&', 'and', $condition);
400400
$condition = str_replace('||', 'or', $condition);
401+
$condition = str_replace('!==', '!=', $condition);
402+
$condition = preg_replace('/!([^=])/', 'not $1', $condition);
401403

402404
foreach (Replacements::getConstants() as $constant => $value) {
403405
$condition = str_replace($value, Replacements::getSanitizedConstant($constant), $condition);
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<div class="block">
2+
<div class="block block--{{ modifier }}" style="fill: {{ color }}; height: {{ height }}">
3+
Hello World
4+
</div>
5+
</div>
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<template>
2+
<div class="block">
3+
<div :class="`block block--${modifier}`" :style="`fill: ${color}; height: ${height}`">
4+
Hello World
5+
</div>
6+
</div>
7+
</template>
8+
9+
<script>
10+
export default {
11+
props: {
12+
modifier: {
13+
type: String,
14+
required: true,
15+
},
16+
},
17+
};
18+
</script>

tests/fixtures/vue-if/simple-if-2.twig

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,7 @@
22
{% if someVar %}
33
<div>Text</div>
44
{% endif %}
5+
{% if not someVar and mobile != true %}
6+
<div>Mobile</div>
7+
{% endif %}
58
</div>

tests/fixtures/vue-if/simple-if-2.vue

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<template>
22
<div>
33
<div v-if="someVar">Text</div>
4+
<div v-if="!someVar && mobile !== true">Mobile</div>
45
</div>
56
</template>

0 commit comments

Comments
 (0)