Inject SCSSCacher

Signed-off-by: Roeland Jago Douma <roeland@famdouma.nl>
This commit is contained in:
Roeland Jago Douma 2016-11-30 22:09:36 +01:00
parent d64d661ef5
commit 7bd9087f9e
No known key found for this signature in database
GPG Key ID: F941078878347C0C
2 changed files with 19 additions and 33 deletions

View File

@ -25,33 +25,22 @@
namespace OC\Template;
use OC\SystemConfig;
use OCP\Files\IAppData;
use OCP\ILogger;
use OCP\IURLGenerator;
class CSSResourceLocator extends ResourceLocator {
/** @var IAppData */
protected $appData;
/** @var IURLGenerator */
protected $urlGenerator;
/** @var SystemConfig */
protected $systemConfig;
/** @var SCSSCacher */
protected $scssCacher;
/**
* @param ILogger $logger
* @param string $theme
* @param array $core_map
* @param array $party_map
* @param IAppData $appData
* @param IURLGenerator $urlGenerator
* @param SystemConfig $systemConfig
* @param SCSSCacher $scssCcacher
*/
public function __construct(ILogger $logger, $theme, $core_map, $party_map, IAppData $appData, IURLGenerator $urlGenerator, SystemConfig $systemConfig) {
$this->appData = $appData;
$this->urlGenerator = $urlGenerator;
$this->systemConfig = $systemConfig;
public function __construct(ILogger $logger, $theme, $core_map, $party_map, SCSSCacher $scssCacher) {
$this->scssCacher = $scssCacher;
parent::__construct($logger, $theme, $core_map, $party_map);
}
@ -62,8 +51,8 @@ class CSSResourceLocator extends ResourceLocator {
public function doFind($style) {
if (strpos($style, '3rdparty') === 0
&& $this->appendIfExist($this->thirdpartyroot, $style.'.css')
|| $this->cacheAndAppendScssIfExist($this->serverroot, $style.'.scss', $this->appData, $this->urlGenerator, $this->systemConfig)
|| $this->cacheAndAppendScssIfExist($this->serverroot, 'core/'.$style.'.scss', $this->appData, $this->urlGenerator, $this->systemConfig)
|| $this->cacheAndAppendScssIfExist($this->serverroot, $style.'.scss')
|| $this->cacheAndAppendScssIfExist($this->serverroot, 'core/'.$style.'.scss')
|| $this->appendIfExist($this->serverroot, $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 $file the filename
* @param IAppData $appData
* @param IURLGenerator $urlGenerator
* @param SystemConfig $systemConfig
* @param string|null $webRoot base for path, default map $root to $webRoot
* @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)) {
$scssCache = new SCSSCacher(
$this->logger,
$appData,
$urlGenerator,
$systemConfig);
if($scssCache->process($root, $file)) {
$this->append($root, $scssCache->getCachedSCSS('core', $file), $webRoot, false);
if($this->scssCacher->process($root, $file)) {
$this->append($root, $this->scssCacher->getCachedSCSS('core', $file), $webRoot, false);
return true;
} else {
$this->logger->error('Failed to compile and/or save '.$root.'/'.$file, ['app' => 'core']);

View File

@ -36,6 +36,7 @@
namespace OC;
use OC\Template\JSConfigHelper;
use OC\Template\SCSSCacher;
class TemplateLayout extends \OC_Template {
@ -193,14 +194,19 @@ class TemplateLayout extends \OC_Template {
// Read the selected theme from the config file
$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(
\OC::$server->getLogger(),
$theme,
array( \OC::$SERVERROOT => \OC::$WEBROOT ),
array( \OC::$SERVERROOT => \OC::$WEBROOT ),
\OC::$server->getAppDataDir('css'),
\OC::$server->getURLGenerator(),
\OC::$server->getSystemConfig());
$SCSSCacher);
$locator->find($styles);
return $locator->getResources();
}