From 8cf06f9e142b5ba3254bccfa6ac3787e59c278dd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stefan=20H=C3=BCsges?= Date: Thu, 30 Jan 2020 15:44:14 +0100 Subject: [PATCH 1/6] ADD v-html --- tests/VueHtmlTest.php | 23 +++++++++++++++++++++++ tests/fixtures/vue-html/html.twig | 8 ++++++++ tests/fixtures/vue-html/html.vue | 19 +++++++++++++++++++ 3 files changed, 50 insertions(+) create mode 100644 tests/VueHtmlTest.php create mode 100644 tests/fixtures/vue-html/html.twig create mode 100644 tests/fixtures/vue-html/html.vue diff --git a/tests/VueHtmlTest.php b/tests/VueHtmlTest.php new file mode 100644 index 0000000..d905896 --- /dev/null +++ b/tests/VueHtmlTest.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 new file mode 100644 index 0000000..42f3370 --- /dev/null +++ b/tests/fixtures/vue-html/html.twig @@ -0,0 +1,8 @@ +{% set rawHtml = 'text' %} + diff --git a/tests/fixtures/vue-html/html.vue b/tests/fixtures/vue-html/html.vue new file mode 100644 index 0000000..a993694 --- /dev/null +++ b/tests/fixtures/vue-html/html.vue @@ -0,0 +1,19 @@ + + + + {% set rawHtml = 'text' %} + + + From 1693a4a16e846532ecc03c1d6ce69ad17edc0076 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stefan=20H=C3=BCsges?= Date: Mon, 10 Feb 2020 17:45:47 +0100 Subject: [PATCH 2/6] Add handleHtml --- src/Compiler.php | 16 ++++++++++++++++ tests/fixtures/vue-html/html.twig | 12 +++++------- tests/fixtures/vue-html/html.vue | 2 +- 3 files changed, 22 insertions(+), 8 deletions(-) diff --git a/src/Compiler.php b/src/Compiler.php index 6b8c33d..deeedde 100644 --- a/src/Compiler.php +++ b/src/Compiler.php @@ -149,6 +149,7 @@ public function convertNode(DOMNode $node, int $level = 0): DOMNode $this->replaceShowWithIf($node); $this->handleIf($node); $this->handleFor($node); + $this->handleHtml($node); $this->stripEventHandlers($node); //$this->handleRawHtml($node, $data); $this->handleDefaultSlot($node); @@ -521,6 +522,21 @@ private function handleFor(DOMElement $node) $node->removeAttribute('v-for'); } + private function handleHtml(DOMElement $node) + { + if (!$node->hasAttribute('v-html')) { + return; + } + + $html = $node->getAttribute('v-html'); + $node->removeAttribute('v-html'); + while ($node->hasChildNodes()) { + $node->removeChild($node->firstChild); + } + $node->appendChild(new DOMText('{{ ' . $html . '|raw }}')); + } + + protected function addDefaultsToVariable($varName, $string): string { if (!in_array($varName, array_keys($this->properties))) { diff --git a/tests/fixtures/vue-html/html.twig b/tests/fixtures/vue-html/html.twig index 42f3370..56b6f9b 100644 --- a/tests/fixtures/vue-html/html.twig +++ b/tests/fixtures/vue-html/html.twig @@ -1,8 +1,6 @@ {% set rawHtml = 'text' %} - +
+ + {{ rawHtml|raw }} + +
diff --git a/tests/fixtures/vue-html/html.vue b/tests/fixtures/vue-html/html.vue index a993694..b6be55d 100644 --- a/tests/fixtures/vue-html/html.vue +++ b/tests/fixtures/vue-html/html.vue @@ -5,7 +5,7 @@ - {% set rawHtml = 'text' %} + {% set rawHtml = '<strong>text</strong>' %}