Use courier in all rendering tests

This commit is contained in:
Knut Sveidqvist
2020-08-16 21:49:36 +02:00
parent 236332d8c7
commit 6b23c71bb5
17 changed files with 191 additions and 107 deletions

View File

@@ -8,29 +8,43 @@ import config from './defaultConfig';
export const defaultConfig = Object.freeze(config);
let siteConfig = assignWithDepth({}, defaultConfig);
let siteConfigDelta;
let directives = [];
let currentConfig = assignWithDepth({}, defaultConfig);
export const updateCurrentConfig = (siteCfg, _directives) => {
// start with config beeing the siteConfig
let cfg = assignWithDepth({}, siteCfg);
// let sCfg = assignWithDepth(defaultConfig, siteConfigDelta);
// Apply directives
// Join directives
let themeVariables = {};
let sumOfDirectives = {};
for (let i = 0; i < _directives.length; i++) {
const d = _directives[i];
sanitize(d);
cfg = assignWithDepth(cfg, d);
if (d.theme) {
cfg.themeVariables = theme[cfg.theme].getThemeVariables(d.themeVariables);
}
// Apply the data from the directive where the the overrides the themeVaraibles
sumOfDirectives = assignWithDepth(sumOfDirectives, d);
}
if (cfg.theme && theme[cfg.theme]) {
let tVars = assignWithDepth({}, cfg.themeVariables);
tVars = assignWithDepth(tVars, themeVariables);
const variables = theme[cfg.theme].getThemeVariables(tVars);
cfg.themeVariables = variables;
cfg = assignWithDepth(cfg, sumOfDirectives);
if (sumOfDirectives.theme) {
const themeVariables = assignWithDepth(
siteConfigDelta.themeVariables || {},
sumOfDirectives.themeVariables
);
cfg.themeVariables = theme[cfg.theme].getThemeVariables(themeVariables);
}
// if (cfg.theme && theme[cfg.theme]) {
// let tVars = assignWithDepth({}, cfg.themeVariables);
// tVars = assignWithDepth(tVars, themeVariables);
// const variables = theme[cfg.theme].getThemeVariables(tVars);
// cfg.themeVariables = variables;
// }
currentConfig = cfg;
return cfg;
};
@@ -59,6 +73,28 @@ export const setSiteConfig = conf => {
currentConfig = updateCurrentConfig(siteConfig, directives);
return siteConfig;
};
const deepCopyFunction = inObject => {
let outObject, value, key;
if (typeof inObject !== 'object' || inObject === null) {
return inObject; // Return the value if inObject is not an object
}
// Create an array or object to hold the values
outObject = Array.isArray(inObject) ? [] : {};
for (key in inObject) {
value = inObject[key];
// Recursively (deep) copy for nested objects, including arrays
outObject[key] = deepCopyFunction(value);
}
return outObject;
};
export const setSiteConfigDelta = conf => {
siteConfigDelta = assignWithDepth({}, conf);
};
export const updateSiteConfig = conf => {
siteConfig = assignWithDepth(siteConfig, conf);
updateCurrentConfig(siteConfig, directives);