Skip to content

Commit

Permalink
lass backcall in templates
Browse files Browse the repository at this point in the history
  • Loading branch information
Carreau committed Sep 27, 2023
1 parent 86611ef commit c842960
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 14 deletions.
28 changes: 19 additions & 9 deletions papyri/render.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,10 @@ def GET(ref_map, key, cpath):
return siblings


def _uuid():
return uuid.uuid4().hex


class HtmlRenderer:
def __init__(self, store: GraphStore, *, sidebar, prefix, trailing_html):
assert prefix.startswith("/")
Expand All @@ -218,7 +222,7 @@ def __init__(self, store: GraphStore, *, sidebar, prefix, trailing_html):
self.env.globals["unreachable"] = unreachable
self.env.globals["sidebar"] = sidebar
self.env.globals["dothtml"] = extension
self.env.globals["uuid"] = lambda: uuid.uuid4().hex
self.env.globals["uuid"] = _uuid

def compute_graph(
self, backrefs: Set[Key], refs: Set[Key], key: Key
Expand Down Expand Up @@ -380,7 +384,7 @@ class S:
backrefs=[[], []],
module="*",
doc=doc,
parts={"*": []},
parts=list({"*": []}.items()),
version="*",
ext="",
current_type="",
Expand Down Expand Up @@ -475,7 +479,8 @@ class D:
meta=meta,
figmap=figmap,
module=package,
parts=parts,
parts_mods=parts.get(package, []),
parts=list(parts.items()),
version=version,
parts_links=defaultdict(lambda: ""),
doc=doc,
Expand All @@ -501,7 +506,8 @@ class D:
logo=logo,
meta=meta,
module=package,
parts={},
parts=list({}.items()),
parts_mods=[],
version=version,
parts_links=defaultdict(lambda: ""),
doc=doc,
Expand Down Expand Up @@ -569,15 +575,17 @@ def render_one(
doc.content[k] = self.LR.visit(v)

doc.arbitrary = [self.LR.visit(x) for x in doc.arbitrary]
module = qa.split(".")[0]
return template.render(
current_type=current_type,
doc=doc,
logo=meta.get("logo", None),
version=meta["version"],
module=qa.split(".")[0],
module=module,
name=qa.split(":")[-1].split(".")[-1],
backrefs=backrefs,
parts=parts,
parts_mods=parts.get(module, []),
parts=list(parts.items()),
parts_links=parts_links,
graph=graph,
meta=meta,
Expand Down Expand Up @@ -725,6 +733,7 @@ async def _write_api_file(
template = self.env.get_template("html.tpl.j2")
gfiles = list(self.store.glob((None, None, "module", None)))
random.shuffle(gfiles)

for _, key in progress(gfiles, description="Rendering API..."):
module, version = key.module, key.version
if config.ascii:
Expand Down Expand Up @@ -869,7 +878,7 @@ class Doc:
meta=meta,
logo=meta["logo"],
module=package,
parts=parts,
parts=list(parts.items()),
version=version,
parts_links=defaultdict(lambda: ""),
doc=doc,
Expand Down Expand Up @@ -897,7 +906,8 @@ class Doc:
meta=meta,
logo=logo,
module=module,
parts=parts,
parts_mods=parts.get(module, []),
parts=list(parts.items()),
version=version,
parts_links=defaultdict(lambda: ""),
doc=doc,
Expand Down Expand Up @@ -1188,7 +1198,7 @@ def old_render_one(
version=meta["version"],
module=qa.split(".")[0],
backrefs=backrefs,
parts=parts,
parts=list(parts.items()),
parts_links=parts_links,
graph=graph,
meta=meta,
Expand Down
4 changes: 2 additions & 2 deletions papyri/skeleton.tpl.j2
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<div class="dropdown">
<a href={{module}}>{{module}}</a>&nbsp;/&nbsp;
<div class="dropdown-content">
{% for link,name in parts.get(module, []) -%}
{% for link,name in parts_mods -%}
<a href="{{url(link)}}">{{link.path}}</a>
{% endfor %}
</div>
Expand All @@ -30,7 +30,7 @@
</div>
</div>

{% for p,links in parts.items() %}
{% for p,links in parts %}
{% if links %}
<div class="dropdown">
{% if p =='+' %}
Expand Down
6 changes: 3 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ dependencies = [
"tomli_w",
"urwid",
"httpx",
"jinja2<3.1",
"jinja2>3.1.2",
"ipython",
"numpydoc",
"cachetools",
Expand All @@ -27,8 +27,8 @@ dependencies = [
"jedi",
"typer",
"velin",
"quart-trio",
"quart<0.14",
"quart-trio>=0.6.0",
"quart>=0.18.4",
"flatlatex",
# "tree_sitter", # tree sitter does not currently provide builds for all platform. tree-sitter-builds is an
# alternative build that provide more wheels.
Expand Down

0 comments on commit c842960

Please sign in to comment.