diff options
author | emkael <emkael@tlen.pl> | 2016-05-02 23:39:42 +0200 |
---|---|---|
committer | emkael <emkael@tlen.pl> | 2016-05-02 23:39:42 +0200 |
commit | c1ba0e05fbd618d48fce4995f34e14c2175b1dfc (patch) | |
tree | f6f785b8ea3c8dea646b045f88c6f5485b6aca09 /app/php/web/ClientScriptManager.php | |
parent | 6a4785982e854f61fc3e0d498ca3f4284b79acd8 (diff) |
* support for theme sheet files in compiled CSS
Diffstat (limited to 'app/php/web/ClientScriptManager.php')
-rw-r--r-- | app/php/web/ClientScriptManager.php | 56 |
1 files changed, 50 insertions, 6 deletions
diff --git a/app/php/web/ClientScriptManager.php b/app/php/web/ClientScriptManager.php index a0fe657..1ebd8c3 100644 --- a/app/php/web/ClientScriptManager.php +++ b/app/php/web/ClientScriptManager.php @@ -54,6 +54,9 @@ class ClientScriptManager extends TClientScriptManager { private function _getFileCollectionCacheKey($files) { sort($files); + if ($this->_page->Theme) { + $files[] = $this->_page->Theme->Name; + } return md5(implode(PHP_EOL, $files)); } @@ -320,6 +323,14 @@ class ClientScriptManager extends TClientScriptManager { $paths = $this->_getBasePaths( array_map('reset', $files) ); + $correctedPaths = []; + foreach ($paths as $url => $path) { + $correctedPaths[ + in_array($url, $this->_themeStyles) && $this->_page->Theme + ? $this->_page->Theme->BaseUrl . DIRECTORY_SEPARATOR + : $url + ] = $path; + } $cacheKey = $this->_getFileCollectionCacheKey($paths); $cacheFile = $this->_getCacheFilePath($cacheKey . '.css', 'styles'); $this->_appendRenderedSheets($files, $cacheFile); @@ -328,8 +339,8 @@ class ClientScriptManager extends TClientScriptManager { PHP_EOL, array_map( [$this, '_getCompressedSheet'], - array_keys($paths), - $paths + array_keys($correctedPaths), + $correctedPaths ) ); file_put_contents($cacheFile, $styleContent); @@ -446,7 +457,13 @@ class ClientScriptManager extends TClientScriptManager { ); return $sheetUrls; } - return parent::getStyleSheetUrls(); + // in Debug mode, theme sheets before fixing paths + // might also have been published via assets manager, + // so we have to discard these from parent list + return array_diff( + parent::getStyleSheetUrls(), + $this->_fixedStyleFiles + ); } private $_styles = []; @@ -454,12 +471,39 @@ class ClientScriptManager extends TClientScriptManager { public function registerStyleSheetFile($key, $file, $media = '') { $this->_styles[$key] = [$file, $media]; - return parent::registerStyleSheetFile($key, $file, $media); + return parent::registerStyleSheetFile($key, $file, $media ?: 'all'); } + private $_fixedStyleFiles = []; + public function registerThemeStyleSheetFile($key, $file, $media = '') { - $this->_themeStyles[$key] = $file; - return $this->registerStyleSheetFile($key, $file, $media); + if ($this->getApplication()->getMode() !== TApplicationMode::Debug) { + $this->_themeStyles[$key] = $file; + } else { + if ($this->_isFileLocal($file) && $this->_page->Theme) { + $tempFile = $this->_getCacheFilePath( + $this->_getFileCollectionCacheKey([ + $this->_getBasePath() + . DIRECTORY_SEPARATOR + . $file + ]) + . '.' . basename($file), + $this->_page->Theme->Name + ); + file_put_contents( + $tempFile, + $this->_fixStyleSheetPaths( + file_get_contents( + $this->_getBasePath() . DIRECTORY_SEPARATOR . $file + ), + $this->_page->Theme->BaseUrl . DIRECTORY_SEPARATOR + ) + ); + $this->_fixedStyleFiles[] = $file; + $file = $this->Application->AssetManager->publishFilePath($tempFile); + } + } + return $this->registerStyleSheetFile($key, $file, $media ?: 'all'); } } |