From c6685702504ddadc69f2328f09666944dd960a3e Mon Sep 17 00:00:00 2001 From: Ibrahim BinAlshikh Date: Sun, 10 Sep 2023 21:52:51 +0300 Subject: [PATCH] Added Support for Inline JS --- tests/webfiori/test/ui/LoadTemplateTest.php | 41 +++++++++++++++++++++ tests/webfiori/test/ui/template.html | 12 ++++++ tests/webfiori/test/ui/template2.php | 14 +++++++ webfiori/ui/TemplateCompiler.php | 19 ++++++++-- 4 files changed, 83 insertions(+), 3 deletions(-) create mode 100644 tests/webfiori/test/ui/template.html create mode 100644 tests/webfiori/test/ui/template2.php diff --git a/tests/webfiori/test/ui/LoadTemplateTest.php b/tests/webfiori/test/ui/LoadTemplateTest.php index 8f3fa15..d750414 100644 --- a/tests/webfiori/test/ui/LoadTemplateTest.php +++ b/tests/webfiori/test/ui/LoadTemplateTest.php @@ -113,6 +113,7 @@ public function test07() { $node = $compiler->getCompiled(); $this->assertEquals("
\n No posts.\n
", $node->toHTML()); } + /** * @test */ @@ -135,6 +136,46 @@ public function test08() { . "" . "", $compiler->getCompiled()->toHTML()); } + /** + * @test + */ + public function test09() { + $compiler = new TemplateCompiler('template.html'); + $this->assertEquals("
= 8 || someVar === 6\">\r\n" + . " \r\n" + . "
\r\n", $compiler->getCompiled()->toHTML(true)); + } + /** + * @test + */ + public function test10() { + $compiler = new TemplateCompiler('template2.php'); + $this->assertEquals("
= 8 || someVar === 6\">\r\n" + . " \r\n" + . "
\r\n", $compiler->getCompiled()->toHTML(true)); + } /** * @test */ diff --git a/tests/webfiori/test/ui/template.html b/tests/webfiori/test/ui/template.html new file mode 100644 index 0000000..4aebd1f --- /dev/null +++ b/tests/webfiori/test/ui/template.html @@ -0,0 +1,12 @@ +
+ +
\ No newline at end of file diff --git a/tests/webfiori/test/ui/template2.php b/tests/webfiori/test/ui/template2.php new file mode 100644 index 0000000..896362d --- /dev/null +++ b/tests/webfiori/test/ui/template2.php @@ -0,0 +1,14 @@ + +
+ +
\ No newline at end of file diff --git a/webfiori/ui/TemplateCompiler.php b/webfiori/ui/TemplateCompiler.php index 9fcc1e1..bddbc7d 100644 --- a/webfiori/ui/TemplateCompiler.php +++ b/webfiori/ui/TemplateCompiler.php @@ -762,10 +762,12 @@ private static function parseAttributesHelper(Queue $queue, bool $isEqualFound, * with the hashes. */ private static function replaceAttrsValues(string $htmlStr) : array { + $scripts = []; + preg_match_all("/(?<=