update build script (new-style themes and css)
This commit is contained in:
parent
db531f7abc
commit
b9387eb26f
1 changed files with 81 additions and 35 deletions
|
@ -1,7 +1,6 @@
|
||||||
#!/usr/bin/env python
|
#!/usr/bin/env python
|
||||||
#vim: et:ts=4:sw=4:sts=4
|
#vim: et:ts=4:sw=4:sts=4
|
||||||
|
|
||||||
import base64
|
|
||||||
import json
|
import json
|
||||||
import os
|
import os
|
||||||
import ox
|
import ox
|
||||||
|
@ -30,26 +29,41 @@ def build_oxjs(downloads=False, geo=False):
|
||||||
year = time.strftime('%Y', time.gmtime())
|
year = time.strftime('%Y', time.gmtime())
|
||||||
comment = ' OxJS %s (c) %s 0x2620, dual-licensed GPL/MIT, see https://oxjs.org for details ' % (version, year)
|
comment = ' OxJS %s (c) %s 0x2620, dual-licensed GPL/MIT, see https://oxjs.org for details ' % (version, year)
|
||||||
|
|
||||||
# SVGs
|
# Ox.UI Theme Data
|
||||||
path = source_path + 'Ox.UI/themes/classic/svg/'
|
theme_data = {}
|
||||||
for filename in os.listdir(path):
|
themes = [dirname for dirname in os.listdir(source_path + 'Ox.UI/themes/') if not dirname[0] in '._']
|
||||||
|
for theme in themes:
|
||||||
|
theme_data[theme] = read_jsonc(source_path + 'Ox.UI/themes/%s/json/theme.jsonc' % theme)
|
||||||
|
theme_data[theme]['themeClass'] = 'OxTheme' + theme[0].upper() + theme[1:]
|
||||||
|
|
||||||
|
# Ox.UI CSS
|
||||||
|
css = read_file(source_path + 'Ox.UI/css/Ox.UI.css')
|
||||||
|
css = css.replace('$import', '\n'.join([
|
||||||
|
'@import url("../themes/%s/css/theme.css");' % theme for theme in themes
|
||||||
|
]))
|
||||||
|
write_file('%sOx.UI/css/Ox.UI.css' % build_path, css)
|
||||||
|
write_file('%sOx.UI/css/Ox.UI.css' % dev_path, css)
|
||||||
|
|
||||||
|
# Ox.UI Theme CSS
|
||||||
|
css = read_file(source_path + 'Ox.UI/css/theme.css')
|
||||||
|
for theme in themes:
|
||||||
|
theme_css = parse_css(css, theme_data[theme])
|
||||||
|
write_file('%sOx.UI/themes/%s/css/theme.css' % (build_path, theme), theme_css)
|
||||||
|
write_file('%sOx.UI/themes/%s/css/theme.css' % (dev_path, theme), theme_css)
|
||||||
|
|
||||||
|
# Ox.UI SVGs
|
||||||
|
ui_images = {}
|
||||||
|
path = source_path + 'Ox.UI/svg/'
|
||||||
|
for filename in [filename for filename in os.listdir(path) if not filename[0] in '._']:
|
||||||
svg = read_file(path + filename)
|
svg = read_file(path + filename)
|
||||||
svg = svg.replace('#000000', '#XXXXXX').replace('#404040', '#C0C0C0').replace('#FFFFFF', '#000000').replace('#XXXXXX', '#FFFFFF')
|
svg = re.sub('\n\s*', '', svg)
|
||||||
write_file(path.replace('/classic/', '/modern/') + filename, svg)
|
svg = re.sub('<!--.+?-->', '', svg)
|
||||||
imageURLs = {}
|
ui_images[filename[:-4]] = svg
|
||||||
imageDataURLs = {}
|
if filename.startswith('symbolLoading'):
|
||||||
for theme in ['classic', 'modern']:
|
for theme in themes:
|
||||||
path = source_path + 'Ox.UI/themes/' + theme + '/svg/'
|
theme_svg = re.sub('#808080', format_hex(theme_data[theme]['symbolDefaultColor']), svg)
|
||||||
for filename in os.listdir(path):
|
write_file('%sOx.UI/themes/%s/svg/%s' % (build_path, theme, filename), theme_svg)
|
||||||
if not filename[0] in '._' and not filename.endswith('~'):
|
write_file('%sOx.UI/themes/%s/svg/%s' % (dev_path, theme, filename), theme_svg)
|
||||||
key = theme + '/' + filename[:-4]
|
|
||||||
imageURLs[key] = os.path.join(path, filename).replace(source_path, '')
|
|
||||||
data = re.sub('\n\s+', '', read_file(path + filename))
|
|
||||||
imageDataURLs[key] = 'data:image/svg+xml;base64,' + base64.b64encode(data)
|
|
||||||
write_file(build_path + 'Ox.UI/json/Ox.UI.imageURLs.json', json.dumps(imageURLs, sort_keys=True))
|
|
||||||
write_file(build_path + 'Ox.UI/json/Ox.UI.imageDataURLs.json', json.dumps(imageDataURLs, sort_keys=True))
|
|
||||||
write_file(dev_path + 'Ox.UI/json/Ox.UI.imageURLs.json', json.dumps(imageURLs, indent=4, sort_keys=True))
|
|
||||||
write_file(dev_path + 'Ox.UI/json/Ox.UI.imageDataURLs.json', json.dumps(imageDataURLs, indent=4, sort_keys=True))
|
|
||||||
|
|
||||||
# copy & link
|
# copy & link
|
||||||
ui_files = {'build': [], 'dev': []}
|
ui_files = {'build': [], 'dev': []}
|
||||||
|
@ -57,12 +71,15 @@ def build_oxjs(downloads=False, geo=False):
|
||||||
for filename in filenames:
|
for filename in filenames:
|
||||||
if not '_' in path and not filename[0] in '._' \
|
if not '_' in path and not filename[0] in '._' \
|
||||||
and not filename.endswith('~') \
|
and not filename.endswith('~') \
|
||||||
|
and not filename.endswith('.css') \
|
||||||
|
and not '/Ox.UI/svg' in path \
|
||||||
and (geo or not '/Ox.Geo/' in path):
|
and (geo or not '/Ox.Geo/' in path):
|
||||||
# write copies in build path
|
# write copies in build path
|
||||||
source = os.path.join(path, filename)
|
source = os.path.join(path, filename)
|
||||||
is_jquery = re.match('^jquery-[\d\.]+\.js$', filename)
|
is_jquery = re.search('^jquery-[\d\.]+\.js$', filename)
|
||||||
is_jquery_min = re.match('^jquery-[\d\.]+\.min\.js$', filename)
|
is_jquery_min = re.search('^jquery-[\d\.]+\.min\.js$', filename)
|
||||||
is_jquery_plugin = re.match('^jquery\..*?\.js$', filename)
|
is_jquery_plugin = re.search('^jquery\..*?\.js$', filename)
|
||||||
|
is_jsonc = re.search('\.jsonc$', filename)
|
||||||
if is_jquery or is_jquery_min:
|
if is_jquery or is_jquery_min:
|
||||||
target = os.path.join(path.replace(source_path, build_path), 'jquery.js')
|
target = os.path.join(path.replace(source_path, build_path), 'jquery.js')
|
||||||
else:
|
else:
|
||||||
|
@ -71,9 +88,9 @@ def build_oxjs(downloads=False, geo=False):
|
||||||
ui_files['build'].append(target.replace(build_path, ''))
|
ui_files['build'].append(target.replace(build_path, ''))
|
||||||
ui_files['dev'].append(target.replace(build_path, ''))
|
ui_files['dev'].append(target.replace(build_path, ''))
|
||||||
if not '/Ox/js' in source and not '/Ox.UI/js/' in source and not is_jquery:
|
if not '/Ox/js' in source and not '/Ox.UI/js/' in source and not is_jquery:
|
||||||
if re.match('^Ox\..+\.js$', filename):
|
if re.match('^Ox\..+\.js$', filename) or is_jsonc:
|
||||||
js = read_file(source)
|
js = read_file(source)
|
||||||
write_file(target, ox.js.minify(js, comment))
|
write_file(target, ox.js.minify(js, '' if is_jsonc else comment))
|
||||||
else:
|
else:
|
||||||
copy_file(source, target)
|
copy_file(source, target)
|
||||||
# write links in dev path
|
# write links in dev path
|
||||||
|
@ -141,14 +158,14 @@ def build_oxjs(downloads=False, geo=False):
|
||||||
for path, dirnames, filenames in os.walk(root):
|
for path, dirnames, filenames in os.walk(root):
|
||||||
for filename in sorted(filenames):
|
for filename in sorted(filenames):
|
||||||
# jquery gets included by Ox.UI loader
|
# jquery gets included by Ox.UI loader
|
||||||
# theme css files get included by main css
|
# Ox.UI.css imports all other css files
|
||||||
# svgs are loaded as URLs or dataURLs
|
# svgs are loaded as URLs or dataURLs
|
||||||
# browser images appear before load
|
# browser images appear before load
|
||||||
if path != root and not '_' in path and not filename[0] in '._'\
|
if path != root and not '_' in path and not filename[0] in '._' \
|
||||||
and not filename.endswith('~')\
|
and not filename.endswith('~') \
|
||||||
and not 'jquery' in filename\
|
and not 'jquery' in filename \
|
||||||
and not ('/themes/' in path and filename.endswith('.css'))\
|
and not filename.endswith('theme.css') \
|
||||||
and not filename.endswith('.svg')\
|
and not filename.endswith('.svg') \
|
||||||
and not filename.startswith('browser'):
|
and not filename.startswith('browser'):
|
||||||
ui_files['dev'].append(os.path.join(path.replace(source_path, ''), filename))
|
ui_files['dev'].append(os.path.join(path.replace(source_path, ''), filename))
|
||||||
if not '/js/' in path:
|
if not '/js/' in path:
|
||||||
|
@ -158,10 +175,14 @@ def build_oxjs(downloads=False, geo=False):
|
||||||
filename = build_path + 'Ox.UI/js/Ox.UI.js'
|
filename = build_path + 'Ox.UI/js/Ox.UI.js'
|
||||||
write_file(filename, ox.js.minify(js, comment))
|
write_file(filename, ox.js.minify(js, comment))
|
||||||
ui_files['build'].append(filename.replace(build_path, ''))
|
ui_files['build'].append(filename.replace(build_path, ''))
|
||||||
files = json.dumps(sorted(ui_files['build']))
|
write_file(build_path + 'Ox.UI/json/Ox.UI.json', json.dumps({
|
||||||
write_file(build_path + 'Ox.UI/json/Ox.UI.files.json', files)
|
'files': sorted(ui_files['build']),
|
||||||
files = json.dumps(sorted(ui_files['dev']), indent=4)
|
'images': ui_images
|
||||||
write_file(dev_path + 'Ox.UI/json/Ox.UI.files.json', files)
|
}, sort_keys=True))
|
||||||
|
write_file(dev_path + 'Ox.UI/json/Ox.UI.json', json.dumps({
|
||||||
|
'files': sorted(ui_files['dev']),
|
||||||
|
'images': ui_images
|
||||||
|
}, indent=4, sort_keys=True))
|
||||||
ui_files['dev'].append('Ox.UI/Ox.UI.js')
|
ui_files['dev'].append('Ox.UI/Ox.UI.js')
|
||||||
|
|
||||||
# index
|
# index
|
||||||
|
@ -250,10 +271,32 @@ def filter_source(tarinfo):
|
||||||
return None
|
return None
|
||||||
return tarinfo
|
return tarinfo
|
||||||
|
|
||||||
|
def format_hex(rgb):
|
||||||
|
return '#%s' % ''.join([hex(c)[-2:].replace('x', '0').upper() for c in rgb])
|
||||||
|
|
||||||
def get_title(file):
|
def get_title(file):
|
||||||
match = re.search('<h1>(.+)</h1>', read_file(file))
|
match = re.search('<h1>(.+)</h1>', read_file(file))
|
||||||
return match.groups()[0] if match else 'Untitled'
|
return match.groups()[0] if match else 'Untitled'
|
||||||
|
|
||||||
|
def parse_css(css, values):
|
||||||
|
def sub(match):
|
||||||
|
key = match.group(1)
|
||||||
|
index = match.group(2)
|
||||||
|
value = values[key] if index == None else values[key][int(index[1:-1])]
|
||||||
|
if isinstance(value, str):
|
||||||
|
string = value
|
||||||
|
else:
|
||||||
|
if isinstance(value[0], int):
|
||||||
|
value = [value]
|
||||||
|
string = ', '.join(
|
||||||
|
['rgb%s(%s)' % (
|
||||||
|
'a' if len(vals) == 4 else '',
|
||||||
|
', '.join([str(val) for val in vals])
|
||||||
|
) for vals in value]
|
||||||
|
)
|
||||||
|
return string
|
||||||
|
return re.sub('\$(\w+)(\[\d+\])?', sub, css)
|
||||||
|
|
||||||
def read_file(file):
|
def read_file(file):
|
||||||
print 'reading', file
|
print 'reading', file
|
||||||
f = open(file)
|
f = open(file)
|
||||||
|
@ -261,6 +304,9 @@ def read_file(file):
|
||||||
f.close()
|
f.close()
|
||||||
return data
|
return data
|
||||||
|
|
||||||
|
def read_jsonc(file):
|
||||||
|
return ox.jsonc.loads(read_file(file))
|
||||||
|
|
||||||
def write_file(file, data):
|
def write_file(file, data):
|
||||||
print 'writing', file
|
print 'writing', file
|
||||||
write_path(file)
|
write_path(file)
|
||||||
|
|
Loading…
Reference in a new issue