Skip to content

Commit

Permalink
Add default theming into accessibility compiler
Browse files Browse the repository at this point in the history
Signed-off-by: John Molakvoæ (skjnldsv) <skjnldsv@protonmail.com>
  • Loading branch information
skjnldsv committed Aug 15, 2018
1 parent 62a9ec1 commit a7c426a
Showing 1 changed file with 34 additions and 1 deletion.
35 changes: 34 additions & 1 deletion apps/accessibility/lib/Controller/AccessibilityController.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,12 @@ class AccessibilityController extends Controller {
/** @var IconsCacher */
protected $iconsCacher;

/** @var \OC_Defaults */
private $defaults;

/** @var null|string */
private $injectedVariables;

/**
* Account constructor.
*
Expand All @@ -82,6 +88,7 @@ class AccessibilityController extends Controller {
* @param ITimeFactory $timeFactory
* @param IUserSession $userSession
* @param IAppManager $appManager
* @param \OC_Defaults $defaults
*/
public function __construct(string $appName,
IRequest $request,
Expand All @@ -92,7 +99,8 @@ public function __construct(string $appName,
ITimeFactory $timeFactory,
IUserSession $userSession,
IAppManager $appManager,
IconsCacher $iconsCacher) {
IconsCacher $iconsCacher,
\OC_Defaults $defaults) {
parent::__construct($appName, $request);
$this->appName = $appName;
$this->config = $config;
Expand All @@ -103,6 +111,7 @@ public function __construct(string $appName,
$this->userSession = $userSession;
$this->appManager = $appManager;
$this->iconsCacher = $iconsCacher;
$this->defaults = $defaults;

$this->serverRoot = \OC::$SERVERROOT;
$this->appRoot = $this->appManager->getAppPath($this->appName);
Expand Down Expand Up @@ -141,6 +150,7 @@ public function getCss(): DataDisplayResponse {
$css .= $scss->compile(
$imports .
'@import "variables.scss";' .
$this->getInjectedVariables() .
'@import "css-variables.scss";'
);
} catch (ParserException $e) {
Expand Down Expand Up @@ -220,4 +230,27 @@ private function rebaseUrls(string $css, string $webDir): string {
private function invertSvgIconsColor(string $css) {
return str_replace(['/000', '/fff', '/***'], ['/***', '/000', '/fff'], $css);
}

/**
* @return string SCSS code for variables from OC_Defaults
*/
private function getInjectedVariables(): string {
if ($this->injectedVariables !== null) {
return $this->injectedVariables;
}
$variables = '';
foreach ($this->defaults->getScssVariables() as $key => $value) {
$variables .= '$' . $key . ': ' . $value . ';';
}

// check for valid variables / otherwise fall back to defaults
try {
$scss = new Compiler();
$scss->compile($variables);
$this->injectedVariables = $variables;
} catch (ParserException $e) {
$this->logger->error($e, ['app' => 'core']);
}
return $variables;
}
}

0 comments on commit a7c426a

Please sign in to comment.