Browse Source

Started work on a 'dynamic SASS' system.

development
Bryan Miller 4 years ago
parent
commit
dd184064a3
No known key found for this signature in database
3 changed files with 66 additions and 6 deletions
  1. +26
    -3
      app/index.js
  2. +38
    -0
      app/styles.js
  3. +2
    -3
      view/sass/main.scss

+ 26
- 3
app/index.js View File

@@ -1,8 +1,31 @@


const sass = require('sass');
const styles = require('../app/styles');

console.log("Hello there")
async function start(){
let style = null;
try {
style = await styles.render("main");
} catch (err) {
console.log(err);
}

if (style !== null){
console.log(style);
let e = document.createElement('style');
e.innerHTML = style.css.toString();

let head = document.getElementsByTagName('head');
if (head.length > 0)
head = head[0]; // There should really only be one head... we're not a hydra!!!
head.appendChild(e);
}
}

console.log("Kicking the pig!");
start();

/*
sass.render({file: 'view/sass/main.scss'}, (err, res) => {
if (err){
console.log(err);
@@ -17,5 +40,5 @@ sass.render({file: 'view/sass/main.scss'}, (err, res) => {
head = head[0]; // There should really only be one head... we're not a hydra!!!
head.appendChild(style);
});
*/


+ 38
- 0
app/styles.js View File

@@ -0,0 +1,38 @@

const sass = require('sass');

// TODO: Once configs are setup, make this section more dynamic!!
var VARS = {
COLOR_LIGHTER: "#fffcf2",
COLOR_LIGHT: "#ccc5b9",
COLOR_DARK: "#403d39",
COLOR_DARKER: "#252422",
COLOR_HIGHLIGHT: "#eb5e28",
UI_SCALE: 1.0
};


function buildSASSVars(){
let res = "";
Object.keys(VARS).forEach((key)=>{
res = res + "$" + key + ": " + VARS[key] + ";\n";
});
return res;
}

function render(entryfile){
return new Promise((res, rej) => {
let entry = buildSASSVars() + "@import '" + entryfile + "';\n";
sass.render({data: entry, includePaths:['view/sass/']}, (err, data) => {
if (err){rej(err);}
res(data);
});
});
}


module.exports = {
render
};



+ 2
- 3
view/sass/main.scss View File

@@ -1,7 +1,6 @@

@import 'colors';

body {
background-color: $COLOR_MAIN;
background-color: $COLOR_DARK;
color: $COLOR_LIGHT;
}


Loading…
Cancel
Save