From 4c7b4a29d74a03b54e21ea8dcc23469be9c9c597 Mon Sep 17 00:00:00 2001 From: Ryan Date: Thu, 28 Nov 2024 22:08:43 -0800 Subject: [PATCH] feat: add simple web server for mermaid diagrams preview --- Procfile.dev | 1 + README.md | 10 ++++++++++ web/app.py | 26 ++++++++++++++++++++++++++ web/requirements.txt | 3 +++ web/settings.py | 4 ++++ 5 files changed, 44 insertions(+) create mode 100644 web/app.py create mode 100644 web/requirements.txt create mode 100644 web/settings.py diff --git a/Procfile.dev b/Procfile.dev index bf2a92c..32e6093 100644 --- a/Procfile.dev +++ b/Procfile.dev @@ -2,3 +2,4 @@ # text only UI and force loading / no cache mpf: mpf both -Xtav -c development monitor: mpf monitor +docs: cd web && flask run diff --git a/README.md b/README.md index a63e3c4..858ebd3 100644 --- a/README.md +++ b/README.md @@ -9,6 +9,16 @@ Machine](http://www.ipdb.org/machine.cgi?id=1072) by Williams. ![Playfield](https://github.com/deathsave/grand-prix/raw/main/monitor/playfield.jpg) +### Docs + +A simple web server is included to serve up the markdown docs and +Mermaid diagrams. To setup, run `pip install -r requirements.txt` +in the `./web/` root. Then to run it, use `bin/docs`. + +```mermaid +graph TD + TODO --> DIAGRAM["Diagram Modes"] +``` Proposed OPP Build ------------------ diff --git a/web/app.py b/web/app.py new file mode 100644 index 0000000..aa58986 --- /dev/null +++ b/web/app.py @@ -0,0 +1,26 @@ +import os +import markdown +import markdown_mermaidjs + +from flask import Flask +from settings import MACHINE_ROOT + +SIMPLE_CSS = '' \ + '' + +app = Flask(__name__) + +@app.route('/') +def readme(): + with open(os.path.join(MACHINE_ROOT, 'README.md')) as f: + html = markdown.markdown( + f.read(), extensions=["markdown_mermaidjs"] + ) + return SIMPLE_CSS + html + +if __name__ == '__main__': + app.run() diff --git a/web/requirements.txt b/web/requirements.txt new file mode 100644 index 0000000..1432de6 --- /dev/null +++ b/web/requirements.txt @@ -0,0 +1,3 @@ +mistune +flask +markdown-mermaidjs diff --git a/web/settings.py b/web/settings.py new file mode 100644 index 0000000..d8c3472 --- /dev/null +++ b/web/settings.py @@ -0,0 +1,4 @@ +import os +# __file__ refers to the file settings.py +APP_ROOT = os.path.dirname(os.path.abspath(__file__)) +MACHINE_ROOT = os.path.join(APP_ROOT, '../')