diff --git a/core/lib/Thelia/Config/Resources/smarty-plugin.xml b/core/lib/Thelia/Config/Resources/smarty-plugin.xml index 0d0b7ed15..9ea787534 100644 --- a/core/lib/Thelia/Config/Resources/smarty-plugin.xml +++ b/core/lib/Thelia/Config/Resources/smarty-plugin.xml @@ -4,23 +4,21 @@ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://thelia.net/schema/dic/config http://thelia.net/schema/dic/config/thelia-1.0.xsd"> - - - - - - - + + + %kernel.environment% + - + - %kernel.environment% + + diff --git a/core/lib/Thelia/Core/Template/Assets/AssetManagerInterface.php b/core/lib/Thelia/Core/Template/Assets/AssetManagerInterface.php new file mode 100644 index 000000000..d9109b2c8 --- /dev/null +++ b/core/lib/Thelia/Core/Template/Assets/AssetManagerInterface.php @@ -0,0 +1,53 @@ +. */ +/* */ +/*************************************************************************************/ + +namespace Thelia\Core\Template\Assets; + +interface AssetManagerInterface { + /** + * Prepare an asset directory. + * + * @param string $source_assets_directory the full path to the source asstes directory + * @param string $web_assets_directory_base the base directory of the web based asset directory + * @throws \RuntimeException if something goes wrong. + */ + public function prepareAssets($source_assets_directory, $web_assets_directory_base); + + /** + * Generates assets from $asset_path in $output_path, using $filters. + * + * @param string $asset_path the full path to the asset file (or file collection, e.g. *.less) + * + * @param string $web_assets_directory_base the full disk path to the base assets output directory in the web space + * @param string $output_url the URL to the base assets output directory in the web space + * + * @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. + * @param array $filters a list of filters, as defined below (see switch($filter_name) ...) + * + * @param boolean $debug the debug mode, true or false + * + * @throws \InvalidArgumentException if an invalid filter name is found + * @return string The URL to the generated asset file. + */ + public function processAsset($asset_path, $web_assets_directory_base, $output_url, $asset_type, $filters, $debug); +} \ No newline at end of file diff --git a/core/lib/Thelia/Core/Template/Assets/AsseticHelper.php b/core/lib/Thelia/Core/Template/Assets/AsseticAssetManager.php similarity index 96% rename from core/lib/Thelia/Core/Template/Assets/AsseticHelper.php rename to core/lib/Thelia/Core/Template/Assets/AsseticAssetManager.php index 0f3e00d54..b5356bee6 100755 --- a/core/lib/Thelia/Core/Template/Assets/AsseticHelper.php +++ b/core/lib/Thelia/Core/Template/Assets/AsseticAssetManager.php @@ -38,10 +38,17 @@ use Symfony\Component\Filesystem\Exception\IOException; * * @author Franck Allimant */ -class AsseticHelper +class AsseticAssetManager implements AssetManagerInterface { + protected $developmentMode; + protected $source_file_extensions = array('less', 'js', 'coffee', 'html', 'tpl', 'htm', 'xml'); + public function __construct($developmentMode) + { + $this->developmentMode = $developmentMode; + } + /** * Create a stamp form the modification time of the content of the given directory and all of its subdirectories * @@ -175,7 +182,7 @@ class AsseticHelper $fs = new Filesystem(); - //FIXME: lock the stuff ? + // FIXME: locking or not locking ? /* $lock_file = "$web_assets_directory_base/assets-".md5($source_assets_directory)."-generation-lock.txt"; @@ -286,11 +293,10 @@ class AsseticHelper * @param array $filters a list of filters, as defined below (see switch($filter_name) ...) * * @param boolean $debug true / false - * @param boolean $dev_mode true / false. If true, assets are not cached and always compiled. * @throws \InvalidArgumentException if an invalid filter name is found * @return string The URL to the generated asset file. */ - public function asseticize($asset_path, $web_assets_directory_base, $output_url, $asset_type, $filters, $debug, $dev_mode = false) + public function processAsset($asset_path, $web_assets_directory_base, $output_url, $asset_type, $filters, $debug) { $asset_name = basename($asset_path); $input_directory = realpath(dirname($asset_path)); @@ -330,7 +336,7 @@ class AsseticHelper Tlog::getInstance()->addDebug("Asset destination name: ", $asset_destination_path); // We generate an asset only if it does not exists, or if the asset processing is forced in development mode - if (! file_exists($asset_destination_path) || ($dev_mode && ConfigQuery::read('process_assets', true)) ) { + if (! file_exists($asset_destination_path) || ($this->developmentMode && ConfigQuery::read('process_assets', true)) ) { $writer = new AssetWriter($output_directory); diff --git a/core/lib/Thelia/Core/Template/Smarty/Assets/SmartyAssetsManager.php b/core/lib/Thelia/Core/Template/Smarty/Assets/SmartyAssetsManager.php index daa204dbc..dd8491bb2 100755 --- a/core/lib/Thelia/Core/Template/Smarty/Assets/SmartyAssetsManager.php +++ b/core/lib/Thelia/Core/Template/Smarty/Assets/SmartyAssetsManager.php @@ -25,32 +25,30 @@ namespace Thelia\Core\Template\Smarty\Assets; use Thelia\Core\Template\Assets\AsseticHelper; use Thelia\Tools\URL; +use Thelia\Core\Template\Assets\AssetManagerInterface; class SmartyAssetsManager { const ASSET_TYPE_AUTO = ''; - private $assetic_manager; + private $assetsManager; private $web_root; private $path_relative_to_web_root; - private $developmentMode; /** * Creates a new SmartyAssetsManager instance * - * @param string $web_root the disk path to the web root (with final /) - * @param string $path_relative_to_web_root the path (relative to web root) where the assets will be generated - * @param boolean $developmentMode true / false. If true, assets are not cached, and always generated. + * @param AssetManagerInterface $assetsManager an asset manager instance + * @param string $web_root the disk path to the web root (with final /) + * @param string $path_relative_to_web_root the path (relative to web root) where the assets will be generated */ - public function __construct($web_root, $path_relative_to_web_root, $developmentMode) + public function __construct(AssetManagerInterface $assetsManager, $web_root, $path_relative_to_web_root) { $this->web_root = $web_root; $this->path_relative_to_web_root = $path_relative_to_web_root; - $this->developmentMode = $developmentMode; - - $this->assetic_manager = new AsseticHelper(); + $this->assetsManager = $assetsManager; } public function prepareAssets($assets_directory, \Smarty_Internal_Template $template) { @@ -61,12 +59,10 @@ class SmartyAssetsManager if ($asset_dir_absolute_path === false) throw new \Exception("Failed to get real path of '".$tpl_dir . DS . $assets_directory."'"); - $modified = $this->assetic_manager->prepareAssets( + $this->assetsManager->prepareAssets( $asset_dir_absolute_path, $this->web_root . $this->path_relative_to_web_root ); - - } public function computeAssetUrl($assetType, $params, \Smarty_Internal_Template $template) @@ -86,25 +82,14 @@ class SmartyAssetsManager $asset_file = basename($file); if ($asset_dir === false) throw new \Exception("Failed to get real path of '".$tpl_dir.'/'.dirname($file)."'"); -/* - $url = $this->assetic_manager->asseticize( - $asset_dir.'/'.$asset_file, - $this->web_root . DS . $this->path_relative_to_web_root, - URL::getInstance()->absoluteUrl($this->path_relative_to_web_root, null, URL::PATH_TO_FILE),// PATH only - $assetType, - $filters, - $debug, - $this->developmentMode - ); -*/ - $url = $this->assetic_manager->asseticize( + + $url = $this->assetsManager->processAsset( $asset_dir . DS . $asset_file, $this->web_root . $this->path_relative_to_web_root, URL::getInstance()->absoluteUrl($this->path_relative_to_web_root, null, URL::PATH_TO_FILE /* path only */), $assetType, $filters, - $debug, - $this->developmentMode + $debug ); return $url; diff --git a/core/lib/Thelia/Core/Template/Smarty/Plugins/Assetic.php b/core/lib/Thelia/Core/Template/Smarty/Plugins/Assets.php similarity index 94% rename from core/lib/Thelia/Core/Template/Smarty/Plugins/Assetic.php rename to core/lib/Thelia/Core/Template/Smarty/Plugins/Assets.php index 808f4a2f6..e4c220ed5 100755 --- a/core/lib/Thelia/Core/Template/Smarty/Plugins/Assetic.php +++ b/core/lib/Thelia/Core/Template/Smarty/Plugins/Assets.php @@ -27,16 +27,17 @@ use Thelia\Core\Template\Smarty\SmartyPluginDescriptor; use Thelia\Core\Template\Smarty\AbstractSmartyPlugin; use Thelia\Core\Template\Smarty\Assets\SmartyAssetsManager; use Thelia\Model\ConfigQuery; +use Thelia\Core\Template\Assets\AssetManagerInterface; -class Assetic extends AbstractSmartyPlugin +class Assets extends AbstractSmartyPlugin { public $assetManager; - public function __construct($developmentMode) + public function __construct(AssetManagerInterface $assetsManager) { $asset_dir_from_web_root = ConfigQuery::read('asset_dir_from_web_root', 'assets'); - $this->assetManager = new SmartyAssetsManager(THELIA_WEB_DIR, $asset_dir_from_web_root, $developmentMode == 'dev'); + $this->assetManager = new SmartyAssetsManager($assetsManager, THELIA_WEB_DIR, $asset_dir_from_web_root); } public function declareAssets($params, \Smarty_Internal_Template $template)