Inject SCSSCacher
Signed-off-by: Roeland Jago Douma <roeland@famdouma.nl>
This commit is contained in:
parent
d64d661ef5
commit
7bd9087f9e
|
@ -25,33 +25,22 @@
|
||||||
|
|
||||||
namespace OC\Template;
|
namespace OC\Template;
|
||||||
|
|
||||||
use OC\SystemConfig;
|
|
||||||
use OCP\Files\IAppData;
|
|
||||||
use OCP\ILogger;
|
use OCP\ILogger;
|
||||||
use OCP\IURLGenerator;
|
|
||||||
|
|
||||||
class CSSResourceLocator extends ResourceLocator {
|
class CSSResourceLocator extends ResourceLocator {
|
||||||
|
|
||||||
/** @var IAppData */
|
/** @var SCSSCacher */
|
||||||
protected $appData;
|
protected $scssCacher;
|
||||||
/** @var IURLGenerator */
|
|
||||||
protected $urlGenerator;
|
|
||||||
/** @var SystemConfig */
|
|
||||||
protected $systemConfig;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param ILogger $logger
|
* @param ILogger $logger
|
||||||
* @param string $theme
|
* @param string $theme
|
||||||
* @param array $core_map
|
* @param array $core_map
|
||||||
* @param array $party_map
|
* @param array $party_map
|
||||||
* @param IAppData $appData
|
* @param SCSSCacher $scssCcacher
|
||||||
* @param IURLGenerator $urlGenerator
|
|
||||||
* @param SystemConfig $systemConfig
|
|
||||||
*/
|
*/
|
||||||
public function __construct(ILogger $logger, $theme, $core_map, $party_map, IAppData $appData, IURLGenerator $urlGenerator, SystemConfig $systemConfig) {
|
public function __construct(ILogger $logger, $theme, $core_map, $party_map, SCSSCacher $scssCacher) {
|
||||||
$this->appData = $appData;
|
$this->scssCacher = $scssCacher;
|
||||||
$this->urlGenerator = $urlGenerator;
|
|
||||||
$this->systemConfig = $systemConfig;
|
|
||||||
|
|
||||||
parent::__construct($logger, $theme, $core_map, $party_map);
|
parent::__construct($logger, $theme, $core_map, $party_map);
|
||||||
}
|
}
|
||||||
|
@ -62,8 +51,8 @@ class CSSResourceLocator extends ResourceLocator {
|
||||||
public function doFind($style) {
|
public function doFind($style) {
|
||||||
if (strpos($style, '3rdparty') === 0
|
if (strpos($style, '3rdparty') === 0
|
||||||
&& $this->appendIfExist($this->thirdpartyroot, $style.'.css')
|
&& $this->appendIfExist($this->thirdpartyroot, $style.'.css')
|
||||||
|| $this->cacheAndAppendScssIfExist($this->serverroot, $style.'.scss', $this->appData, $this->urlGenerator, $this->systemConfig)
|
|| $this->cacheAndAppendScssIfExist($this->serverroot, $style.'.scss')
|
||||||
|| $this->cacheAndAppendScssIfExist($this->serverroot, 'core/'.$style.'.scss', $this->appData, $this->urlGenerator, $this->systemConfig)
|
|| $this->cacheAndAppendScssIfExist($this->serverroot, 'core/'.$style.'.scss')
|
||||||
|| $this->appendIfExist($this->serverroot, $style.'.css')
|
|| $this->appendIfExist($this->serverroot, $style.'.css')
|
||||||
|| $this->appendIfExist($this->serverroot, 'core/'.$style.'.css')
|
|| $this->appendIfExist($this->serverroot, 'core/'.$style.'.css')
|
||||||
) {
|
) {
|
||||||
|
@ -91,22 +80,13 @@ class CSSResourceLocator extends ResourceLocator {
|
||||||
*
|
*
|
||||||
* @param string $root path to check
|
* @param string $root path to check
|
||||||
* @param string $file the filename
|
* @param string $file the filename
|
||||||
* @param IAppData $appData
|
|
||||||
* @param IURLGenerator $urlGenerator
|
|
||||||
* @param SystemConfig $systemConfig
|
|
||||||
* @param string|null $webRoot base for path, default map $root to $webRoot
|
* @param string|null $webRoot base for path, default map $root to $webRoot
|
||||||
* @return bool True if the resource was found and cached, false otherwise
|
* @return bool True if the resource was found and cached, false otherwise
|
||||||
*/
|
*/
|
||||||
protected function cacheAndAppendScssIfExist($root, $file, IAppData $appData, IURLGenerator $urlGenerator, SystemConfig $systemConfig, $webRoot = null) {
|
protected function cacheAndAppendScssIfExist($root, $file, $webRoot = null) {
|
||||||
if (is_file($root.'/'.$file)) {
|
if (is_file($root.'/'.$file)) {
|
||||||
$scssCache = new SCSSCacher(
|
if($this->scssCacher->process($root, $file)) {
|
||||||
$this->logger,
|
$this->append($root, $this->scssCacher->getCachedSCSS('core', $file), $webRoot, false);
|
||||||
$appData,
|
|
||||||
$urlGenerator,
|
|
||||||
$systemConfig);
|
|
||||||
|
|
||||||
if($scssCache->process($root, $file)) {
|
|
||||||
$this->append($root, $scssCache->getCachedSCSS('core', $file), $webRoot, false);
|
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
$this->logger->error('Failed to compile and/or save '.$root.'/'.$file, ['app' => 'core']);
|
$this->logger->error('Failed to compile and/or save '.$root.'/'.$file, ['app' => 'core']);
|
||||||
|
|
|
@ -36,6 +36,7 @@
|
||||||
namespace OC;
|
namespace OC;
|
||||||
|
|
||||||
use OC\Template\JSConfigHelper;
|
use OC\Template\JSConfigHelper;
|
||||||
|
use OC\Template\SCSSCacher;
|
||||||
|
|
||||||
class TemplateLayout extends \OC_Template {
|
class TemplateLayout extends \OC_Template {
|
||||||
|
|
||||||
|
@ -193,14 +194,19 @@ class TemplateLayout extends \OC_Template {
|
||||||
// Read the selected theme from the config file
|
// Read the selected theme from the config file
|
||||||
$theme = \OC_Util::getTheme();
|
$theme = \OC_Util::getTheme();
|
||||||
|
|
||||||
|
$SCSSCacher = new SCSSCacher(
|
||||||
|
\OC::$server->getLogger(),
|
||||||
|
\OC::$server->getAppDataDir('css'),
|
||||||
|
\OC::$server->getURLGenerator(),
|
||||||
|
\OC::$server->getSystemConfig()
|
||||||
|
);
|
||||||
|
|
||||||
$locator = new \OC\Template\CSSResourceLocator(
|
$locator = new \OC\Template\CSSResourceLocator(
|
||||||
\OC::$server->getLogger(),
|
\OC::$server->getLogger(),
|
||||||
$theme,
|
$theme,
|
||||||
array( \OC::$SERVERROOT => \OC::$WEBROOT ),
|
array( \OC::$SERVERROOT => \OC::$WEBROOT ),
|
||||||
array( \OC::$SERVERROOT => \OC::$WEBROOT ),
|
array( \OC::$SERVERROOT => \OC::$WEBROOT ),
|
||||||
\OC::$server->getAppDataDir('css'),
|
$SCSSCacher);
|
||||||
\OC::$server->getURLGenerator(),
|
|
||||||
\OC::$server->getSystemConfig());
|
|
||||||
$locator->find($styles);
|
$locator->find($styles);
|
||||||
return $locator->getResources();
|
return $locator->getResources();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue