Skip to content

Commit

Permalink
Merge pull request #914 from LuckyCyborg/master
Browse files Browse the repository at this point in the history
 	Improve the Routing of Vendor based Assets and rename the "Custom" Layout as "Backend" on AdminLte Template, being a more appropriate name
  • Loading branch information
daveismynamecom committed May 31, 2016
2 parents 9a2ebc8 + ec5485b commit 3386cd3
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 15 deletions.
File renamed without changes.
40 changes: 25 additions & 15 deletions system/Routing/BaseRouter.php
Original file line number Diff line number Diff line change
Expand Up @@ -260,16 +260,18 @@ protected function dispatchFile($uri)
if (preg_match('#^assets/(.*)$#i', $uri, $matches)) {
$filePath = ROOTDIR .'assets' .DS .$matches[1];
} else if (preg_match('#^(templates|modules)/([^/]+)/assets/([^/]+)/(.*)$#i', $uri, $matches)) {
$type = ucfirst($matches[1]);
$module = Inflector::classify($matches[2]);

$name = Inflector::classify($matches[2]);
$folder = $matches[3];

if($type == 'Modules') {
$path = $matches[4];

if($matches[1] == 'Modules') {
// A Module Asset file.
$filePath = APPDIR .$type .DS .$name .DS .'Assets' .DS .$matches[3] .DS .$matches[4];
$filePath = $this->getModuleAssetPath($module, $folder, $path);
} else {
// A Template Asset file.
$filePath = $this->getTemplateAsset($name, $matches[3], $matches[4]);
$filePath = $this->getTemplateAssetPath($module, $folder, $path);
}
}

Expand All @@ -287,7 +289,18 @@ protected function dispatchFile($uri)
* Get the path of a Asset file
* @return string|null
*/
protected function getTemplateAsset($template, $folder, $path)
protected function getModuleAssetPath($module, $folder, $path)
{
$basePath = APPDIR .str_replace('/', DS, "Modules/$module/Assets/");

return $basePath .$folder .DS .$path;
}

/**
* Get the path of a Asset file
* @return string|null
*/
protected function getTemplateAssetPath($template, $folder, $path)
{
$path = str_replace('/', DS, $path);

Expand All @@ -303,27 +316,24 @@ protected function getTemplateAsset($template, $folder, $path)
$info = array();
}

//
$basePath = null;

// Get the current Asset Folder's Mode.
$mode = array_get($info, 'assets.paths.' .$folder, 'local');

if ($mode == 'local') {
$basePath = APPDIR .'Templates' .DS .$template .DS .'Assets' .DS;
$basePath = APPDIR .str_replace('/', DS, "Templates/$template/Assets/");
} else if ($mode == 'vendor') {
$basePath = null;

// Get the Vendor name.
$vendor = array_get($info, 'assets.vendor', '');

if (! empty($vendor)) {
$basePath = ROOTDIR .'vendor' .DS. $vendor .DS;
$basePath = ROOTDIR .str_replace('/', DS, "vendor/$vendor/");
}
}

if (! empty($basePath)) {
return $basePath .$folder .DS .$path;
}

return '';
return ! empty($basePath) ? $basePath .$folder .DS .$path : '';
}

/**
Expand Down

0 comments on commit 3386cd3

Please sign in to comment.