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

Add default theming into accessibility compiler #10689

Merged
merged 1 commit into from
Aug 15, 2018
Merged
Changes from all commits
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
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;
}
}