Skip to content

Commit

Permalink
feat: add support for embed scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
mychidarko committed Feb 11, 2023
1 parent 310c756 commit bbb38c2
Showing 1 changed file with 14 additions and 24 deletions.
38 changes: 14 additions & 24 deletions src/UI/Core.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'], ['']);
}

/**
Expand Down Expand Up @@ -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 "<?php for ($matches[1]): ?>";
}, $compiled);

$compiled = preg_replace_callback('/@endfor/', function ($matches) {
return "<?php endfor; ?>";
}, $compiled);

$compiled = preg_replace_callback('/@foreach\((.*?)\)/', function ($matches) {
$compiled = preg_replace_callback('/@foreach\([\s\S]*?\)\s*[\s\S]*?(\s*@endforeach\s*)/', function ($matches) {
return "<?php foreach ($matches[1]): ?>";
}, $compiled);

$compiled = preg_replace_callback('/@endforeach/', function ($matches) {
return "<?php endforeach; ?>";
}, $compiled);

$compiled = preg_replace_callback('/@while\((.*?)\)/', function ($matches) {
return "<?php while ($matches[1]): ?>";
}, $compiled);

$compiled = preg_replace_callback('/@endwhile/', function ($matches) {
return "<?php endwhile; ?>";
}, $compiled);

$compiled = preg_replace_callback('/@switch\((.*?)\)/', function ($matches) {
$compiled = preg_replace_callback('/@switch\([\s\S]*?\)\s*[\s\S]*?(\s*@endswitch\s*)/', function ($matches) {
return "<?php switch ($matches[1]): ?>";
}, $compiled);

Expand All @@ -164,10 +151,6 @@ public static function compileTemplate(string $rawText, array $state = []): stri
return "<?php break; ?>";
}, $compiled);

$compiled = preg_replace_callback('/@endswitch/', function ($matches) {
return "<?php endswitch; ?>";
}, $compiled);

$compiled = preg_replace_callback('/@continue/', function ($matches) {
return "<?php continue; ?>";
}, $compiled);
Expand All @@ -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
*
Expand Down

0 comments on commit bbb38c2

Please sign in to comment.