File: update-icons.py

package info (click to toggle)
bootstrap-flask 2.4.2%2Bds-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 28,784 kB
  • sloc: python: 2,334; makefile: 30
file content (47 lines) | stat: -rw-r--r-- 1,732 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
'''Generate example page with overview of all icons.'''

from lxml import etree

def parse(filename):
    '''Parse SVG file containing icons.'''
    symbols = set()
    data = etree.parse(filename)
    svg = data.getroot()
    for symbol in svg:
        symbols.add(symbol.attrib['id'])
    return sorted(symbols)

def generate(version):
    '''Write the HTML template file.'''
    head = f'''{{% extends 'base.html' %}}
{{% from 'bootstrap{version}/utils.html' import render_icon %}}
<!-- DO NOT EDIT! Use update-icons.py for updating this file. -->

{{% block content %}}
<h2>Icons</h2>
<p>These are all the icons which are currently supported by Bootstrap-Flask.</p>
<ul class="row row-cols-3 row-cols-sm-4 row-cols-lg-6 row-cols-xl-8 list-unstyled list">
'''
    names = parse(f'../flask_bootstrap/static/bootstrap{version}/icons/bootstrap-icons.svg')
    with open(f'bootstrap{version}/templates/icons.html', 'w') as file:  # pylint:disable=unspecified-encoding
        file.write(head)
        number = 0
        for name in sorted(names):
            item=f'''<li class="col mb-4">
<a class="d-block text-dark text-body-emphasis text-decoration-none" href="https://icons.getbootstrap.com/icons/{name}/">
<div class="px-3 py-4 mb-2 bg-light text-center rounded">
{{{{ render_icon('{name}', 32) }}}}
</div>
</a>
<div class="name text-body-secondary text-decoration-none text-center pt-1">{name}</div>
</li>
'''
            file.write(item)
            number += 1
        file.write('</ul>\n')
        file.write(f'<p>This is a total of {number} icons.</p>\n')
        file.write('{% endblock %}\n\n')
        print(f'For Bootstrap{version}, a total of {number} icons are supported.')

for value in (4, 5):
    generate(value)