blob: a69452c67fdf9782b61e1630081168c08ac6214d (
plain)
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
|
"""
Render click.yaml config file into human-readable list of supported sites
"""
import pkg_resources, yaml
from docutils import nodes
from docutils.parsers.rst import Directive
from yarl import URL
class ClickList (Directive):
def run(self):
# XXX: do this once only
fd = pkg_resources.resource_stream ('crocoite', 'data/click.yaml')
config = list (yaml.safe_load_all (fd))
l = nodes.definition_list ()
for site in config:
urls = set ()
v = nodes.definition ()
vl = nodes.bullet_list ()
v += vl
for s in site['selector']:
i = nodes.list_item ()
i += nodes.paragraph (text=s['description'])
vl += i
urls.update (map (lambda x: URL(x).with_path ('/'), s.get ('urls', [])))
item = nodes.definition_list_item ()
term = ', '.join (map (lambda x: x.host, urls)) if urls else site['match']
k = nodes.term (text=term)
item += k
item += v
l += item
return [l]
def setup(app):
app.add_directive ("clicklist", ClickList)
return {
'version': '0.1',
'parallel_read_safe': True,
'parallel_write_safe': True,
}
|