Skip to content

Commit 27e52ac

Browse files
Refactor code
1 parent 0824a23 commit 27e52ac

File tree

1 file changed

+35
-51
lines changed

1 file changed

+35
-51
lines changed

src/Assets.php

Lines changed: 35 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -189,11 +189,7 @@ public function getScripts($location = null)
189189
$scripts = array_merge($scripts, $this->getScriptItem($location, $configName, $script));
190190
}
191191

192-
if (isset($this->appendedScripts[$location])) {
193-
$scripts = array_merge($scripts, $this->appendedScripts[$location]);
194-
}
195-
196-
return $scripts;
192+
return array_merge($scripts, array_get($this->appendedScripts, $location, []));
197193
}
198194

199195
/**
@@ -241,35 +237,6 @@ public function styleToHtml($name)
241237
return $this->itemToHtml($name, 'style');
242238
}
243239

244-
/**
245-
* Render assets to header.
246-
*
247-
* @param array $lastStyles
248-
* @return string
249-
* @throws \Throwable
250-
*/
251-
public function renderHeader($lastStyles = [])
252-
{
253-
$styles = $this->getStyles($lastStyles);
254-
255-
$headScripts = $this->getScripts(self::ASSETS_SCRIPT_POSITION_HEADER);
256-
257-
return view('assets::header', compact('styles', 'headScripts'))->render();
258-
}
259-
260-
/**
261-
* Render assets to footer.
262-
*
263-
* @return string
264-
* @throws \Throwable
265-
*/
266-
public function renderFooter()
267-
{
268-
$bodyScripts = $this->getScripts(self::ASSETS_SCRIPT_POSITION_FOOTER);
269-
270-
return view('assets::footer', compact('bodyScripts'))->render();
271-
}
272-
273240
/**
274241
* Get script item.
275242
*
@@ -289,22 +256,6 @@ protected function getScriptItem($location, $configName, $script)
289256
return $scripts;
290257
}
291258

292-
/**
293-
* Fallback to local script if CDN fails.
294-
*
295-
* @param string $src
296-
* @param string $configName
297-
* @return array
298-
*/
299-
protected function getFallbackScript($src, $configName)
300-
{
301-
return [
302-
'src' => $src,
303-
'fallback' => array_get($this->config, $configName . '.fallback'),
304-
'fallbackURL' => array_get($this->config, $configName . '.src.local'),
305-
];
306-
}
307-
308259
/**
309260
* Convert item to html.
310261
*
@@ -388,7 +339,11 @@ protected function getSource($configName, $location = null)
388339
$isUsingCdn &&
389340
$location === self::ASSETS_SCRIPT_POSITION_HEADER &&
390341
array_has($this->config, $configName . '.fallback')) {
391-
$scripts[] = $this->getFallbackScript($src, $configName);
342+
$scripts[] = [
343+
'src' => $src,
344+
'fallback' => array_get($this->config, $configName . '.fallback'),
345+
'fallbackURL' => array_get($this->config, $configName . '.src.local'),
346+
];
392347
}
393348

394349
return $scripts;
@@ -409,4 +364,33 @@ public function getHtmlBuilder()
409364
{
410365
return $this->htmlBuilder;
411366
}
367+
368+
/**
369+
* Render assets to header.
370+
*
371+
* @param array $lastStyles
372+
* @return string
373+
* @throws \Throwable
374+
*/
375+
public function renderHeader($lastStyles = [])
376+
{
377+
$styles = $this->getStyles($lastStyles);
378+
379+
$headScripts = $this->getScripts(self::ASSETS_SCRIPT_POSITION_HEADER);
380+
381+
return view('assets::header', compact('styles', 'headScripts'))->render();
382+
}
383+
384+
/**
385+
* Render assets to footer.
386+
*
387+
* @return string
388+
* @throws \Throwable
389+
*/
390+
public function renderFooter()
391+
{
392+
$bodyScripts = $this->getScripts(self::ASSETS_SCRIPT_POSITION_FOOTER);
393+
394+
return view('assets::footer', compact('bodyScripts'))->render();
395+
}
412396
}

0 commit comments

Comments
 (0)