From 709df5de89451e9dae1e5c8f39dd0cf6f1a5992b Mon Sep 17 00:00:00 2001 From: EnesSacid-Buker <73346401+EnesSacid-Buker@users.noreply.github.com> Date: Tue, 6 Sep 2022 17:20:35 +0300 Subject: [PATCH] Js Declaration Component added --- app/View/Components/Script/Declaration.php | 65 +++++++++++++++++++ .../components/script/declaration.blade.php | 5 ++ 2 files changed, 70 insertions(+) create mode 100644 app/View/Components/Script/Declaration.php create mode 100644 resources/views/components/script/declaration.blade.php diff --git a/app/View/Components/Script/Declaration.php b/app/View/Components/Script/Declaration.php new file mode 100644 index 000000000..712a6c61e --- /dev/null +++ b/app/View/Components/Script/Declaration.php @@ -0,0 +1,65 @@ +kind = $kind; + $this->value = $value; + + $this->scripts = $this->getScripts(); + } + + /** + * Get the view / contents that represent the component. + * + * @return \Illuminate\Contracts\View\View|string + */ + public function render() + { + return view('components.script.declaration'); + } + + protected function getScripts() + { + $scripts = ''; + + foreach ($this->value as $key => $value) { + $scripts .= $this->getScript($key, $value) . "\n"; + } + + return $scripts; + } + + protected function getScript($key, $value = null) + { + $script = $this->kind . ' ' . $key; + + if (! is_null($value)) { + $script .= ' = ' . Js::from($value)->toHtml() . ';'; + } else { + $script .= ' = ' . 'null;'; + } + + return $script; + } +} diff --git a/resources/views/components/script/declaration.blade.php b/resources/views/components/script/declaration.blade.php new file mode 100644 index 000000000..be2c2f3f3 --- /dev/null +++ b/resources/views/components/script/declaration.blade.php @@ -0,0 +1,5 @@ +@push('scripts_start') + +@endpush