Skip to content

Commit

Permalink
Merge pull request #3619 from nextcloud/fix-scss-for-apps
Browse files Browse the repository at this point in the history
Fix SCSS usage in apps
  • Loading branch information
MorrisJobke authored Mar 17, 2017
2 parents 5683365 + f86b5c2 commit ead9a10
Show file tree
Hide file tree
Showing 4 changed files with 94 additions and 7 deletions.
50 changes: 49 additions & 1 deletion lib/private/Template/CSSResourceLocator.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,8 @@ 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), false);

$this->append($root, $this->scssCacher->getCachedSCSS($app, $file), false, true, true);
return true;
} else {
$this->logger->warning('Failed to compile and/or save '.$root.'/'.$file, ['app' => 'core']);
Expand All @@ -101,4 +102,51 @@ protected function cacheAndAppendScssIfExist($root, $file, $app = 'core') {
}
return false;
}

public function append($root, $file, $webRoot = null, $throw = true, $scss = false) {
if (!$scss) {
parent::append($root, $file, $webRoot, $throw);
} else {
if (!$webRoot) {
$tmpRoot = $root;
/*
* traverse the potential web roots upwards in the path
*
* example:
* - root: /srv/www/apps/myapp
* - available mappings: ['/srv/www']
*
* First we check if a mapping for /srv/www/apps/myapp is available,
* then /srv/www/apps, /srv/www/apps, /srv/www, ... until we find a
* valid web root
*/
do {
if (isset($this->mapping[$tmpRoot])) {
$webRoot = $this->mapping[$tmpRoot];
break;
}

if ($tmpRoot === '/') {
$webRoot = '';
$this->logger->error('ResourceLocator can not find a web root (root: {root}, file: {file}, webRoot: {webRoot}, throw: {throw})', [
'app' => 'lib',
'root' => $root,
'file' => $file,
'webRoot' => $webRoot,
'throw' => $throw ? 'true' : 'false'
]);
break;
}
$tmpRoot = dirname($tmpRoot);
} while(true);

}

if ($throw && $tmpRoot === '/') {
throw new ResourceNotFoundException($file, $webRoot);
}

$this->resources[] = array($tmpRoot, $webRoot, $file);
}
}
}
33 changes: 32 additions & 1 deletion lib/private/Template/ResourceLocator.php
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,38 @@ protected function appendIfExist($root, $file, $webRoot = null) {
*/
protected function append($root, $file, $webRoot = null, $throw = true) {
if (!$webRoot) {
$webRoot = $this->mapping[$root];
$tmpRoot = $root;
/*
* traverse the potential web roots upwards in the path
*
* example:
* - root: /srv/www/apps/myapp
* - available mappings: ['/srv/www']
*
* First we check if a mapping for /srv/www/apps/myapp is available,
* then /srv/www/apps, /srv/www/apps, /srv/www, ... until we find a
* valid web root
*/
do {
if (isset($this->mapping[$tmpRoot])) {
$webRoot = $this->mapping[$tmpRoot];
break;
}

if ($tmpRoot === '/') {
$webRoot = '';
$this->logger->error('ResourceLocator can not find a web root (root: {root}, file: {file}, webRoot: {webRoot}, throw: {throw})', [
'app' => 'lib',
'root' => $root,
'file' => $file,
'webRoot' => $webRoot,
'throw' => $throw ? 'true' : 'false'
]);
break;
}
$tmpRoot = dirname($tmpRoot);
} while(true);

}
$this->resources[] = array($root, $webRoot, $file);

Expand Down
15 changes: 11 additions & 4 deletions lib/private/Template/SCSSCacher.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,17 +46,26 @@ class SCSSCacher {
/** @var SystemConfig */
protected $systemConfig;

/** @var string */
protected $serverRoot;

/**
* @param ILogger $logger
* @param IAppData $appData
* @param IURLGenerator $urlGenerator
* @param SystemConfig $systemConfig
* @param string $serverRoot
*/
public function __construct(ILogger $logger, IAppData $appData, IURLGenerator $urlGenerator, SystemConfig $systemConfig) {
public function __construct(ILogger $logger,
IAppData $appData,
IURLGenerator $urlGenerator,
SystemConfig $systemConfig,
$serverRoot) {
$this->logger = $logger;
$this->appData = $appData;
$this->urlGenerator = $urlGenerator;
$this->systemConfig = $systemConfig;
$this->serverRoot = $serverRoot;
}

/**
Expand All @@ -74,9 +83,7 @@ public function process($root, $file, $app) {

$path = implode('/', $path);

$webDir = explode('/', $file);
array_pop($webDir);
$webDir = implode('/', $webDir);
$webDir = substr($path, strlen($this->serverRoot)+1);

try {
$folder = $this->appData->getFolder($app);
Expand Down
3 changes: 2 additions & 1 deletion lib/private/TemplateLayout.php
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,8 @@ static public function findStylesheetFiles($styles, $compileScss = true) {
\OC::$server->getLogger(),
\OC::$server->getAppDataDir('css'),
\OC::$server->getURLGenerator(),
\OC::$server->getSystemConfig()
\OC::$server->getSystemConfig(),
\OC::$SERVERROOT
);
} else {
$SCSSCacher = null;
Expand Down

0 comments on commit ead9a10

Please sign in to comment.