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

New: Added theme variables to compilation (fixes #3577) #3578

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
29 changes: 23 additions & 6 deletions grunt/tasks/less.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,17 @@ module.exports = function(grunt) {
.replace(convertSlashes, '/');
const cwd = process.cwd();

let configJSON;
try {
configJSON = JSON.parse(grunt.file.read(options.config)
.toString());
} catch (e) {}

let imports = '';
let src = '';

if (options.src && options.config) {
let screenSize;
try {
const configjson = JSON.parse(grunt.file.read(options.config)
.toString());
screenSize = configjson?.screenSize;
} catch (e) {}
const screenSize = configJSON?.screenSize;
if (!screenSize) {
const error = new Error('No screenSize defined in config.json');
const errorString = error.toString();
Expand Down Expand Up @@ -81,6 +82,22 @@ module.exports = function(grunt) {
}
}

if (configJSON.themeVariables) {
// Add theme variables
function fetchVariableNameValuePairs(object) {
return Object.entries(object).flatMap(([name, value]) => {
if (value === '' || value === null) return [];
if (typeof value !== 'object') return [[ name, value ]];
return fetchVariableNameValuePairs(value);
});
}
const variableNameValuePairs = fetchVariableNameValuePairs(configJSON.themeVariables);
// Add less variables
imports += variableNameValuePairs.map(([name, value]) => `\n@${name}: ${value};`).join('');
// Add css variables
imports += `\n:root {\n ${variableNameValuePairs.map(([name, value]) => `\n --adapt-${name}: ${value};`).join('')}\n}`;
}

let sourcemaps;
if (options.sourcemaps) {
sourcemaps = {
Expand Down
120 changes: 120 additions & 0 deletions src/course/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -78,5 +78,125 @@
},
"build": {
"strictMode": true
},
"themeVariables": {
"_global": {
"font-color": "",
"font-color-inverted": "",
"link": "",
"link-inverted": "",
"link-hover": "",
"link-inverted-hover": "",
"heading-color": "",
"heading-color-inverted": ""
},
"_items": {
"item-color": "",
"item-color-inverted": "",
"item-color-hover": "",
"item-color-inverted-hover": "",
"item-color-selected": "",
"item-color-inverted-selected": "",
"visited": "",
"visited-inverted": ""
},
"_buttons": {
"btn-color": "",
"btn-color-inverted": "",
"btn-color-hover": "",
"btn-color-inverted-hover": "",
"btn-icon-color": "",
"btn-icon-color-inverted": "",
"btn-icon-color-hover": "",
"btn-icon-color-inverted-hover": "",
"disabled": "",
"disabled-inverted": ""
},
"_validation": {
"validation-success": "",
"validation-success-inverted": "",
"validation-error": "",
"validation-error-inverted": ""
},
"_progress": {
"progress": "",
"progress-inverted": "",
"progress-border": ""
},
"_menu": {
"menu-header-background-color": "",
"menu-header-title-color": "",
"menu-header-subtitle-color": "",
"menu-header-body-color": "",
"menu-header-instruction-color": "",
"menu-item": "",
"menu-item-inverted": "",
"menu-item-border-color": "",
"menu-item-progress": "",
"menu-item-progress-inverted": "",
"menu-item-progress-border": "",
"menu-item-btn-color": "",
"menu-item-btn-color-inverted": "",
"menu-item-btn-color-hover": "",
"menu-item-btn-color-inverted-hover": ""
},
"_nav": {
"nav": "",
"nav-inverted": "",
"nav-icon": "",
"nav-icon-inverted": "",
"nav-icon-hover": "",
"nav-icon-inverted-hover": "",
"nav-progress": "",
"nav-progress-inverted": "",
"nav-progress-border": "",
"nav-progress-hover": "",
"nav-progress-inverted-hover": "",
"nav-progress-border-hover": ""
},
"_notify": {
"notify": "",
"notify-inverted": "",
"notify-link": "",
"notify-link-hover": "",
"notify-btn": "",
"notify-btn-inverted": "",
"notify-btn-hover": "",
"notify-btn-inverted-hover": "",
"notify-icon": "",
"notify-icon-inverted": "",
"notify-icon-hover": "",
"notify-icon-inverted-hover": ""
},
"_drawer": {
"drawer": "",
"drawer-inverted": "",
"drawer-link": "",
"drawer-link-hover": "",
"drawer-icon": "",
"drawer-icon-inverted": "",
"drawer-icon-hover": "",
"drawer-icon-inverted-hover": "",
"drawer-item": "",
"drawer-item-inverted": "",
"drawer-item-hover": "",
"drawer-item-inverted-hover": "",
"drawer-item-selected": "",
"drawer-item-inverted-selected": "",
"drawer-progress": "",
"drawer-progress-inverted": "",
"drawer-progress-border": "",
"drawer-progress-hover": "",
"drawer-progress-inverted-hover": "",
"drawer-progress-border-hover": ""
},
"_misc": {
"background": "",
"background-inverted": "",
"shadow": "",
"shadow-inverted": "",
"loading": "",
"loading-inverted": ""
}
}
}