diff options
author | Lars-Dominik Braun <lars@6xq.net> | 2019-07-29 15:34:50 +0200 |
---|---|---|
committer | Lars-Dominik Braun <lars@6xq.net> | 2019-07-29 15:35:16 +0200 |
commit | 949dd6d2a14f11036d251ef7d11607a214389d17 (patch) | |
tree | dc4d31ffed9d2e8b02440569ec6fc9d85d4e57b8 /doc/_ext | |
parent | 3433889e1c04881eba0bbd1e211beb544123dd57 (diff) | |
download | crocoite-949dd6d2a14f11036d251ef7d11607a214389d17.tar.gz crocoite-949dd6d2a14f11036d251ef7d11607a214389d17.tar.bz2 crocoite-949dd6d2a14f11036d251ef7d11607a214389d17.zip |
doc: Auto-generate list of supported click selectors
Using shinx plugin. Also improve click selector descriptions for this
purpose.
Diffstat (limited to 'doc/_ext')
-rw-r--r-- | doc/_ext/clicklist.py | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/doc/_ext/clicklist.py b/doc/_ext/clicklist.py new file mode 100644 index 0000000..a69452c --- /dev/null +++ b/doc/_ext/clicklist.py @@ -0,0 +1,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, + } + |