summaryrefslogtreecommitdiffstats
path: root/lib/private/Template/CSSResourceLocator.php
diff options
context:
space:
mode:
Diffstat (limited to 'lib/private/Template/CSSResourceLocator.php')
-rw-r--r--lib/private/Template/CSSResourceLocator.php52
1 files changed, 50 insertions, 2 deletions
diff --git a/lib/private/Template/CSSResourceLocator.php b/lib/private/Template/CSSResourceLocator.php
index ffeaf765ff5..3a474a1ecfd 100644
--- a/lib/private/Template/CSSResourceLocator.php
+++ b/lib/private/Template/CSSResourceLocator.php
@@ -25,23 +25,46 @@
namespace OC\Template;
+use OCP\ILogger;
+
class CSSResourceLocator extends ResourceLocator {
+
+ /** @var SCSSCacher */
+ protected $scssCacher;
+
+ /**
+ * @param ILogger $logger
+ * @param string $theme
+ * @param array $core_map
+ * @param array $party_map
+ * @param SCSSCacher $scssCacher
+ */
+ public function __construct(ILogger $logger, $theme, $core_map, $party_map, $scssCacher) {
+ $this->scssCacher = $scssCacher;
+
+ parent::__construct($logger, $theme, $core_map, $party_map);
+ }
+
/**
* @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', $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($app_path, $style.'.scss', $app)) {
+ $this->append($app_path, $style.'.css', $app_url);
+ }
}
/**
@@ -53,4 +76,29 @@ class CSSResourceLocator extends ResourceLocator {
|| $this->appendIfExist($this->serverroot, $theme_dir.$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
+ * @return bool True if the resource was found and cached, false otherwise
+ */
+ 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);
+ return true;
+ } else {
+ $this->logger->warning('Failed to compile and/or save '.$root.'/'.$file, ['app' => 'core']);
+ return false;
+ }
+ } else {
+ $this->logger->debug('Scss is disabled for '.$root.'/'.$file.', ignoring', ['app' => 'core']);
+ return true;
+ }
+ }
+ return false;
+ }
}