AssetMaker Improvements (#2847)
* Check if asset file exists before symbolizing path Adds a check to see if the asset file exists before attempting to symbolize it, this will allow the asset combiner to be passed assets with complete paths instead of only relative paths. * Implement combiner business logic * Improve handling of bad inputs
This commit is contained in:
parent
3a2b9b1973
commit
68e874dc97
|
|
@ -404,7 +404,7 @@ class CombineAssets
|
||||||
$filesSalt = null;
|
$filesSalt = null;
|
||||||
foreach ($assets as $asset) {
|
foreach ($assets as $asset) {
|
||||||
$filters = $this->getFilters(File::extension($asset)) ?: [];
|
$filters = $this->getFilters(File::extension($asset)) ?: [];
|
||||||
$path = File::symbolizePath($asset, null) ?: $this->localPath . $asset;
|
$path = file_exists($asset) ? $asset : File::symbolizePath($asset, null) ?: $this->localPath . $asset;
|
||||||
$files[] = new FileAsset($path, $filters, public_path());
|
$files[] = new FileAsset($path, $filters, public_path());
|
||||||
$filesSalt .= $this->localPath . $asset;
|
$filesSalt .= $this->localPath . $asset;
|
||||||
}
|
}
|
||||||
|
|
@ -458,7 +458,7 @@ class CombineAssets
|
||||||
$key = '';
|
$key = '';
|
||||||
|
|
||||||
$assetFiles = array_map(function ($file) {
|
$assetFiles = array_map(function ($file) {
|
||||||
return File::symbolizePath($file, null) ?: $this->localPath . $file;
|
return file_exists($file) ? $file : File::symbolizePath($file, null) ?: $this->localPath . $file;
|
||||||
}, $assets);
|
}, $assets);
|
||||||
|
|
||||||
foreach ($assetFiles as $file) {
|
foreach ($assetFiles as $file) {
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,7 @@ use Url;
|
||||||
use Html;
|
use Html;
|
||||||
use System\Models\Parameter;
|
use System\Models\Parameter;
|
||||||
use System\Models\PluginVersion;
|
use System\Models\PluginVersion;
|
||||||
|
use System\Classes\CombineAssets;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Asset Maker Trait
|
* Asset Maker Trait
|
||||||
|
|
@ -110,6 +111,10 @@ trait AssetMaker
|
||||||
*/
|
*/
|
||||||
public function addJs($name, $attributes = [])
|
public function addJs($name, $attributes = [])
|
||||||
{
|
{
|
||||||
|
if (is_array($name)) {
|
||||||
|
$name = $this->combineAssets($name);
|
||||||
|
}
|
||||||
|
|
||||||
$jsPath = $this->getAssetPath($name);
|
$jsPath = $this->getAssetPath($name);
|
||||||
|
|
||||||
if (isset($this->controller)) {
|
if (isset($this->controller)) {
|
||||||
|
|
@ -136,6 +141,10 @@ trait AssetMaker
|
||||||
*/
|
*/
|
||||||
public function addCss($name, $attributes = [])
|
public function addCss($name, $attributes = [])
|
||||||
{
|
{
|
||||||
|
if (is_array($name)) {
|
||||||
|
$name = $this->combineAssets($name);
|
||||||
|
}
|
||||||
|
|
||||||
$cssPath = $this->getAssetPath($name);
|
$cssPath = $this->getAssetPath($name);
|
||||||
|
|
||||||
if (isset($this->controller)) {
|
if (isset($this->controller)) {
|
||||||
|
|
@ -179,6 +188,22 @@ trait AssetMaker
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Run the provided assets through the Asset Combiner
|
||||||
|
* @param array $assets Collection of assets
|
||||||
|
* @param string $localPath Prefix all assets with this path (optional)
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function combineAssets(array $assets, $localPath = '')
|
||||||
|
{
|
||||||
|
// Short circuit if no assets actually provided
|
||||||
|
if (empty($assets)) {
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
$assetPath = !empty($localPath) ? $localPath : $this->assetPath;
|
||||||
|
return Url::to(CombineAssets::combine($assets, $assetPath));
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns an array of all registered asset paths.
|
* Returns an array of all registered asset paths.
|
||||||
* @return array
|
* @return array
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue