Formatting
Signed-off-by: Roeland Jago Douma <roeland@famdouma.nl>
This commit is contained in:
parent
1e44a15dd1
commit
d9eaed5ffa
|
@ -25,25 +25,30 @@
|
||||||
|
|
||||||
namespace OC\Template;
|
namespace OC\Template;
|
||||||
|
|
||||||
|
use OC\SystemConfig;
|
||||||
|
use OCP\Files\IAppData;
|
||||||
|
use OCP\ILogger;
|
||||||
|
use OCP\IURLGenerator;
|
||||||
|
|
||||||
class CSSResourceLocator extends ResourceLocator {
|
class CSSResourceLocator extends ResourceLocator {
|
||||||
|
|
||||||
/** @var \OCP\Files\IAppData */
|
/** @var IAppData */
|
||||||
protected $appData;
|
protected $appData;
|
||||||
/** @var \OCP\IURLGenerator */
|
/** @var IURLGenerator */
|
||||||
protected $urlGenerator;
|
protected $urlGenerator;
|
||||||
/** @var \OC\SystemConfig */
|
/** @var SystemConfig */
|
||||||
protected $systemConfig;
|
protected $systemConfig;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param \OCP\ILogger $logger
|
* @param ILogger $logger
|
||||||
* @param string $theme
|
* @param string $theme
|
||||||
* @param array $core_map
|
* @param array $core_map
|
||||||
* @param array $party_map
|
* @param array $party_map
|
||||||
* @param \OCP\Files\IAppData $appData
|
* @param IAppData $appData
|
||||||
* @param \OCP\IURLGenerator $urlGenerator
|
* @param IURLGenerator $urlGenerator
|
||||||
* @param \OC\SystemConfig $systemConfig
|
* @param SystemConfig $systemConfig
|
||||||
*/
|
*/
|
||||||
public function __construct(\OCP\ILogger $logger, $theme, $core_map, $party_map, \OCP\Files\IAppData $appData, \OCP\IURLGenerator $urlGenerator, \OC\SystemConfig $systemConfig) {
|
public function __construct(ILogger $logger, $theme, $core_map, $party_map, IAppData $appData, IURLGenerator $urlGenerator, SystemConfig $systemConfig) {
|
||||||
$this->appData = $appData;
|
$this->appData = $appData;
|
||||||
$this->urlGenerator = $urlGenerator;
|
$this->urlGenerator = $urlGenerator;
|
||||||
$this->systemConfig = $systemConfig;
|
$this->systemConfig = $systemConfig;
|
||||||
|
@ -80,4 +85,36 @@ class CSSResourceLocator extends ResourceLocator {
|
||||||
|| $this->appendIfExist($this->serverroot, $theme_dir.$style.'.css')
|
|| $this->appendIfExist($this->serverroot, $theme_dir.$style.'.css')
|
||||||
|| $this->appendIfExist($this->serverroot, $theme_dir.'core/'.$style.'.css');
|
|| $this->appendIfExist($this->serverroot, $theme_dir.'core/'.$style.'.css');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* cache and append the scss $file if exist at $root
|
||||||
|
*
|
||||||
|
* @param string $root path to check
|
||||||
|
* @param string $file the filename
|
||||||
|
* @param \OCP\Files\IAppData $appData
|
||||||
|
* @param \OCP\IURLGenerator $urlGenerator
|
||||||
|
* @param \OC\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, $appData, $urlGenerator, $systemConfig, $webRoot = null) {
|
||||||
|
if (is_file($root.'/'.$file)) {
|
||||||
|
$scssCache = new SCSSCacher(
|
||||||
|
$this->logger,
|
||||||
|
$root,
|
||||||
|
$file,
|
||||||
|
$appData,
|
||||||
|
$urlGenerator,
|
||||||
|
$systemConfig);
|
||||||
|
|
||||||
|
if($scssCache->process()) {
|
||||||
|
$this->append($root, $scssCache->getCachedSCSS('core'), $webRoot, false);
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
$this->logger->error('Failed to compile and/or save '.$root.'/'.$file, ['app' => 'core']);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -106,38 +106,6 @@ abstract class ResourceLocator {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* cache and append the scss $file if exist at $root
|
|
||||||
*
|
|
||||||
* @param string $root path to check
|
|
||||||
* @param string $file the filename
|
|
||||||
* @param \OCP\Files\IAppData $appData
|
|
||||||
* @param \OCP\IURLGenerator $urlGenerator
|
|
||||||
* @param \OC\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, $appData, $urlGenerator, $systemConfig, $webRoot = null) {
|
|
||||||
if (is_file($root.'/'.$file)) {
|
|
||||||
$scssCache = new \OC\Template\SCSSCacher(
|
|
||||||
$this->logger,
|
|
||||||
$root,
|
|
||||||
$file,
|
|
||||||
$appData,
|
|
||||||
$urlGenerator,
|
|
||||||
$systemConfig);
|
|
||||||
|
|
||||||
if($scssCache->process()) {
|
|
||||||
$this->append($root, $scssCache->getCachedSCSS('core'), $webRoot, false);
|
|
||||||
return true;
|
|
||||||
} else {
|
|
||||||
$this->logger->error('Failed to compile and/or save '.$root.'/'.$file, ['app' => 'core']);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* append the $file resource at $root
|
* append the $file resource at $root
|
||||||
*
|
*
|
||||||
|
|
|
@ -23,39 +23,59 @@ namespace OC\Template;
|
||||||
|
|
||||||
use Leafo\ScssPhp\Compiler;
|
use Leafo\ScssPhp\Compiler;
|
||||||
use Leafo\ScssPhp\Exception\ParserException;
|
use Leafo\ScssPhp\Exception\ParserException;
|
||||||
|
use Leafo\ScssPhp\Formatter\Crunched;
|
||||||
|
use Leafo\ScssPhp\Formatter\Expanded;
|
||||||
use OC\Files\SimpleFS\SimpleFolder;
|
use OC\Files\SimpleFS\SimpleFolder;
|
||||||
|
use OC\SystemConfig;
|
||||||
|
use OCP\Files\IAppData;
|
||||||
use OCP\Files\NotFoundException;
|
use OCP\Files\NotFoundException;
|
||||||
|
use OCP\ILogger;
|
||||||
|
use OCP\IURLGenerator;
|
||||||
|
|
||||||
class SCSSCacher {
|
class SCSSCacher {
|
||||||
|
|
||||||
/**
|
/** @var string The root path to the nextcloud installation */
|
||||||
* @var string The root path to the nextcloud installation
|
protected $root;
|
||||||
* @var array The exploded absolute path to the file
|
|
||||||
* @var string The scss filename with extension
|
/** @var array The exploded absolute path to the file */
|
||||||
* @var string The css filename with extension
|
protected $file;
|
||||||
* @var string Absolute path to scss file location folder
|
|
||||||
* @var string Path to scss file from the root installation
|
/** @var string The scss filename with extension */
|
||||||
* @var SimpleFolder The folder we're putting our compiled css files
|
protected $fileNameSCSS;
|
||||||
*/
|
|
||||||
protected $root, $file, $fileNameSCSS, $fileNameCSS, $fileLoc, $rootCssLoc, $folder;
|
/** @var string The css filename with extension */
|
||||||
|
protected $fileNameCSS;
|
||||||
|
|
||||||
|
/** @var string Absolute path to scss file location folder */
|
||||||
|
protected $fileLoc;
|
||||||
|
|
||||||
|
/** @var string Path to scss file from the root installation */
|
||||||
|
protected $rootCssLoc;
|
||||||
|
|
||||||
|
/** @var SimpleFolder The folder we're putting our compiled css files */
|
||||||
|
protected $folder;
|
||||||
|
|
||||||
|
/** @var ILogger */
|
||||||
|
protected $logger;
|
||||||
|
|
||||||
|
/** @var IAppData */
|
||||||
|
protected $appData;
|
||||||
|
|
||||||
|
/** @var IURLGenerator */
|
||||||
|
protected $urlGenerator;
|
||||||
|
|
||||||
|
/** @var SystemConfig */
|
||||||
|
protected $systemConfig;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var \OCP\ILogger
|
* @param ILogger $logger
|
||||||
* @var \OCP\Files\IAppData
|
|
||||||
* @var \OCP\IURLGenerator
|
|
||||||
* @var \OC\SystemConfig
|
|
||||||
*/
|
|
||||||
protected $logger, $appData, $urlGenerator, $systemConfig;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param \OCP\ILogger $logger
|
|
||||||
* @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 \OCP\Files\IAppData $appData
|
* @param IAppData $appData
|
||||||
* @param \OCP\IURLGenerator $urlGenerator
|
* @param IURLGenerator $urlGenerator
|
||||||
* @param \OC\SystemConfig $systemConfig
|
* @param SystemConfig $systemConfig
|
||||||
*/
|
*/
|
||||||
public function __construct(\OCP\ILogger $logger, $root, $file, \OCP\Files\IAppData $appData, \OCP\IURLGenerator $urlGenerator, \OC\SystemConfig $systemConfig) {
|
public function __construct(ILogger $logger, $root, $file, IAppData $appData, IURLGenerator $urlGenerator, SystemConfig $systemConfig) {
|
||||||
$this->logger = $logger;
|
$this->logger = $logger;
|
||||||
$this->appData = $appData;
|
$this->appData = $appData;
|
||||||
$this->urlGenerator = $urlGenerator;
|
$this->urlGenerator = $urlGenerator;
|
||||||
|
@ -122,11 +142,11 @@ class SCSSCacher {
|
||||||
$scss->setImportPaths($this->fileLoc);
|
$scss->setImportPaths($this->fileLoc);
|
||||||
if($this->systemConfig->getValue('debug')) {
|
if($this->systemConfig->getValue('debug')) {
|
||||||
// Debug mode
|
// Debug mode
|
||||||
$scss->setFormatter('Leafo\ScssPhp\Formatter\Expanded');
|
$scss->setFormatter(Expanded::class);
|
||||||
$scss->setLineNumberStyle(Compiler::LINE_COMMENTS);
|
$scss->setLineNumberStyle(Compiler::LINE_COMMENTS);
|
||||||
} else {
|
} else {
|
||||||
// Compression
|
// Compression
|
||||||
$scss->setFormatter('Leafo\ScssPhp\Formatter\Crunched');
|
$scss->setFormatter(Crunched::class);
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
Loading…
Reference in New Issue