Projet

Général

Profil

0001-misc-include-list-of-scss-options-in-themes.json-340.patch

Frédéric Péters, 16 juin 2019 20:29

Télécharger (2,89 ko)

Voir les différences:

Subject: [PATCH] misc: include list of scss options in themes.json (#34027)

 Makefile              |  4 ++--
 create_themes_json.py | 31 ++++++++++++++++++++++++++++++-
 2 files changed, 32 insertions(+), 3 deletions(-)
Makefile
23 23
static/hellemmes/_data_uris.scss: $(wildcard static/hellemmes/img/*)
24 24
	python make_data_uris.py static/hellemmes/
25 25

  
26
themes.json: $(wildcard static/*/config.json)
27
	python create_themes_json.py
26
themes.json: $(wildcard static/*/config.json) help/fr/misc-scss.page
27
	python3 create_themes_json.py
28 28

  
29 29
%.css: export LC_ALL=C.UTF-8
30 30
.SECONDEXPANSION:
create_themes_json.py
3 3
import argparse
4 4
import json
5 5
import os
6
import xml.etree.ElementTree as ET
6 7

  
7 8
parser = argparse.ArgumentParser()
8 9
parser.add_argument('--overlay', dest='overlay', type=str)
9 10
args = parser.parse_args()
10 11

  
12
# get themes
11 13
themes = []
12 14
for dirname in sorted(os.listdir('static')):
13 15
    config = os.path.join('static', dirname, 'config.json')
......
28 30
        theme['overlay'] = args.overlay
29 31
    themes.append(theme)
30 32

  
33
# get parameters
34
parameters = {'primary-color': {'type': 'color'}}
35
if os.path.exists('help/fr/misc-scss.page'):
36
    tree = ET.parse('help/fr/misc-scss.page')
37
    for element in tree.findall('.//{http://projectmallard.org/1.0/}tr'):
38
        name, description, value = element.findall('{http://projectmallard.org/1.0/}td')
39
        name = ''.join(name.itertext()).strip('$')
40
        description = ''.join(description.itertext()).strip('$')
41
        value = ''.join(value.itertext()).strip('$')
42
        parameter_type = 'text'
43
        if (value.startswith('#') or value in ('white', 'black') or
44
                name.endswith('color') or name.endswith('background')):
45
            parameter_type = 'color'
46
        if value.endswith('px') or value.endswith('rem') or name.endswith('size'):
47
            parameter_type = 'size'
48
        if value in ('true', 'false'):
49
            parameter_type = 'boolean'
50
        if name.endswith('weight'):
51
            parameter_type = 'weight'
52
        if name.endswith('family'):
53
            parameter_type = 'family'
54
        parameters[name] = {
55
            'type': parameter_type,
56
            'description': description,
57
        }
58

  
59

  
31 60
with open('themes.json', 'w') as fd:
32
    json.dump({'themes': themes}, fd, indent=2, sort_keys=True)
61
    json.dump({'themes': themes, 'parameters': parameters}, fd, indent=2, sort_keys=True)
33
-