Async SCSS configuration

This commit is contained in:
Samuel Elliott 2018-02-21 00:14:06 +00:00
parent 0be09f6cf8
commit 2eaafdb1ac
No known key found for this signature in database
GPG Key ID: 8420C7CDE43DC4D6
2 changed files with 9 additions and 7 deletions

View File

@ -135,7 +135,7 @@ export default class Theme {
let css = '';
if (this.info.type === 'sass') {
css = await ClientIPC.send('bd-compileSass', {
data: ThemeManager.getConfigAsSCSS(this.config),
data: await ThemeManager.getConfigAsSCSS(this.config),
path: this.paths.mainPath.replace(/\\/g, '/')
});
console.log(css);

View File

@ -64,12 +64,12 @@ export default class ThemeManager extends ContentManager {
theme.recompile();
}
static getConfigAsSCSS(config) {
static async getConfigAsSCSS(config) {
const variables = [];
for (let category of config) {
for (let setting of category.settings) {
const setting_scss = this.parseSetting(setting);
const setting_scss = await this.parseSetting(setting);
if (setting_scss) variables.push(`$${setting_scss[0]}: ${setting_scss[1]};`);
}
}
@ -77,12 +77,12 @@ export default class ThemeManager extends ContentManager {
return variables.join('\n');
}
static getConfigAsSCSSMap(config) {
static async getConfigAsSCSSMap(config) {
const variables = [];
for (let category of config) {
for (let setting of category.settings) {
const setting_scss = this.parseSetting(setting);
const setting_scss = await this.parseSetting(setting);
if (setting_scss) variables.push(`${setting_scss[0]}: (${setting_scss[1]})`);
}
}
@ -90,7 +90,7 @@ export default class ThemeManager extends ContentManager {
return '(' + variables.join(', ') + ')';
}
static parseSetting(setting) {
static async parseSetting(setting) {
const { type, id, value } = setting;
const name = id.replace(/[^a-zA-Z0-9-]/g, '-').replace(/--/g, '-');
@ -116,7 +116,9 @@ export default class ThemeManager extends ContentManager {
console.log('items', items);
// Final comma ensures the variable is a list
const maps = items.map(i => this.getConfigAsSCSSMap(i.settings));
const maps = [];
for (let item of items)
maps.push(await this.getConfigAsSCSSMap(item.settings));
return [name, maps.length ? maps.join(', ') + ',' : '()'];
}