Skip to content

Commit

Permalink
Don't execute serialisation login in jinja.
Browse files Browse the repository at this point in the history
This makes it a bit easier to profile as function calls in jinja are
hard to track.
  • Loading branch information
Carreau committed Dec 21, 2023
1 parent a3fee3b commit 0df469b
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 3 deletions.
3 changes: 2 additions & 1 deletion papyri/render.py
Original file line number Diff line number Diff line change
Expand Up @@ -657,7 +657,8 @@ def render_one(

backrefs_ = (None, group_backrefs(backrefs, self.LR))

root = self._myst_root(doc)

root = json.dumps(self._myst_root(doc).to_dict(), indent=2)
try:
module = qa.split(".")[0]
return template.render(
Expand Down
4 changes: 2 additions & 2 deletions papyri/templates/html.tpl.j2
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@
<div class='article'>


{% from 'macros.tpl.j2' import render_paragraph, example, render_myst, render_II with context %}
{% from 'macros.tpl.j2' import render_paragraph, example, render_myst_json, render_II with context %}
{% from 'graph.tpl.j2' import d3script with context%}



{{render_myst(myst_root)}}
{{render_myst_json(myst_root)}}


{% if backrefs[0] or backrefs[1] %}
Expand Down
9 changes: 9 additions & 0 deletions papyri/templates/macros.tpl.j2
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,15 @@
{%- endfor %}
{%- endmacro %}



{% macro render_myst_json(json) -%}
{% set key = uuid() %}
<div style='border: solid thin cyan' id="{{ key }}"></div>
<script>
render("{{ key }}", {"type": "root", "children":[{{ json|safe }}]})
</script>
{%- endmacro %}
{% macro render_myst(obj) -%}
{% set astJson = obj.to_dict() %}
{% set key = uuid() %}
Expand Down

0 comments on commit 0df469b

Please sign in to comment.