From 272b30d7db16149db58cb14d80a384e67fd5ad43 Mon Sep 17 00:00:00 2001 From: Matthias Bussonnier Date: Tue, 21 Nov 2023 15:16:04 +0100 Subject: [PATCH] simplify a bunch of stuff in mcros --- papyri/render.py | 1 + papyri/templates/ascii.tpl.j2 | 31 ++++--------------------------- papyri/templates/html.tpl.j2 | 8 +++----- papyri/templates/macros.tpl.j2 | 28 ++++++++++------------------ papyri/templates/toctree.tpl.j2 | 2 +- 5 files changed, 19 insertions(+), 51 deletions(-) diff --git a/papyri/render.py b/papyri/render.py index 8f8d85f6..bc53f963 100644 --- a/papyri/render.py +++ b/papyri/render.py @@ -1241,6 +1241,7 @@ def old_render_one( doc.content[k] = LR.visit(v) doc.arbitrary = [LR.visit(x) for x in doc.arbitrary] + doc.see_also = [LR.visit(s) for s in doc.see_also] return template.render( current_type=current_type, doc=doc, diff --git a/papyri/templates/ascii.tpl.j2 b/papyri/templates/ascii.tpl.j2 index 7526137d..3ca54895 100644 --- a/papyri/templates/ascii.tpl.j2 +++ b/papyri/templates/ascii.tpl.j2 @@ -24,30 +24,9 @@ {%- endif -%} {%- endmacro %} {#--#} -{% macro render_inner(type, obj) -%} - |{%- if type == 'Directive' -%} - | |:{{blue(obj.domain)}}:{{blue(obj.role)}}:`{{blue(obj.value)}}` - |{%- elif type == 'Link' %} - | |{% if obj.kind=='local' %} - | | {{-green(obj.value)-}} - | |{% elif obj.kind=='exists' %} - | | {{-blue(obj.value)-}} - | |{% elif obj.kind=='missing' %} - | | {{-unreachable(obj)}} - | |{% else %} - | |{% endif %} - |{% elif type == 'Math' %} - | ${{obj.value}}$ - |{% elif type == 'Verbatim' %} - | {{-yellow(obj.text)-}} - |{% else %} - | |Some A {{type}} - |{%- endif -%} -{%- endmacro %} - {% macro block_paragraph(pgr) -%} |{%- for c in pgr.children -%} - | |{{-render_inner(c.__class__.__name__, c)-}} + | |{{-render_II(c)-}} |{%- endfor -%} {% endmacro %} @@ -66,9 +45,7 @@ | |{{block_paragraph(obj)}} |{% else %} |{%- set type = obj.__class__.__name__ -%} - | |{%- if type in ('Directive', 'Link', 'Math', 'Verbatim') -%} - | | |{{unreachable()}} - | |{% elif type == 'MMystDirective' %} + | |{% if type == 'MMystDirective' %} | | |{{'\n'}}{{myst_directive(obj)}} | |{% elif type == 'Verbatim' %} | | |{{obj}} @@ -104,7 +81,7 @@ |{% endif %} |{% for prg in prgs %} | | |{%- for obj in prg.children -%} - | | | {{- render_inner(obj.__class__.__name__, obj) -}} + | | | {{- render_II(obj) -}} | | |{%- endfor -%} |{%- endfor -%} {%- endmacro %} @@ -195,7 +172,7 @@ {% if doc.see_also %} |{{bold("See Also")}} |{% for sa in doc.see_also %} - | {{bold(render_inner(sa.name.__class__.__name__, sa.name))}} + | {{bold(render_II(sa.name))}} | {{render_paragraph(sa.descriptions) | wordwrap | indent(width=8)}} |{% endfor %} {% endif %} diff --git a/papyri/templates/html.tpl.j2 b/papyri/templates/html.tpl.j2 index 6e3cd60f..0e4ccf5a 100644 --- a/papyri/templates/html.tpl.j2 +++ b/papyri/templates/html.tpl.j2 @@ -14,7 +14,7 @@ {%block api %} -{% from 'macros.tpl.j2' import render_inner, render_paragraph, myst_directive, example, render_myst, render_II with context %} +{% from 'macros.tpl.j2' import render_paragraph, myst_directive, example, render_myst, render_II with context %} {% from 'graph.tpl.j2' import d3script with context%} @@ -121,9 +121,7 @@

Back References

The following pages refer to to this document either explicitly or contain code examples using this.

- {% if backrefs[0] is not none %} - {{unreachable()}} - {% endif%} + {% if backrefs[1] is not none %} {% for k,v in backrefs[1].items() %}

{{k}}

@@ -131,7 +129,7 @@ {{v | length}} Elements
{% for r in v %} -
{{ render_inner('MLink', r) -}}
+
{{ render_II(r) -}}
{% endfor %}
diff --git a/papyri/templates/macros.tpl.j2 b/papyri/templates/macros.tpl.j2 index 060dab55..ce1de8eb 100644 --- a/papyri/templates/macros.tpl.j2 +++ b/papyri/templates/macros.tpl.j2 @@ -1,16 +1,3 @@ -{% macro render_inner(type_, obj) -%} - {%- if type_ == 'Directive' -%} - - {{ render_myst(obj) }} - {%- elif type_ in ('Math', 'Verbatim', 'MText','MEmphasis','MInlineCode', 'MLink') -%} - {{ render_myst(obj) }} - {%- elif type_ in ['SubstitutionRef','Unimplemented'] %} - {{unimplemented(type_, obj.__class__.__name__, obj.__dict__)}} -
{{obj}}
- {%- else %} - {{unreachable(type_, obj.__class__.__name__, obj.__dict__)}} - {%- endif -%} -{%- endmacro %} {% macro render_paragraph(prgs) -%} {% for prg in prgs %} @@ -88,11 +75,16 @@
             {{obj}}
            
- {% else %} - Type {{type}} (A) Not implemented yet -
-           {{-unimplemented(type, obj)-}}
-           
+ {%- elif type == 'Directive' -%} + + {{ render_myst(obj) }} + {%- elif type in ('Math', 'Verbatim', 'MText','MEmphasis','MInlineCode', 'MLink') -%} + {{ render_myst(obj) }} + {%- elif type in ['SubstitutionRef','Unimplemented','SubstitutionDef'] %} + {{unimplemented(type, obj.__class__.__name__, obj.__dict__)}} +
{{obj}}
+ {%- else %} + {{unreachable(type, obj.__class__.__name__, obj.__dict__)}} {%- endif -%} {%- endmacro %} diff --git a/papyri/templates/toctree.tpl.j2 b/papyri/templates/toctree.tpl.j2 index ea67e2c4..6b5d24a6 100644 --- a/papyri/templates/toctree.tpl.j2 +++ b/papyri/templates/toctree.tpl.j2 @@ -1,6 +1,6 @@ {% extends "skeleton.tpl.j2" %} {% set current_type = 'TocTree' %} -{% from 'macros.tpl.j2' import render_inner, render_paragraph, lines, block, myst_directive, example, render_II with context %} +{% from 'macros.tpl.j2' import render_paragraph, lines, block, myst_directive, example, render_II with context %} {% macro tci(obj) -%} {%if obj.children%}