assets
This commit is contained in:
@@ -43,6 +43,7 @@ interface AssetManagerInterface {
|
|||||||
* Generates assets from $asset_path in $output_path, using $filters.
|
* Generates assets from $asset_path in $output_path, using $filters.
|
||||||
*
|
*
|
||||||
* @param $assetSource
|
* @param $assetSource
|
||||||
|
* @param $assetDirectoryBase
|
||||||
* @param $webAssetsDirectoryBase
|
* @param $webAssetsDirectoryBase
|
||||||
* @param $webAssetsTemplate
|
* @param $webAssetsTemplate
|
||||||
* @param $webAssetsKey
|
* @param $webAssetsKey
|
||||||
@@ -60,5 +61,5 @@ interface AssetManagerInterface {
|
|||||||
* @internal param string $asset_type the asset type: css, js, ... The generated files will have this extension. Pass an empty string to use the asset source extension.
|
* @internal param string $asset_type the asset type: css, js, ... The generated files will have this extension. Pass an empty string to use the asset source extension.
|
||||||
* @return string The URL to the generated asset file.
|
* @return string The URL to the generated asset file.
|
||||||
*/
|
*/
|
||||||
public function processAsset($assetSource, $webAssetsDirectoryBase, $webAssetsTemplate, $webAssetsKey, $outputUrl, $assetType, $filters, $debug);
|
public function processAsset($assetSource, $assetDirectoryBase, $webAssetsDirectoryBase, $webAssetsTemplate, $webAssetsKey, $outputUrl, $assetType, $filters, $debug);
|
||||||
}
|
}
|
||||||
@@ -273,6 +273,7 @@ class AsseticAssetManager implements AssetManagerInterface
|
|||||||
* Generates assets from $asset_path in $output_path, using $filters.
|
* Generates assets from $asset_path in $output_path, using $filters.
|
||||||
*
|
*
|
||||||
* @param $assetSource
|
* @param $assetSource
|
||||||
|
* @param $assetDirectoryBase
|
||||||
* @param string $webAssetsDirectoryBase the full path to the asset file (or file collection, e.g. *.less)
|
* @param string $webAssetsDirectoryBase the full path to the asset file (or file collection, e.g. *.less)
|
||||||
*
|
*
|
||||||
* @param string $webAssetsTemplate the full disk path to the base assets output directory in the web space
|
* @param string $webAssetsTemplate the full disk path to the base assets output directory in the web space
|
||||||
@@ -286,11 +287,13 @@ class AsseticAssetManager implements AssetManagerInterface
|
|||||||
*
|
*
|
||||||
* @return string The URL to the generated asset file.
|
* @return string The URL to the generated asset file.
|
||||||
*/
|
*/
|
||||||
public function processAsset($assetSource, $webAssetsDirectoryBase, $webAssetsTemplate, $webAssetsKey, $outputUrl, $assetType, $filters, $debug)
|
public function processAsset($assetSource, $assetDirectoryBase, $webAssetsDirectoryBase, $webAssetsTemplate, $webAssetsKey, $outputUrl, $assetType, $filters, $debug)
|
||||||
{
|
{
|
||||||
$assetName = basename($assetSource);
|
$assetName = basename($assetSource);
|
||||||
$inputDirectory = realpath(dirname($assetSource));
|
$inputDirectory = realpath(dirname($assetSource));
|
||||||
|
|
||||||
|
$assetFileDirectoryInAssetDirectory = trim(str_replace(array($assetDirectoryBase, $assetName), '', $assetSource), DS);
|
||||||
|
|
||||||
$am = new AssetManager();
|
$am = new AssetManager();
|
||||||
$fm = new FilterManager();
|
$fm = new FilterManager();
|
||||||
|
|
||||||
@@ -318,21 +321,24 @@ class AsseticAssetManager implements AssetManagerInterface
|
|||||||
|
|
||||||
$assetTargetFilename = $asset->getTargetPath();
|
$assetTargetFilename = $asset->getTargetPath();
|
||||||
|
|
||||||
// This is the final name of the generated asset
|
/*
|
||||||
$assetDestinationPath = $outputDirectory . DS . $assetTargetFilename;
|
* This is the final name of the generated asset
|
||||||
|
* We preserve file structure intending to keep - for example - relative css links working
|
||||||
|
*/
|
||||||
|
$assetDestinationPath = $outputDirectory . DS . $assetFileDirectoryInAssetDirectory . DS . $assetTargetFilename;
|
||||||
|
|
||||||
Tlog::getInstance()->addDebug("Asset destination full path: $assetDestinationPath");
|
Tlog::getInstance()->addDebug("Asset destination full path: $assetDestinationPath");
|
||||||
|
|
||||||
// We generate an asset only if it does not exists, or if the asset processing is forced in development mode
|
// We generate an asset only if it does not exists, or if the asset processing is forced in development mode
|
||||||
if (! file_exists($assetDestinationPath) || ($this->debugMode && ConfigQuery::read('process_assets', true)) ) {
|
if (! file_exists($assetDestinationPath) || ($this->debugMode && ConfigQuery::read('process_assets', true)) ) {
|
||||||
|
|
||||||
$writer = new AssetWriter($outputDirectory);
|
$writer = new AssetWriter($outputDirectory . DS . $assetFileDirectoryInAssetDirectory);
|
||||||
|
|
||||||
Tlog::getInstance()->addDebug("Writing asset to $outputDirectory");
|
Tlog::getInstance()->addDebug("Writing asset to $outputDirectory . DS . $assetFileDirectoryInAssetDirectory");
|
||||||
|
|
||||||
$writer->writeAsset($asset);
|
$writer->writeAsset($asset);
|
||||||
}
|
}
|
||||||
|
|
||||||
return rtrim($outputUrl, '/') . '/' . $outputRelativeWebPath . $assetTargetFilename;
|
return rtrim($outputUrl, DS) . DS . trim($outputRelativeWebPath, DS) . DS . trim($assetFileDirectoryInAssetDirectory, DS) . DS . ltrim($assetTargetFilename, DS);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -37,6 +37,8 @@ class SmartyAssetsManager
|
|||||||
private $web_root;
|
private $web_root;
|
||||||
private $path_relative_to_web_root;
|
private $path_relative_to_web_root;
|
||||||
|
|
||||||
|
static private $assetsDirectory = null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new SmartyAssetsManager instance
|
* Creates a new SmartyAssetsManager instance
|
||||||
*
|
*
|
||||||
@@ -54,6 +56,7 @@ class SmartyAssetsManager
|
|||||||
|
|
||||||
public function prepareAssets($assets_directory, \Smarty_Internal_Template $template)
|
public function prepareAssets($assets_directory, \Smarty_Internal_Template $template)
|
||||||
{
|
{
|
||||||
|
self::$assetsDirectory = $assets_directory;
|
||||||
$smartyParser = $template->smarty;
|
$smartyParser = $template->smarty;
|
||||||
$templateDefinition = $smartyParser->getTemplateDefinition();
|
$templateDefinition = $smartyParser->getTemplateDefinition();
|
||||||
switch($templateDefinition->getType()) {
|
switch($templateDefinition->getType()) {
|
||||||
@@ -62,7 +65,7 @@ class SmartyAssetsManager
|
|||||||
if(isset($frontOfficeTemplateDirectories[$templateDefinition->getName()])) {
|
if(isset($frontOfficeTemplateDirectories[$templateDefinition->getName()])) {
|
||||||
/* create assets foreach directory : main @ modules */
|
/* create assets foreach directory : main @ modules */
|
||||||
foreach($frontOfficeTemplateDirectories[$templateDefinition->getName()] as $key => $directory) {
|
foreach($frontOfficeTemplateDirectories[$templateDefinition->getName()] as $key => $directory) {
|
||||||
$tpl_path = $directory . DS . $assets_directory;
|
$tpl_path = $directory . DS . self::$assetsDirectory;
|
||||||
$asset_dir_absolute_path = realpath($tpl_path);
|
$asset_dir_absolute_path = realpath($tpl_path);
|
||||||
if(false !== $asset_dir_absolute_path) {
|
if(false !== $asset_dir_absolute_path) {
|
||||||
$this->assetsManager->prepareAssets(
|
$this->assetsManager->prepareAssets(
|
||||||
@@ -81,7 +84,7 @@ class SmartyAssetsManager
|
|||||||
if(isset($backOfficeTemplateDirectories[$templateDefinition->getName()])) {
|
if(isset($backOfficeTemplateDirectories[$templateDefinition->getName()])) {
|
||||||
/* create assets foreach directory : main @ modules */
|
/* create assets foreach directory : main @ modules */
|
||||||
foreach($backOfficeTemplateDirectories[$templateDefinition->getName()] as $key => $directory) {
|
foreach($backOfficeTemplateDirectories[$templateDefinition->getName()] as $key => $directory) {
|
||||||
$tpl_path = $directory . DS . $assets_directory;
|
$tpl_path = $directory . DS . self::$assetsDirectory;
|
||||||
$asset_dir_absolute_path = realpath($tpl_path);
|
$asset_dir_absolute_path = realpath($tpl_path);
|
||||||
if(false !== $asset_dir_absolute_path) {
|
if(false !== $asset_dir_absolute_path) {
|
||||||
$this->assetsManager->prepareAssets(
|
$this->assetsManager->prepareAssets(
|
||||||
@@ -104,7 +107,7 @@ class SmartyAssetsManager
|
|||||||
|
|
||||||
// $tpl_dir = dirname($template->source->filepath);
|
// $tpl_dir = dirname($template->source->filepath);
|
||||||
//
|
//
|
||||||
// $tpl_path = $tpl_dir . DS . $assets_directory;
|
// $tpl_path = $tpl_dir . DS . self::$assetsDirectory;
|
||||||
// $asset_dir_absolute_path = realpath($tpl_path);
|
// $asset_dir_absolute_path = realpath($tpl_path);
|
||||||
// if ($asset_dir_absolute_path === false) {
|
// if ($asset_dir_absolute_path === false) {
|
||||||
// /* no assets for current template */
|
// /* no assets for current template */
|
||||||
@@ -176,6 +179,7 @@ class SmartyAssetsManager
|
|||||||
|
|
||||||
$url = $this->assetsManager->processAsset(
|
$url = $this->assetsManager->processAsset(
|
||||||
$assetSource . DS . $file,
|
$assetSource . DS . $file,
|
||||||
|
$assetSource . DS . self::$assetsDirectory,
|
||||||
$this->web_root . $this->path_relative_to_web_root,
|
$this->web_root . $this->path_relative_to_web_root,
|
||||||
$templateDefinition->getPath(),
|
$templateDefinition->getPath(),
|
||||||
$assetOrigin,
|
$assetOrigin,
|
||||||
|
|||||||
Reference in New Issue
Block a user