From 25a16daba1873361b4616c71618059bd6ba0e53e Mon Sep 17 00:00:00 2001 From: alshapton Date: Wed, 10 Aug 2022 09:05:46 +0100 Subject: [PATCH 1/6] Added new --heading option to change ADR page heading, also fixed mission --template-dir option from README.md --- README.md | 12 +++++++----- adr_viewer/__init__.py | 28 +++++++++++++++++----------- adr_viewer/templates/index.html | 4 ++-- 3 files changed, 26 insertions(+), 18 deletions(-) diff --git a/README.md b/README.md index 27199d1..f784301 100644 --- a/README.md +++ b/README.md @@ -35,11 +35,13 @@ $ python setup.py install Usage: adr-viewer [OPTIONS] Options: - --adr-path TEXT Directory containing ADR files. [default: doc/adr/] - --output TEXT File to write output to. [default: index.html] - --serve Serve content at http://localhost:8000/ - --port INT Custom server port [default: 8000] - --help Show this message and exit. + --adr-path TEXT Directory containing ADR files. [default: doc/adr/] + --output TEXT File to write output to. [default: index.html] + --serve Serve content at http://localhost:8000/ + --port INTEGER Change port for the server [default: 8000] + --template-dir TEXT Template directory + --heading TEXT ADR Page Heading [default: ADR Viewer - ] + --help Show this message and exit ``` The default for `--adr-path` is `doc/adr/` because this is the default path generated by `adr-tools`. diff --git a/adr_viewer/__init__.py b/adr_viewer/__init__.py index 8093691..adddbf6 100644 --- a/adr_viewer/__init__.py +++ b/adr_viewer/__init__.py @@ -46,7 +46,7 @@ def parse_adr_to_config(path): header = soup.find('h1') if header: - return { + return { 'status': status, 'body': adr_as_html, 'title': header.text @@ -80,15 +80,17 @@ def run_server(content, port): run(app, host='localhost', port=port, quiet=True) -def generate_content(path, template_dir_override=None): +def generate_content(path, template_dir_override=None, heading=None): files = get_adr_files("%s/*.md" % path) + if not heading: + heading = 'ADR Viewer - ' + os.path.basename(os.getcwd()) + config = { - 'project_title': os.path.basename(os.getcwd()), + 'heading': heading, 'records': [] } - for index, adr_file in enumerate(files): adr_attributes = parse_adr_to_config(adr_file) @@ -104,16 +106,20 @@ def generate_content(path, template_dir_override=None): @click.command() -@click.option('--adr-path', default='doc/adr/', help='Directory containing ADR files.', show_default=True) -@click.option('--output', default='index.html', help='File to write output to.', show_default=True) -@click.option('--serve', default=False, help='Serve content at http://localhost:8000/', is_flag=True) -@click.option('--port', default=8000, help='Change port for the server', show_default=True) -@click.option('--template-dir', default=None, help='Template directory.', show_default=True) -def main(adr_path, output, serve, port, template_dir): - content = generate_content(adr_path, template_dir) +@click.option('--adr-path', default='doc/adr/', help='Directory containing ADR files.', show_default=True) +@click.option('--output', default='index.html', help='File to write output to.', show_default=True) +@click.option('--serve', default=False, help='Serve content at http://localhost:8000/', is_flag=True) +@click.option('--port', default=8000, help='Change port for the server', show_default=True) +@click.option('--template-dir', default=None, help='Template directory.', show_default=True) +@click.option('--heading', default='ADR Viewer - ', help='ADR Page Heading', show_default=True) +def main(adr_path, output, serve, port, template_dir, heading): + content = generate_content(adr_path, template_dir, heading) if serve: run_server(content, port) else: with open(output, 'w') as out: out.write(content) + +if __name__ == '__main__': + main() \ No newline at end of file diff --git a/adr_viewer/templates/index.html b/adr_viewer/templates/index.html index 6f5639b..07db540 100644 --- a/adr_viewer/templates/index.html +++ b/adr_viewer/templates/index.html @@ -6,7 +6,7 @@ - ADR Viewer - {{ config.project_title }} + {{ config.heading }}