Skip to content

Commit

Permalink
appdocstrings
Browse files Browse the repository at this point in the history
  • Loading branch information
koaning committed Jul 9, 2024
1 parent a43cdb3 commit 26f17a7
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions mandr/app.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
"""The webapp that can render the InfoMander objects."""

import json
from pathlib import Path

Expand All @@ -14,10 +16,12 @@


def fetch_mander(*path):
"""Give a path as *args and return the mander at the given path."""
return InfoMander("/".join(path))


def render_views(*path):
"""Render the views attached to the mander for the given path."""
mander = fetch_mander(*path)
view_nav_templ = read_template("partials/views.html")
first_name = None
Expand All @@ -29,6 +33,7 @@ def render_views(*path):


def render_info(*path):
"""Render the info attached to the mander for the given path."""
mander = fetch_mander(*path)
return (
'<pre class="text-xs">'
Expand All @@ -41,6 +46,7 @@ def render_info(*path):


def render_logs(*path):
"""Render the logs attached to the mander for the given path."""
mander = fetch_mander(*path)
view_nav_templ = read_template("partials/logs.html")
return view_nav_templ.render(
Expand All @@ -50,17 +56,20 @@ def render_logs(*path):


def render_artifacts(*path):
"""Render the artifacts attached to the mander for the given path."""
mander = fetch_mander(*path)
view_nav_templ = read_template("partials/artifacts.html")
return view_nav_templ.render(artifacts=list(mander["_artifacts"].items()))


def read_template(path):
"""Read a template from the templates directory."""
p = Path(__file__).parent / "templates" / path
return Template(p.read_text())


def render_top_nav(*args):
"""Render the top navigation bar for the given path, which allows for navigation."""
nav_temp = read_template("partials/nav-top.html")
path_pairs = []
for i, p in enumerate(args):
Expand All @@ -80,11 +89,13 @@ def render_top_nav(*args):


def render_mid_nav(*args):
"""Render the content at a given path."""
nav_temp = read_template("partials/nav-mid.html")
return nav_temp.render(path="/".join(args))


def render_mander(*args):
"""Render the interface for the mander mander at the given path."""
p = Path(__file__).parent / "templates" / "page.html"
t = Template(p.read_text())
res = render_top_nav(*args)
Expand All @@ -95,6 +106,7 @@ def render_mander(*args):
@app.route("/", defaults={"path": ""}, methods=["GET", "POST"])
@app.route("/<path:path>", methods=["GET", "POST"])
def home(path):
"""Render the main route for the app. This route will render the mander and allow for navigation."""
if "favicon" in path:
return Response("", status=400)
if len(path) == 0:
Expand All @@ -117,6 +129,7 @@ def home(path):


def render_sketchpad(*path):
"""Render the sketchpad for templates."""
mander = fetch_mander(*path)
children = [f"{m.path}" for m in mander.children()]
return read_template("sketchpad.html").render(
Expand All @@ -125,6 +138,7 @@ def render_sketchpad(*path):


def render_template(*path):
"""Render a template. Used for the sketchpad."""
mander = fetch_mander(*path)
template_rendered = TemplateRenderer(mander)
return template_rendered.render(request.form["template"])
Expand Down

0 comments on commit 26f17a7

Please sign in to comment.