From 64dad0aaf905f89e7ef7b0e7062c47e18d0f3608 Mon Sep 17 00:00:00 2001 From: Kavalar Date: Thu, 9 Jan 2025 17:13:22 +0300 Subject: [PATCH] assets class --- kernel/Assets.php | 66 +++++++++++++++++++ .../default/DefaultAdminThemeAssets.php | 25 +++++++ kernel/admin_themes/default/layout/main.php | 11 ++-- 3 files changed, 95 insertions(+), 7 deletions(-) create mode 100644 kernel/Assets.php create mode 100644 kernel/admin_themes/default/DefaultAdminThemeAssets.php diff --git a/kernel/Assets.php b/kernel/Assets.php new file mode 100644 index 0000000..30c2c8b --- /dev/null +++ b/kernel/Assets.php @@ -0,0 +1,66 @@ +setResourceURI($resourceURI); + $this->createCSS(); + $this->createJS(); + } + + protected function createCSS(){} + protected function createJS(){} + + public function setResourceURI(string $resourceURI): void + { + $this->resourceURI = $resourceURI; + } + + public function registerJS(string $slug, string $resource, bool $body = true, bool $addResourceURI = true): void + { + $resource = $addResourceURI ? $this->resourceURI . $resource : $resource; + if ($body) { + $this->jsBody[$slug] = $resource; + } else { + $this->jsHeader[$slug] = $resource; + } + } + + public function registerCSS(string $slug, string $resource, bool $addResourceURI = true): void + { + $resource = $addResourceURI ? $this->resourceURI . $resource : $resource; + $this->css[$slug] = $resource; + } + + public function getJSAsStr(bool $body = true): void + { + if ($body) { + foreach ($this->jsBody as $key => $item){ + echo ""; + } + } + else { + foreach ($this->jsHeader as $key => $item){ + echo ""; + } + } + } + + public function getCSSAsSTR(): void + { + foreach ($this->css as $key => $item){ + echo ""; + } + } + +} \ No newline at end of file diff --git a/kernel/admin_themes/default/DefaultAdminThemeAssets.php b/kernel/admin_themes/default/DefaultAdminThemeAssets.php new file mode 100644 index 0000000..7c5cf70 --- /dev/null +++ b/kernel/admin_themes/default/DefaultAdminThemeAssets.php @@ -0,0 +1,25 @@ +registerJS(slug: "jquery", resource: "/js/jquery.min.js"); + $this->registerJS(slug: "popper", resource: "/js/popper.js"); + $this->registerJS(slug: "bootstrap", resource: "/js/bootstrap.min.js"); + $this->registerJS(slug: "main", resource: "/js/main.js"); + } + + protected function createCSS() + { + $this->registerCSS(slug: "font-awesome", resource: "https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.6.0/css/all.min.css", addResourceURI: false); + $this->registerCSS(slug: "bootstrap", resource: "/css/bootstrap.min.css"); + $this->registerCSS(slug: "style", resource: "/css/style.css"); + } + +} \ No newline at end of file diff --git a/kernel/admin_themes/default/layout/main.php b/kernel/admin_themes/default/layout/main.php index 98be7fb..a015dda 100644 --- a/kernel/admin_themes/default/layout/main.php +++ b/kernel/admin_themes/default/layout/main.php @@ -6,6 +6,7 @@ * @var \kernel\CgView $view */ \Josantonius\Session\Facades\Session::start(); +$assets = new \kernel\admin_themes\default\DefaultAdminThemeAssets($resources) ?> @@ -17,9 +18,8 @@ - - - + getCSSAsSTR(); ?> + getJSAsStr(body: false); ?> @@ -92,9 +92,6 @@ - - - - +getJSAsStr(); ?> \ No newline at end of file