From 4ceb2bf84ce4c40345feae3846a0f5aae926ce1f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?John=20Molakvo=C3=A6=20=28skjnldsv=29?= Date: Sun, 22 Jan 2017 19:33:45 +0100 Subject: [PATCH 1/3] Enable every app to generate their scss file MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: John Molakvoæ (skjnldsv) --- lib/private/Template/CSSResourceLocator.php | 14 ++++++++------ lib/private/Template/SCSSCacher.php | 7 ++++--- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/lib/private/Template/CSSResourceLocator.php b/lib/private/Template/CSSResourceLocator.php index 6af4e319e363d..bcc43198cbb60 100644 --- a/lib/private/Template/CSSResourceLocator.php +++ b/lib/private/Template/CSSResourceLocator.php @@ -49,20 +49,22 @@ public function __construct(ILogger $logger, $theme, $core_map, $party_map, $scs * @param string $style */ public function doFind($style) { + $app = substr($style, 0, strpos($style, '/')); if (strpos($style, '3rdparty') === 0 && $this->appendIfExist($this->thirdpartyroot, $style.'.css') - || $this->cacheAndAppendScssIfExist($this->serverroot, $style.'.scss') + || $this->cacheAndAppendScssIfExist($this->serverroot, $style.'.scss', $app) || $this->cacheAndAppendScssIfExist($this->serverroot, 'core/'.$style.'.scss') || $this->appendIfExist($this->serverroot, $style.'.css') || $this->appendIfExist($this->serverroot, 'core/'.$style.'.css') ) { return; } - $app = substr($style, 0, strpos($style, '/')); $style = substr($style, strpos($style, '/')+1); $app_path = \OC_App::getAppPath($app); $app_url = \OC_App::getAppWebPath($app); - $this->append($app_path, $style.'.css', $app_url); + if(!$this->cacheAndAppendScssIfExist($this->serverroot.'/apps', $app.'/'.$style.'.scss', $app)) { + $this->append($app_path, $style.'.css', $app_url); + } } /** @@ -83,11 +85,11 @@ public function doFindTheme($style) { * @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, $webRoot = null) { + protected function cacheAndAppendScssIfExist($root, $file, $webRoot = null, $app = 'core') { if (is_file($root.'/'.$file)) { if($this->scssCacher !== null) { - if($this->scssCacher->process($root, $file)) { - $this->append($root, $this->scssCacher->getCachedSCSS('core', $file), $webRoot, false); + if($this->scssCacher->process($root, $file, $app)) { + $this->append($root, $this->scssCacher->getCachedSCSS($app, $file), $webRoot, false); return true; } else { $this->logger->error('Failed to compile and/or save '.$root.'/'.$file, ['app' => 'core']); diff --git a/lib/private/Template/SCSSCacher.php b/lib/private/Template/SCSSCacher.php index 0c1711b9fb72b..d6f5a2c6fd3fc 100644 --- a/lib/private/Template/SCSSCacher.php +++ b/lib/private/Template/SCSSCacher.php @@ -63,9 +63,10 @@ public function __construct(ILogger $logger, IAppData $appData, IURLGenerator $u * Process the caching process if needed * @param string $root Root path to the nextcloud installation * @param string $file + * @param string $app The app name * @return boolean */ - public function process($root, $file) { + public function process($root, $file, $app) { $path = explode('/', $root . '/' . $file); $fileNameSCSS = array_pop($path); @@ -78,10 +79,10 @@ public function process($root, $file) { $webDir = implode('/', $webDir); try { - $folder = $this->appData->getFolder('core'); + $folder = $this->appData->getFolder($app); } catch(NotFoundException $e) { // creating css appdata folder - $folder = $this->appData->newFolder('core'); + $folder = $this->appData->newFolder($app); } if($this->isCached($fileNameCSS, $fileNameSCSS, $folder, $path)) { From a440c3e94c8c82b433341f04ae9d4b7213d6d974 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?John=20Molakvo=C3=A6=20=28skjnldsv=29?= Date: Tue, 24 Jan 2017 17:27:35 +0100 Subject: [PATCH 2/3] Remove unused webroot MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: John Molakvoæ (skjnldsv) --- lib/private/Template/CSSResourceLocator.php | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/lib/private/Template/CSSResourceLocator.php b/lib/private/Template/CSSResourceLocator.php index bcc43198cbb60..02a7ab7e10e99 100644 --- a/lib/private/Template/CSSResourceLocator.php +++ b/lib/private/Template/CSSResourceLocator.php @@ -82,14 +82,13 @@ public function doFindTheme($style) { * * @param string $root path to check * @param string $file the filename - * @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, $webRoot = null, $app = 'core') { + protected function cacheAndAppendScssIfExist($root, $file, $app = 'core') { if (is_file($root.'/'.$file)) { if($this->scssCacher !== null) { if($this->scssCacher->process($root, $file, $app)) { - $this->append($root, $this->scssCacher->getCachedSCSS($app, $file), $webRoot, false); + $this->append($root, $this->scssCacher->getCachedSCSS($app, $file), false); return true; } else { $this->logger->error('Failed to compile and/or save '.$root.'/'.$file, ['app' => 'core']); From dcad6032b1c476572dd4404b5aede440e119d53f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?John=20Molakvo=C3=A6=20=28skjnldsv=29?= Date: Tue, 24 Jan 2017 17:46:20 +0100 Subject: [PATCH 3/3] Appdata var fix MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: John Molakvoæ (skjnldsv) --- lib/private/Template/CSSResourceLocator.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/private/Template/CSSResourceLocator.php b/lib/private/Template/CSSResourceLocator.php index 02a7ab7e10e99..b306e078cd230 100644 --- a/lib/private/Template/CSSResourceLocator.php +++ b/lib/private/Template/CSSResourceLocator.php @@ -62,7 +62,7 @@ public function doFind($style) { $style = substr($style, strpos($style, '/')+1); $app_path = \OC_App::getAppPath($app); $app_url = \OC_App::getAppWebPath($app); - if(!$this->cacheAndAppendScssIfExist($this->serverroot.'/apps', $app.'/'.$style.'.scss', $app)) { + if(!$this->cacheAndAppendScssIfExist($app_path, $style.'.scss', $app)) { $this->append($app_path, $style.'.css', $app_url); } }