Skip to content

Commit

Permalink
Redo ethercat boxes as tree
Browse files Browse the repository at this point in the history
  • Loading branch information
klauer committed Nov 2, 2023
1 parent 6f91ee2 commit 6e9e1f4
Showing 1 changed file with 62 additions and 26 deletions.
88 changes: 62 additions & 26 deletions templates/ethercat.rst
Original file line number Diff line number Diff line change
Expand Up @@ -22,38 +22,65 @@ EtherCAT Terminals by Project

This summary was generated |today|.

{% macro format_box(box, depth) %}
{% macro format_box_html(box, depth) %}
{%- if not box.EtherCAT -%}
(Not EtherCAT?)
{%- else -%}
{%- if depth % 2 == 0 -%}
**
{%- endif %}
{{- box.name | trim("=+-") }} [ID: {{ box.attributes.Id }}]
{%- if depth % 2 == 0 -%}
**
{%- endif %}
{%- set ethercat = box.EtherCAT[0] %}

{%+ if box.attributes.Disabled == "true" %}
{{ "(**Disabled**)" }}
{%- endif %}
{%- if ethercat.SuName %}
( **SyncUnit={{ ethercat.SuName[0].text }}** )
{%- endif %}
{{ ethercat.attributes.Type }}
<table width="100%">
<tr>
<td width="10%">
ID={{ box.attributes.Id }}:
</td>
<td width="75%">
{{- box.name | trim("=+-") }}
</td>
<td>
{%- if ethercat.SuName %}
<b>
SyncUnit {{ ethercat.SuName[0].text }}
</b>
{%- endif %}
</td>
</tr>
<tr>
<td>
{%+ if box.attributes.Disabled == "true" %}
<b>
Disabled
</b>
{%- endif %}
</td>
<td colspan="2">
{{ ethercat.attributes.Type }}
</td>
</tr>
</table>
{%- endif -%}
{%- endmacro -%}

{%- macro format_tree(box, children, depth) %}
{% set box_text = format_box(box, depth) %}
#. {{ box_text }}

{% for child, grandchildren in children.items() %}
{% set child_text = format_tree(child, grandchildren, depth + 1) %}
{{ child_text | indent(width=4, first=False, blank=False) }}
{%- macro format_tree_html(box, children, depth) %}
{% set box_text = format_box_html(box, depth) %}
<li>
{% if not children %}
{{ box_text }}
{% else %}
<details open>
<summary>
{{ box_text }}
</summary>
<ul>
{% for child, grandchildren in children.items() %}

{% set child_text = format_tree_html(child, grandchildren, depth + 1) %}
{{ child_text | indent(width=10, first=False, blank=False) }}

{% endfor %}
</ul>
</details>
{% endif %}
</li>

{% endfor %}
{%- endmacro -%}

{% for project in projects.values() | sort(attribute="git_info.repo_slug") %}
Expand All @@ -62,10 +89,19 @@ This summary was generated |today|.

Version `{{ project.git_info.describe }} <{{ project.git_info.tree_urls[0] }}>`_ - `Documentation <{{ project.git_info.doc_urls[0] }}>`_

.. raw:: html

<ul class="tree">

{% for box, children in get_box_hierarchy(project).items() %}

{% set child_text = format_tree(box, children, 0) %}
{{ child_text }}
{% set child_text = format_tree_html(box, children, 0) %}


{{ child_text }}

{% endfor %}{# for box_id... #}

</ul>

{% endfor %}{# for project... #}

0 comments on commit 6e9e1f4

Please sign in to comment.