Skip to content

Commit

Permalink
simplify a bunch of stuff in mcros
Browse files Browse the repository at this point in the history
  • Loading branch information
Carreau committed Nov 21, 2023
1 parent 0cb8f36 commit 272b30d
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 51 deletions.
1 change: 1 addition & 0 deletions papyri/render.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
31 changes: 4 additions & 27 deletions papyri/templates/ascii.tpl.j2
Original file line number Diff line number Diff line change
Expand Up @@ -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 %}

Expand All @@ -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}}
Expand Down Expand Up @@ -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 %}
Expand Down Expand Up @@ -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 %}
Expand Down
8 changes: 3 additions & 5 deletions papyri/templates/html.tpl.j2
Original file line number Diff line number Diff line change
Expand Up @@ -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%}


Expand Down Expand Up @@ -121,17 +121,15 @@
<h3 id='section-backrefs'>Back References</h3>
<p>The following pages refer to to this document either explicitly or contain code examples using this.</p>

{% if backrefs[0] is not none %}
{{unreachable()}}
{% endif%}

{% if backrefs[1] is not none %}
{% for k,v in backrefs[1].items() %}
<h4>{{k}}</h4>
<details>
<summary>{{v | length}} Elements</summary>
<dl>
{% for r in v %}
<dd>{{ render_inner('MLink', r) -}}</dd>
<dd>{{ render_II(r) -}}</dd>
{% endfor %}
</dl>
</details>
Expand Down
28 changes: 10 additions & 18 deletions papyri/templates/macros.tpl.j2
Original file line number Diff line number Diff line change
@@ -1,16 +1,3 @@
{% macro render_inner(type_, obj) -%}
{%- if type_ == 'Directive' -%}
<!-- In theory we should never get Raw directive in final output --!>
{{ 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__)}}
<pre class='not-implemented'>{{obj}}</pre>
{%- else %}
{{unreachable(type_, obj.__class__.__name__, obj.__dict__)}}
{%- endif -%}
{%- endmacro %}

{% macro render_paragraph(prgs) -%}
{% for prg in prgs %}
Expand Down Expand Up @@ -88,11 +75,16 @@
<pre class='not-implemented'>
{{obj}}
</pre>
{% else %}
<code class='not-implemented'>Type {{type}} (A) Not implemented yet</code>
<pre class='not-implemented'>
{{-unimplemented(type, obj)-}}
</pre>
{%- elif type == 'Directive' -%}
<!-- In theory we should never get Raw directive in final output --!>
{{ 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__)}}
<pre class='not-implemented'>{{obj}}</pre>
{%- else %}
{{unreachable(type, obj.__class__.__name__, obj.__dict__)}}
{%- endif -%}
{%- endmacro %}
Expand Down
2 changes: 1 addition & 1 deletion papyri/templates/toctree.tpl.j2
Original file line number Diff line number Diff line change
@@ -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%}
Expand Down

0 comments on commit 272b30d

Please sign in to comment.