misc: include list of scss options in themes.json (#34027)

This commit is contained in:
Frédéric Péters 2019-06-16 20:28:01 +02:00
parent db81481f76
commit 24d3744b1f
2 changed files with 32 additions and 3 deletions

View File

@ -23,8 +23,8 @@ static/lomme/_data_uris.scss: $(wildcard static/lomme/img/*)
static/hellemmes/_data_uris.scss: $(wildcard static/hellemmes/img/*)
python make_data_uris.py static/hellemmes/
themes.json: $(wildcard static/*/config.json)
python create_themes_json.py
themes.json: $(wildcard static/*/config.json) help/fr/misc-scss.page
python3 create_themes_json.py
%.css: export LC_ALL=C.UTF-8
.SECONDEXPANSION:

View File

@ -3,11 +3,13 @@
import argparse
import json
import os
import xml.etree.ElementTree as ET
parser = argparse.ArgumentParser()
parser.add_argument('--overlay', dest='overlay', type=str)
args = parser.parse_args()
# get themes
themes = []
for dirname in sorted(os.listdir('static')):
config = os.path.join('static', dirname, 'config.json')
@ -28,5 +30,32 @@ for dirname in sorted(os.listdir('static')):
theme['overlay'] = args.overlay
themes.append(theme)
# get parameters
parameters = {'primary-color': {'type': 'color'}}
if os.path.exists('help/fr/misc-scss.page'):
tree = ET.parse('help/fr/misc-scss.page')
for element in tree.findall('.//{http://projectmallard.org/1.0/}tr'):
name, description, value = element.findall('{http://projectmallard.org/1.0/}td')
name = ''.join(name.itertext()).strip('$')
description = ''.join(description.itertext()).strip('$')
value = ''.join(value.itertext()).strip('$')
parameter_type = 'text'
if (value.startswith('#') or value in ('white', 'black') or
name.endswith('color') or name.endswith('background')):
parameter_type = 'color'
if value.endswith('px') or value.endswith('rem') or name.endswith('size'):
parameter_type = 'size'
if value in ('true', 'false'):
parameter_type = 'boolean'
if name.endswith('weight'):
parameter_type = 'weight'
if name.endswith('family'):
parameter_type = 'family'
parameters[name] = {
'type': parameter_type,
'description': description,
}
with open('themes.json', 'w') as fd:
json.dump({'themes': themes}, fd, indent=2, sort_keys=True)
json.dump({'themes': themes, 'parameters': parameters}, fd, indent=2, sort_keys=True)