diff --git a/README.md b/README.md index 3ea5a22..26a9b9c 100644 --- a/README.md +++ b/README.md @@ -8,7 +8,7 @@ Compile vue files to twig templates with PHP |Directive|Implemented| |---------|:---------:| -|v-text|| +|v-text|:white_check_mark:| |v-html|:white_check_mark:| |v-show|:white_check_mark:| |v-if|:white_check_mark:| diff --git a/src/Compiler.php b/src/Compiler.php index 3d589dc..6a4f437 100644 --- a/src/Compiler.php +++ b/src/Compiler.php @@ -150,6 +150,7 @@ public function convertNode(DOMNode $node, int $level = 0): DOMNode $this->handleIf($node); $this->handleFor($node); $this->handleHtml($node); + $this->handleText($node); $this->stripEventHandlers($node); //$this->handleRawHtml($node, $data); $this->handleDefaultSlot($node); @@ -543,9 +544,22 @@ private function handleHtml(DOMElement $node) while ($node->hasChildNodes()) { $node->removeChild($node->firstChild); } - $node->appendChild(new DOMText('{{ ' . $html . '|raw }}')); + $node->appendChild(new DOMText('{{' . $html . '|raw}}')); } + private function handleText(DOMElement $node) + { + if (!$node->hasAttribute('v-text')) { + return; + } + + $text = $node->getAttribute('v-text'); + $node->removeAttribute('v-text'); + while ($node->hasChildNodes()) { + $node->removeChild($node->firstChild); + } + $node->appendChild(new DOMText('{{' . $text . '}}')); + } protected function addDefaultsToVariable($varName, $string): string { diff --git a/tests/VueTextTest.php b/tests/VueTextTest.php new file mode 100644 index 0000000..fddd427 --- /dev/null +++ b/tests/VueTextTest.php @@ -0,0 +1,23 @@ +createCompiler($component); + + $actual = $compiler->convert(); + + $this->assertEqualHtml($expected, $actual); + } +} diff --git a/tests/fixtures/vue-html/html.twig b/tests/fixtures/vue-html/html.twig index 56b6f9b..90b8399 100644 --- a/tests/fixtures/vue-html/html.twig +++ b/tests/fixtures/vue-html/html.twig @@ -1,6 +1,6 @@ {% set rawHtml = 'text' %}