From bbb38c28dcecf83752321ac432f3422eb9b6aff3 Mon Sep 17 00:00:00 2001 From: mychidarko Date: Sat, 11 Feb 2023 09:36:13 +0000 Subject: [PATCH] feat: add support for embed scripts --- src/UI/Core.php | 38 ++++++++++++++------------------------ 1 file changed, 14 insertions(+), 24 deletions(-) diff --git a/src/UI/Core.php b/src/UI/Core.php index b1bacc1..add7dbd 100644 --- a/src/UI/Core.php +++ b/src/UI/Core.php @@ -11,13 +11,16 @@ */ class Core { + /**Scripts to embed into view */ + public static $scripts = []; + /** * Initialize Leaf UI on a page * @return string */ public static function init(): string { - return static::createElement('script', ['src' => '/vendor/leafs/ui/client/dist/ui.cjs.production.min.js'], ['']); + return implode(static::$scripts) . static::createElement('script', ['src' => '/vendor/leafs/ui/client/dist/ui.cjs.production.min.js'], ['']); } /** @@ -128,31 +131,15 @@ public static function compileTemplate(string $rawText, array $state = []): stri return $renderedData; }, $compiled); - $compiled = preg_replace_callback('/@for\((.*?)\)/', function ($matches) { + $compiled = preg_replace_callback('/@for\([\s\S]*?\)\s*[\s\S]*?(\s*@endfor\s*)/', function ($matches) { return ""; }, $compiled); - $compiled = preg_replace_callback('/@endfor/', function ($matches) { - return ""; - }, $compiled); - - $compiled = preg_replace_callback('/@foreach\((.*?)\)/', function ($matches) { + $compiled = preg_replace_callback('/@foreach\([\s\S]*?\)\s*[\s\S]*?(\s*@endforeach\s*)/', function ($matches) { return ""; }, $compiled); - $compiled = preg_replace_callback('/@endforeach/', function ($matches) { - return ""; - }, $compiled); - - $compiled = preg_replace_callback('/@while\((.*?)\)/', function ($matches) { - return ""; - }, $compiled); - - $compiled = preg_replace_callback('/@endwhile/', function ($matches) { - return ""; - }, $compiled); - - $compiled = preg_replace_callback('/@switch\((.*?)\)/', function ($matches) { + $compiled = preg_replace_callback('/@switch\([\s\S]*?\)\s*[\s\S]*?(\s*@endswitch\s*)/', function ($matches) { return ""; }, $compiled); @@ -164,10 +151,6 @@ public static function compileTemplate(string $rawText, array $state = []): stri return ""; }, $compiled); - $compiled = preg_replace_callback('/@endswitch/', function ($matches) { - return ""; - }, $compiled); - $compiled = preg_replace_callback('/@continue/', function ($matches) { return ""; }, $compiled); @@ -193,6 +176,13 @@ public static function compileTemplate(string $rawText, array $state = []): stri return $compiled; } + /** + * Embed a component into a view + * + * @param string $view The component to embed + * @return string + */ + /** * Create an HTML element *