Merge pull request #3197 from nextcloud/enable-scss-for-all-apps

Enable every app to generate their scss file
This commit is contained in:
Morris Jobke 2017-01-25 22:53:23 -06:00 committed by GitHub
commit e7523b07bd
2 changed files with 12 additions and 10 deletions

View File

@ -49,21 +49,23 @@ class CSSResourceLocator extends ResourceLocator {
* @param string $style * @param string $style
*/ */
public function doFind($style) { public function doFind($style) {
$app = substr($style, 0, strpos($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->cacheAndAppendScssIfExist($this->serverroot, $style.'.scss', $app)
|| $this->cacheAndAppendScssIfExist($this->serverroot, 'core/'.$style.'.scss') || $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')
) { ) {
return; return;
} }
$app = substr($style, 0, strpos($style, '/'));
$style = substr($style, strpos($style, '/')+1); $style = substr($style, strpos($style, '/')+1);
$app_path = \OC_App::getAppPath($app); $app_path = \OC_App::getAppPath($app);
$app_url = \OC_App::getAppWebPath($app); $app_url = \OC_App::getAppWebPath($app);
if(!$this->cacheAndAppendScssIfExist($app_path, $style.'.scss', $app)) {
$this->append($app_path, $style.'.css', $app_url); $this->append($app_path, $style.'.css', $app_url);
} }
}
/** /**
* @param string $style * @param string $style
@ -80,14 +82,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 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, $webRoot = null) { protected function cacheAndAppendScssIfExist($root, $file, $app = 'core') {
if (is_file($root.'/'.$file)) { if (is_file($root.'/'.$file)) {
if($this->scssCacher !== null) { if($this->scssCacher !== null) {
if($this->scssCacher->process($root, $file)) { if($this->scssCacher->process($root, $file, $app)) {
$this->append($root, $this->scssCacher->getCachedSCSS('core', $file), $webRoot, false); $this->append($root, $this->scssCacher->getCachedSCSS($app, $file), 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']);

View File

@ -63,9 +63,10 @@ class SCSSCacher {
* Process the caching process if needed * Process the caching process if needed
* @param string $root Root path to the nextcloud installation * @param string $root Root path to the nextcloud installation
* @param string $file * @param string $file
* @param string $app The app name
* @return boolean * @return boolean
*/ */
public function process($root, $file) { public function process($root, $file, $app) {
$path = explode('/', $root . '/' . $file); $path = explode('/', $root . '/' . $file);
$fileNameSCSS = array_pop($path); $fileNameSCSS = array_pop($path);
@ -78,10 +79,10 @@ class SCSSCacher {
$webDir = implode('/', $webDir); $webDir = implode('/', $webDir);
try { try {
$folder = $this->appData->getFolder('core'); $folder = $this->appData->getFolder($app);
} catch(NotFoundException $e) { } catch(NotFoundException $e) {
// creating css appdata folder // creating css appdata folder
$folder = $this->appData->newFolder('core'); $folder = $this->appData->newFolder($app);
} }
if($this->isCached($fileNameCSS, $fileNameSCSS, $folder, $path)) { if($this->isCached($fileNameCSS, $fileNameSCSS, $folder, $path)) {