diff options
| author | Mike Vink <mike@pionative.com> | 2025-01-19 13:52:31 +0100 |
|---|---|---|
| committer | Mike Vink <mike@pionative.com> | 2025-01-19 13:52:31 +0100 |
| commit | c65afb488eb9eab85063d79783d40ae1d7138586 (patch) | |
| tree | 48ce8318f6fc22eb0b82df83b5c175469b853643 /scripts | |
Squashed 'mut/neovim/pack/plugins/start/quicker.nvim/' content from commit 049def7
git-subtree-dir: mut/neovim/pack/plugins/start/quicker.nvim
git-subtree-split: 049def718213d3cdf49fdf29835aded09b3e54a3
Diffstat (limited to 'scripts')
| -rwxr-xr-x | scripts/generate.py | 102 | ||||
| -rwxr-xr-x | scripts/main.py | 31 | ||||
| -rw-r--r-- | scripts/requirements.txt | 4 |
3 files changed, 137 insertions, 0 deletions
diff --git a/scripts/generate.py b/scripts/generate.py new file mode 100755 index 0000000..e1ccded --- /dev/null +++ b/scripts/generate.py @@ -0,0 +1,102 @@ +import os +import os.path +import re +from typing import List + +from nvim_doc_tools import ( + Vimdoc, + VimdocSection, + generate_md_toc, + indent, + parse_directory, + read_section, + render_md_api2, + render_vimdoc_api2, + replace_section, +) + +HERE = os.path.dirname(__file__) +ROOT = os.path.abspath(os.path.join(HERE, os.path.pardir)) +README = os.path.join(ROOT, "README.md") +DOC = os.path.join(ROOT, "doc") +VIMDOC = os.path.join(DOC, "quicker.txt") + + +def add_md_link_path(path: str, lines: List[str]) -> List[str]: + ret = [] + for line in lines: + ret.append(re.sub(r"(\(#)", "(" + path + "#", line)) + return ret + + +def update_md_api(): + types = parse_directory(os.path.join(ROOT, "lua")) + funcs = types.files["quicker/init.lua"].functions + lines = ["\n"] + render_md_api2(funcs, types, 3)[:-1] # trim last newline + replace_section( + README, + r"^<!-- API -->$", + r"^<!-- /API -->$", + lines, + ) + + +def update_options(): + option_lines = ["\n", "```lua\n"] + config_file = os.path.join(ROOT, "lua", "quicker", "config.lua") + option_lines = read_section(config_file, r"^\s*local default_config =", r"^}$") + option_lines.insert(0, 'require("quicker").setup({\n') + option_lines.insert(0, "```lua\n") + option_lines.extend(["})\n", "```\n", "\n"]) + replace_section( + README, + r"^<!-- OPTIONS -->$", + r"^<!-- /OPTIONS -->$", + option_lines, + ) + + +def update_readme_toc(): + toc = ["\n"] + generate_md_toc(README, max_level=1) + ["\n"] + replace_section( + README, + r"^<!-- TOC -->$", + r"^<!-- /TOC -->$", + toc, + ) + + +def gen_options_vimdoc() -> VimdocSection: + section = VimdocSection("Options", "quicker-options", ["\n", ">lua\n"]) + config_file = os.path.join(ROOT, "lua", "quicker", "config.lua") + option_lines = read_section(config_file, r"^\s*local default_config =", r"^}$") + option_lines.insert(0, 'require("quicker").setup({\n') + option_lines.extend(["})\n"]) + section.body.extend(indent(option_lines, 4)) + section.body.append("<\n") + return section + + +def generate_vimdoc(): + doc = Vimdoc("quicker.txt", "quicker") + types = parse_directory(os.path.join(ROOT, "lua")) + funcs = types.files["quicker/init.lua"].functions + doc.sections.extend( + [ + gen_options_vimdoc(), + VimdocSection( + "API", "quicker-api", render_vimdoc_api2("quicker", funcs, types) + ), + ] + ) + + with open(VIMDOC, "w", encoding="utf-8") as ofile: + ofile.writelines(doc.render()) + + +def main() -> None: + """Update the README""" + update_md_api() + update_options() + update_readme_toc() + generate_vimdoc() diff --git a/scripts/main.py b/scripts/main.py new file mode 100755 index 0000000..4dffddf --- /dev/null +++ b/scripts/main.py @@ -0,0 +1,31 @@ +#!/usr/bin/env python +import argparse +import os +import sys + +HERE = os.path.dirname(__file__) +ROOT = os.path.abspath(os.path.join(HERE, os.path.pardir)) +DOC = os.path.join(ROOT, "doc") + + +def main() -> None: + """Generate docs""" + sys.path.append(HERE) + parser = argparse.ArgumentParser(description=main.__doc__) + parser.add_argument("command", choices=["generate", "lint"]) + args = parser.parse_args() + if args.command == "generate": + import generate + + generate.main() + elif args.command == "lint": + from nvim_doc_tools import lint_md_links + + files = [os.path.join(ROOT, "README.md")] + [ + os.path.join(DOC, file) for file in os.listdir(DOC) if file.endswith(".md") + ] + lint_md_links.main(ROOT, files) + + +if __name__ == "__main__": + main() diff --git a/scripts/requirements.txt b/scripts/requirements.txt new file mode 100644 index 0000000..2c6271f --- /dev/null +++ b/scripts/requirements.txt @@ -0,0 +1,4 @@ +pyparsing==3.0.9 +black +isort +mypy |
