Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable every app to generate their scss file #3197

Merged
merged 3 commits into from
Jan 26, 2017
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions lib/private/Template/CSSResourceLocator.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use

if(!$this->cacheAndAppendScssIfExist($app_path, $style.'.scss', $app)) {

instead to make sure things work when using alternative app directories.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if(!$this->cacheAndAppendScssIfExist($app_path, $style.'.scss', null, $app)) {

to pass the correct app parameter

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How did I missed that!
Thanks!

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hum, after a quick thought, it seems that we never used the webroot here.
So I'm not sure we need it :p

Copy link
Member

@icewind1991 icewind1991 Jan 24, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Webroot isn't needed with scss since we load it trough a route anyway, for css it's still needed afaik

edit: ignore this, was talking about different webroot

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I fixed it.
We had the webroot var, but it wasn't used by anything nor passed through a function.

$this->append($app_path, $style.'.css', $app_url);
}
}

/**
Expand All @@ -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']);
Expand Down
7 changes: 4 additions & 3 deletions lib/private/Template/SCSSCacher.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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)) {
Expand Down