docs: improve generation of default config files

- config files are placed into `docs/generated/conf/`, using the
  expected name, and without any indentation
- `literalinclude::` is used instead of `include::`
- uses `:download:` instead of `:file:` to allow for downloading the
  generated files easily
This commit is contained in:
Daniel Hahler 2018-06-16 18:35:58 +02:00
parent 49b065cbe7
commit 8a0cd73821
3 changed files with 12 additions and 15 deletions

View File

@ -500,35 +500,30 @@ def write_conf_docs(app, all_kitten_names):
sc_role.warn_dangling = True sc_role.warn_dangling = True
sc_role.process_link = process_shortcut_link sc_role.process_link = process_shortcut_link
def generate(all_options, name='kitty'): def generate_default_config(all_options, name):
from kitty.conf.definition import as_conf_file from kitty.conf.definition import as_conf_file
from textwrap import indent
with open(f'generated/conf-{name}.rst', 'w', encoding='utf-8') as f: with open(f'generated/conf-{name}.rst', 'w', encoding='utf-8') as f:
print('.. highlight:: conf\n', file=f) print('.. highlight:: conf\n', file=f)
f.write(render_conf(name, all_options.values())) f.write(render_conf(name, all_options.values()))
with open(f'generated/conf-{name}-literal.rst', 'w', encoding='utf-8') as f: conf_name = re.sub(r'^kitten-', '', name) + '.conf'
print('.. code-block:: conf\n', file=f) with open(f'generated/conf/{conf_name}', 'w', encoding='utf-8') as f:
text = '\n'.join(as_conf_file(all_options.values())) text = '\n'.join(as_conf_file(all_options.values()))
text = indent(text, ' ', lambda l: True)
print(text, file=f) print(text, file=f)
from kitty.config_data import all_options from kitty.config_data import all_options
generate(all_options) generate_default_config(all_options, 'kitty')
from kittens.runner import get_kitten_conf_docs from kittens.runner import get_kitten_conf_docs
for kitten in all_kitten_names: for kitten in all_kitten_names:
all_options = get_kitten_conf_docs(kitten) all_options = get_kitten_conf_docs(kitten)
if all_options: if all_options:
generate(all_options, f'kitten-{kitten}') generate_default_config(all_options, f'kitten-{kitten}')
# }}} # }}}
def setup(app): def setup(app):
try: os.makedirs('generated/conf', exist_ok=True)
os.mkdir('generated')
except FileExistsError:
pass
from kittens.runner import all_kitten_names from kittens.runner import all_kitten_names
all_kitten_names = all_kitten_names() all_kitten_names = all_kitten_names()
write_cli_docs(all_kitten_names) write_cli_docs(all_kitten_names)

View File

@ -35,6 +35,7 @@ expanded, so :code:`${USER}.conf` becomes :file:`name.conf` if
Sample kitty.conf Sample kitty.conf
^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^
Below is a sample :file:`kitty.conf` with all default settings. Below is a sample :download:`kitty.conf </generated/conf/kitty.conf>` with all default settings.
.. include:: /generated/conf-kitty-literal.rst .. literalinclude:: /generated/conf/kitty.conf
:language: conf

View File

@ -152,6 +152,7 @@ Command Line Interface
Sample diff.conf Sample diff.conf
----------------- -----------------
Below is a sample :file:`diff.conf` with all default settings. Below is a sample :download:`diff.conf </generated/conf/diff.conf>` with all default settings.
.. include:: /generated/conf-kitten-diff-literal.rst .. literalinclude:: /generated/conf/diff.conf
:language: conf