From 0419a844ce3f2b4b0f81c43ff13dfcf03942ae91 Mon Sep 17 00:00:00 2001 From: Danielle McLean Date: Fri, 27 Oct 2017 11:33:01 +1100 Subject: [PATCH] Load the Material colour scheme directly from the source YAML, rather than hardcoding it into Stylus format --- .gitmodules | 3 +++ lemoncurry/settings/base.py | 2 +- lemoncurry/static/base16-materialtheme-scheme | 1 + .../css/base16-material-darker.styl | 17 --------------- lemoncurry/static/lemoncurry/css/layout.styl | 2 -- lemoncurry/static/lemoncurry/css/theme.js | 18 ++++++++++++++++ package.json | 1 + yarn.lock | 21 +++++++++++++++++++ 8 files changed, 45 insertions(+), 20 deletions(-) create mode 100644 .gitmodules create mode 160000 lemoncurry/static/base16-materialtheme-scheme delete mode 100644 lemoncurry/static/lemoncurry/css/base16-material-darker.styl create mode 100644 lemoncurry/static/lemoncurry/css/theme.js diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..cfcc73b --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "lemoncurry/static/base16-materialtheme-scheme"] + path = lemoncurry/static/base16-materialtheme-scheme + url = git://github.com/ntpeters/base16-materialtheme-scheme.git diff --git a/lemoncurry/settings/base.py b/lemoncurry/settings/base.py index 5eb61e7..5487fc9 100644 --- a/lemoncurry/settings/base.py +++ b/lemoncurry/settings/base.py @@ -192,7 +192,7 @@ STATICFILES_FINDERS = ( ) COMPRESS_PRECOMPILERS = ( - ('text/stylus', os.path.join(BASE_DIR, 'node_modules', '.bin', 'stylus') + ' {infile} -o {outfile}'), + ('text/stylus', './node_modules/.bin/stylus {infile} -u ./lemoncurry/static/lemoncurry/css/theme -o {outfile}'), ) MEDIA_URL = STATIC_URL + 'media/' diff --git a/lemoncurry/static/base16-materialtheme-scheme b/lemoncurry/static/base16-materialtheme-scheme new file mode 160000 index 0000000..cbbc474 --- /dev/null +++ b/lemoncurry/static/base16-materialtheme-scheme @@ -0,0 +1 @@ +Subproject commit cbbc47444208fb8f28dbc48ea986c9dc81843e9a diff --git a/lemoncurry/static/lemoncurry/css/base16-material-darker.styl b/lemoncurry/static/lemoncurry/css/base16-material-darker.styl deleted file mode 100644 index bd64510..0000000 --- a/lemoncurry/static/lemoncurry/css/base16-material-darker.styl +++ /dev/null @@ -1,17 +0,0 @@ -// Source: https://github.com/ntpeters/base16-materialtheme-scheme/blob/cbbc474/material-darker.yaml -$base00 = #212121 -$base01 = #303030 -$base02 = #353535 -$base03 = #4A4A4A -$base04 = #B2CCD6 -$base05 = #EEFFFF -$base06 = #EEFFFF -$base07 = #FFFFFF -$base08 = #F07178 -$base09 = #F78C6C -$base0A = #FFCB6B -$base0B = #C3E88D -$base0C = #89DDFF -$base0D = #82AAFF -$base0E = #C792EA -$base0F = #FF5370 diff --git a/lemoncurry/static/lemoncurry/css/layout.styl b/lemoncurry/static/lemoncurry/css/layout.styl index 28aff7c..3138d2b 100644 --- a/lemoncurry/static/lemoncurry/css/layout.styl +++ b/lemoncurry/static/lemoncurry/css/layout.styl @@ -1,5 +1,3 @@ -@import 'base16-material-darker' - html background-color $base01 diff --git a/lemoncurry/static/lemoncurry/css/theme.js b/lemoncurry/static/lemoncurry/css/theme.js new file mode 100644 index 0000000..47d0b61 --- /dev/null +++ b/lemoncurry/static/lemoncurry/css/theme.js @@ -0,0 +1,18 @@ +const {join} = require('path'); +const {readFileSync} = require('fs'); + +const stylus = require('stylus'); +const {safeLoad} = require('js-yaml'); + +const themePath = join(__dirname, '..', '..', 'base16-materialtheme-scheme', 'material-darker.yaml'); + +module.exports = function() { + const theme = safeLoad(readFileSync(themePath, 'utf8')); + return function(style) { + for (let i = 0; i < 16; i++) { + const key = 'base0' + i.toString(16).toUpperCase(); + + style.define('$' + key, new stylus.nodes.Literal('#' + theme[key])); + } + }; +}; diff --git a/package.json b/package.json index ad98269..b948d02 100644 --- a/package.json +++ b/package.json @@ -4,6 +4,7 @@ "repository": "https://gitlab.com/00dani/lemoncurry", "license": "MIT", "devDependencies": { + "js-yaml": "^3.10.0", "stylus": "^0.54.5" }, "dependencies": { diff --git a/yarn.lock b/yarn.lock index 03b8036..448e842 100644 --- a/yarn.lock +++ b/yarn.lock @@ -6,6 +6,12 @@ amdefine@>=0.0.4: version "1.0.1" resolved "https://registry.yarnpkg.com/amdefine/-/amdefine-1.0.1.tgz#4a5282ac164729e93619bcfd3ad151f817ce91f5" +argparse@^1.0.7: + version "1.0.9" + resolved "https://registry.yarnpkg.com/argparse/-/argparse-1.0.9.tgz#73d83bc263f86e97f8cc4f6bae1b0e90a7d22c86" + dependencies: + sprintf-js "~1.0.2" + balanced-match@^1.0.0: version "1.0.0" resolved "https://registry.yarnpkg.com/balanced-match/-/balanced-match-1.0.0.tgz#89b4d199ab2bee49de164ea02b89ce462d71b767" @@ -31,6 +37,10 @@ debug@*: dependencies: ms "2.0.0" +esprima@^4.0.0: + version "4.0.0" + resolved "https://registry.yarnpkg.com/esprima/-/esprima-4.0.0.tgz#4499eddcd1110e0b218bacf2fa7f7f59f55ca804" + fs.realpath@^1.0.0: version "1.0.0" resolved "https://registry.yarnpkg.com/fs.realpath/-/fs.realpath-1.0.0.tgz#1504ad2523158caa40db4a2787cb01411994ea4f" @@ -57,6 +67,13 @@ inherits@2: version "2.0.3" resolved "https://registry.yarnpkg.com/inherits/-/inherits-2.0.3.tgz#633c2c83e3da42a502f52466022480f4208261de" +js-yaml@^3.10.0: + version "3.10.0" + resolved "https://registry.yarnpkg.com/js-yaml/-/js-yaml-3.10.0.tgz#2e78441646bd4682e963f22b6e92823c309c62dc" + dependencies: + argparse "^1.0.7" + esprima "^4.0.0" + minimatch@^3.0.2: version "3.0.4" resolved "https://registry.yarnpkg.com/minimatch/-/minimatch-3.0.4.tgz#5166e286457f03306064be5497e8dbb0c3d32083" @@ -101,6 +118,10 @@ source-map@0.1.x: dependencies: amdefine ">=0.0.4" +sprintf-js@~1.0.2: + version "1.0.3" + resolved "https://registry.yarnpkg.com/sprintf-js/-/sprintf-js-1.0.3.tgz#04e6926f662895354f3dd015203633b857297e2c" + stylus@^0.54.5: version "0.54.5" resolved "https://registry.yarnpkg.com/stylus/-/stylus-0.54.5.tgz#42b9560931ca7090ce8515a798ba9e6aa3d6dc79"