Improved template pathes management: no more \ and / mix

This commit is contained in:
Franck Allimant
2014-02-04 00:56:50 +01:00
parent f9be7d1963
commit e08ea4e14f
4 changed files with 23 additions and 12 deletions

View File

@@ -316,8 +316,6 @@ class AsseticAssetManager implements AssetManagerInterface
// Get the URL part from the relative path
$outputRelativePath = $webAssetsTemplate . DS . $webAssetsKey;
$outputRelativeWebPath = rtrim(str_replace('\\', '/', $outputRelativePath), '/') . '/';
$assetTargetFilename = $asset->getTargetPath();
/*
@@ -333,11 +331,18 @@ class AsseticAssetManager implements AssetManagerInterface
$writer = new AssetWriter($outputDirectory . DS . $assetFileDirectoryInAssetDirectory);
Tlog::getInstance()->addDebug("Writing asset to $outputDirectory . DS . $assetFileDirectoryInAssetDirectory");
Tlog::getInstance()->addDebug("Writing asset to $outputDirectory" . DS . "$assetFileDirectoryInAssetDirectory");
$writer->writeAsset($asset);
}
// Normalize path to generate a valid URL
if (DS != '/') {
$outputRelativeWebPath = str_replace(DS, '/', $outputRelativePath);
$assetFileDirectoryInAssetDirectory = str_replace(DS, '/', $assetFileDirectoryInAssetDirectory);
$assetTargetFilename = str_replace(DS, '/', $assetTargetFilename);
}
return rtrim($outputUrl, '/') . '/' . trim($outputRelativeWebPath, '/') . '/' . trim($assetFileDirectoryInAssetDirectory, '/') . '/' . ltrim($assetTargetFilename, '/');
}
}

View File

@@ -24,6 +24,7 @@
namespace Thelia\Core\Template\Smarty\Assets;
use Thelia\Log\Tlog;
use Thelia\Tools\URL;
use Thelia\Core\Template\Assets\AssetManagerInterface;
@@ -109,6 +110,11 @@ class SmartyAssetsManager
$assetSource = $templateDirectories[$templateDefinition->getName()][$assetOrigin];
if (DS != '/') {
// Just to be sure to generate a clean pathname
$file = str_replace('/', DS, $file);
}
$url = $this->assetsManager->processAsset(
$assetSource . DS . $file,
$assetSource . DS . self::$assetsDirectory,

View File

@@ -30,10 +30,10 @@ class TemplateDefinition
const PDF = 3;
const EMAIL = 4;
const FRONT_OFFICE_SUBDIR = 'frontOffice/';
const BACK_OFFICE_SUBDIR = 'backOffice/';
const PDF_SUBDIR = 'pdf/';
const EMAIL_SUBDIR = 'email/';
const FRONT_OFFICE_SUBDIR = 'frontOffice';
const BACK_OFFICE_SUBDIR = 'backOffice';
const PDF_SUBDIR = 'pdf';
const EMAIL_SUBDIR = 'email';
protected static $standardTemplatesSubdirs = array(
self::FRONT_OFFICE => self::FRONT_OFFICE_SUBDIR,
@@ -64,16 +64,16 @@ class TemplateDefinition
switch ($type) {
case TemplateDefinition::FRONT_OFFICE:
$this->path = self::FRONT_OFFICE_SUBDIR . $name;
$this->path = self::FRONT_OFFICE_SUBDIR . DS . $name;
break;
case TemplateDefinition::BACK_OFFICE:
$this->path = self::BACK_OFFICE_SUBDIR . $name;
$this->path = self::BACK_OFFICE_SUBDIR . DS . $name;
break;
case TemplateDefinition::PDF:
$this->path = self::PDF_SUBDIR . $name;
$this->path = self::PDF_SUBDIR . DS . $name;
break;
case TemplateDefinition::EMAIL:
$this->path = self::EMAIL_SUBDIR . $name;
$this->path = self::EMAIL_SUBDIR . DS . $name;
break;
default:
$this->path = $name;

View File

@@ -129,7 +129,7 @@ class TemplateHelper
if ($file->isDot() || ! $file->isDir()) continue;
// Ignore reserved directory names
if (in_array($file->getFilename()."/", $exclude)) continue;
if (in_array($file->getFilename(), $exclude)) continue;
$list[] = new TemplateDefinition($file->getFilename(), $templateType);
}