mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
documentation: render nested return dicts for more then one level (#33143)
* Render nested return value documentation for more then one level in the generated webdocs. * Remove unnecessary code and cleanup * Implement recursive option documentation * Build elbow intendation style for options and return documentation
This commit is contained in:
parent
673ec2cb78
commit
496ce388ab
2 changed files with 196 additions and 187 deletions
|
@ -4748,7 +4748,7 @@ th, td {
|
||||||
}
|
}
|
||||||
|
|
||||||
table {
|
table {
|
||||||
overflow-x: scroll;
|
overflow-x: auto;
|
||||||
display: block;
|
display: block;
|
||||||
max-width: 100%;
|
max-width: 100%;
|
||||||
}
|
}
|
||||||
|
@ -4864,3 +4864,48 @@ table {
|
||||||
padding: 8px 13px;
|
padding: 8px 13px;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.outer-elbow-container {
|
||||||
|
display: flex;
|
||||||
|
height: 100%;
|
||||||
|
flex-direction: row;
|
||||||
|
}
|
||||||
|
|
||||||
|
.elbow-placeholder {
|
||||||
|
border-left: 1px solid #000;
|
||||||
|
height: 100%;
|
||||||
|
width: 30px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.elbow-key {
|
||||||
|
height: 100%;
|
||||||
|
padding: 4px;
|
||||||
|
border-top: 1px solid #000;
|
||||||
|
flex-grow: 1;
|
||||||
|
border-left: 1px solid #000;
|
||||||
|
}
|
||||||
|
|
||||||
|
.elbow-blocker {
|
||||||
|
height: 0;
|
||||||
|
overflow: hidden;
|
||||||
|
}
|
||||||
|
|
||||||
|
.return-value-column {
|
||||||
|
height: 1px
|
||||||
|
}
|
||||||
|
|
||||||
|
.return-value-column td {
|
||||||
|
height: inherit
|
||||||
|
}
|
||||||
|
|
||||||
|
.cell-border {
|
||||||
|
padding: 4px;
|
||||||
|
border-left: 1px solid #000;
|
||||||
|
border-top: 1px solid #000;
|
||||||
|
height: 100%;
|
||||||
|
}
|
||||||
|
|
||||||
|
.documentation-table {
|
||||||
|
border-right: 1px solid #000;
|
||||||
|
border-bottom: 1px solid #000;
|
||||||
|
}
|
294
docs/templates/plugin.rst.j2
vendored
294
docs/templates/plugin.rst.j2
vendored
|
@ -86,135 +86,103 @@ Options
|
||||||
|
|
||||||
.. raw:: html
|
.. raw:: html
|
||||||
|
|
||||||
<table border=1 cellpadding=4>
|
<table border=0 cellpadding=0 class="documentation-table">
|
||||||
|
{# Header of the documentation #}
|
||||||
<tr>
|
<tr>
|
||||||
<th class="head">parameter</th>
|
<th class="head"><div class="cell-border">parameter</div></th>
|
||||||
<th class="head">required</th>
|
<th class="head"><div class="cell-border">required</div></th>
|
||||||
<th class="head">default</th>
|
<th class="head"><div class="cell-border">default</div></th>
|
||||||
<th class="head">choices</th>
|
<th class="head"><div class="cell-border">choices</div></th>
|
||||||
{% if plugin_type != 'module' %}
|
{% if plugin_type != 'module' %}
|
||||||
<th class="head">configuration</th>
|
<th class="head"><div class="cell-border">configuration</div></th>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
<th class="head">comments</th>
|
<th class="head"><div class="cell-border">comments</div></th>
|
||||||
</tr>
|
</tr>
|
||||||
{% for k in option_keys -%}
|
{% for key, value in options.items() recursive %}
|
||||||
{% set v = options[k] -%}
|
<tr class="return-value-column">
|
||||||
{% if not v['suboptions'] %}
|
{# parameter name with introduced label #}
|
||||||
|
|
||||||
<tr>
|
|
||||||
<td>@{ k }@<br/><div style="font-size: small;">{% if v['version_added'] -%} (added in @{v['version_added']}@){% endif -%}</div></td>
|
|
||||||
<td>{% if v.get('required', False) -%}yes{% else %}no{% endif -%}</td>
|
|
||||||
<td>{% if v['default'] -%}@{ v['default'] }@{% endif -%}</td>
|
|
||||||
{% if v.get('type', 'not_bool') == 'bool' %}
|
|
||||||
<td><ul><li>yes</li><li>no</li></ul></td>
|
|
||||||
{% else %}
|
|
||||||
<td>{% if v['choices'] -%}<ul>{% for choice in v.get('choices',[]) -%}<li>@{ choice }@</li>{% endfor -%}</ul>{% endif -%}</td>
|
|
||||||
{% endif %}
|
|
||||||
{% if plugin_type != 'module' %}
|
|
||||||
<td>
|
<td>
|
||||||
{% if 'ini' in v %}
|
<div class="outer-elbow-container">
|
||||||
|
{% for i in range(1, loop.depth) %}
|
||||||
|
<div class="elbow-placeholder">
|
||||||
|
</div>
|
||||||
|
{% endfor %}
|
||||||
|
<div class="elbow-key">
|
||||||
|
@{ key }@<br/><div style="font-size: small;">{% if value.version_added %} (added in @{value.version_added}@){% endif %}</div>
|
||||||
|
</div>
|
||||||
|
<div class="outer-elbow-container">
|
||||||
|
</td>
|
||||||
|
{# required #}
|
||||||
|
<td><div class="cell-border">{% if value.get('required', False) %}yes{% else %}no{% endif %}</div></td>
|
||||||
|
{# default value #}
|
||||||
|
<td><div class="cell-border">{% if value.default %}@{ value.default }@{% endif %}</div></td>
|
||||||
|
{# choices #}
|
||||||
|
<td>
|
||||||
|
<div class="cell-border">
|
||||||
|
{% if value.type == 'boolean' %}
|
||||||
|
<ul>
|
||||||
|
<li>yes</li>
|
||||||
|
<li>no</li>
|
||||||
|
</ul>
|
||||||
|
{% else %}
|
||||||
|
{% if value.choices %}
|
||||||
|
<ul>
|
||||||
|
{% for choice in value.choices %}
|
||||||
|
<li>@{ choice }@</li>
|
||||||
|
{% endfor %}
|
||||||
|
</ul>
|
||||||
|
{% endif %}
|
||||||
|
{% endif %}
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
{# configuration #}
|
||||||
|
{% if plugin_type != 'module' %}
|
||||||
|
<td>
|
||||||
|
<div class="cell-border">
|
||||||
|
{% if 'ini' in value %}
|
||||||
<div> ini entries:
|
<div> ini entries:
|
||||||
{% for ini in v.get('ini') %}
|
{% for ini in value.ini %}
|
||||||
<p>[@{ ini.section }@ ]<br>@{ ini.key}@ = @{ v['default']|default('VALUE') }@</p>
|
<p>[@{ ini.section }@ ]<br>@{ ini.key }@ = @{ value.default | default('VALUE') }@</p>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</div>
|
</div>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% if 'env' in v %}
|
{% if 'env' in value %}
|
||||||
{% for env in v.get('env') %}
|
{% for env in value.env %}
|
||||||
<div>env:@{ env.name }@</div>
|
<div>env:@{ env.name }@</div>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% if 'vars' in v %}
|
{% if 'vars' in value %}
|
||||||
{% for myvar in v.get('vars') %}
|
{% for myvar in value.vars %}
|
||||||
<div>var: @{ myvar.name }@</div>
|
<div>var: @{ myvar.name }@</div>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
</div>
|
||||||
</td>
|
</td>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
{# description #}
|
||||||
<td>
|
<td>
|
||||||
{% if v.description is string %}
|
<div class="cell-border">
|
||||||
<div>@{ v.description | replace('\n', '\n ') | html_ify }@</div>
|
{% if value.description is string %}
|
||||||
{% else %}
|
<div>@{ value.description | replace('\n', '\n ') | html_ify }@</div>
|
||||||
{% for desc in v.description %}
|
{% else %}
|
||||||
|
{% for desc in value.description %}
|
||||||
<p>@{ desc | replace('\n', '\n ') | html_ify }@</p>
|
<p>@{ desc | replace('\n', '\n ') | html_ify }@</p>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% if 'aliases' in v and v.aliases %}
|
{% if 'aliases' in value and value.aliases %}
|
||||||
</br><div style="font-size: small;">aliases: @{ v.aliases|join(', ') }@</div>
|
</br><div style="font-size: small;">aliases: @{ value.aliases|join(', ') }@</div>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
</div>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
{% else %}
|
{% if value.suboptions %}
|
||||||
<tr>
|
{% if value.suboptions.items %}
|
||||||
<td rowspan="2">@{ k }@<br/><div style="font-size: small;">{% if v['version_added'] -%} (added in @{v['version_added']}@){% endif -%}</div></td>
|
@{ loop(value.suboptions.items()) }@
|
||||||
<td>{% if v.get('required', False) -%}yes{% else -%}no{% endif -%}</td>
|
{% elif value.suboptions[0].items %}
|
||||||
<td></td>
|
@{ loop(value.suboptions[0].items()) }@
|
||||||
{% if plugin_type != 'module' %}
|
{% endif %}
|
||||||
<td></td>
|
{% endif %}
|
||||||
{% endif %}
|
{% endfor %}
|
||||||
<td></td>
|
|
||||||
<td>
|
|
||||||
{% if v.description is string %}
|
|
||||||
<div>@{ v.description | replace('\n', '\n ') | html_ify }@</div>
|
|
||||||
{% else %}
|
|
||||||
{% for desc in v.description %}
|
|
||||||
<div>@{ desc | replace('\n', '\n ') | html_ify }@</div>
|
|
||||||
{% endfor %}
|
|
||||||
{% endif %}
|
|
||||||
{% if 'aliases' in v and v.aliases %}
|
|
||||||
</br><div style="font-size: small;">aliases: @{ v.aliases|join(', ') }@</div>
|
|
||||||
{% endif %}
|
|
||||||
</tr>
|
|
||||||
|
|
||||||
<tr>
|
|
||||||
<td colspan="5">
|
|
||||||
<table border=1 cellpadding=4>
|
|
||||||
<caption><b>Dictionary object @{ k }@</b></caption>
|
|
||||||
|
|
||||||
<tr>
|
|
||||||
<th class="head">parameter</th>
|
|
||||||
<th class="head">required</th>
|
|
||||||
<th class="head">default</th>
|
|
||||||
<th class="head">choices</th>
|
|
||||||
<th class="head">comments</th>
|
|
||||||
</tr>
|
|
||||||
{% for k2 in v['suboptions'] %}
|
|
||||||
{% set v2 = v['suboptions'] [k2] %}
|
|
||||||
|
|
||||||
<tr>
|
|
||||||
<td>@{ k2 }@<br/><div style="font-size: small;">{% if v2['version_added'] -%} (added in @{v2['version_added']}@){% endif -%}</div></td>
|
|
||||||
<td>{% if v2.get('required', False) -%}yes{% else -%}no{% endif -%}</td>
|
|
||||||
<td>{% if v2['default'] -%}@{ v2['default'] }@{% endif -%}</td>
|
|
||||||
{% if v2.get('type', 'not_bool') == 'bool' %}
|
|
||||||
<td><ul><li>yes</li><li>no</li></ul></td>
|
|
||||||
{% else %}
|
|
||||||
<td>{% if v2['choices'] -%}<ul>{% for choice in v2.get('choices',[]) -%}<li>@{ choice }@</li>{% endfor -%}</ul>{% endif -%}</td>
|
|
||||||
{% endif %}
|
|
||||||
<td>
|
|
||||||
{% if v2.description is string %}
|
|
||||||
<div>@{ v2.description | replace('\n', '\n ') | html_ify }@</div>
|
|
||||||
{% else %}
|
|
||||||
{% for desc in v2.description %}
|
|
||||||
<div>@{ desc | replace('\n', '\n ') | html_ify }@</div>
|
|
||||||
{% endfor %}
|
|
||||||
{% endif %}
|
|
||||||
{% if 'aliases' in v and v2.aliases %}
|
|
||||||
</br><div style="font-size: small;">aliases: @{ v2.aliases|join(', ') }@</div>
|
|
||||||
{% endif %}
|
|
||||||
</td>
|
|
||||||
</tr>
|
|
||||||
{% endfor %}
|
|
||||||
|
|
||||||
</table>
|
|
||||||
|
|
||||||
</td>
|
|
||||||
</tr>
|
|
||||||
{% endif %}
|
|
||||||
</td>
|
|
||||||
</tr>
|
|
||||||
{% endfor %}
|
|
||||||
|
|
||||||
</table>
|
</table>
|
||||||
</br>
|
</br>
|
||||||
|
|
||||||
|
@ -245,68 +213,64 @@ Common return values are documented :ref:`here <common_return_values>`, the foll
|
||||||
|
|
||||||
.. raw:: html
|
.. raw:: html
|
||||||
|
|
||||||
<table border=1 cellpadding=4>
|
<style>
|
||||||
|
.outer-elbow-container{display: flex;height:100%;flex-direction:row;}
|
||||||
|
.elbow-placeholder{border-left:1px solid #000;height:100%;width:30px;}
|
||||||
|
.elbow-key{height:100%;padding:4px;border-top:1px solid #000;flex-grow:1;border-left:1px solid #000;}
|
||||||
|
.elbow-blocker{height:0;overflow:hidden;}
|
||||||
|
.return-value-column{height:1px}
|
||||||
|
.return-value-column td{height:inherit}
|
||||||
|
.cell-border{padding:4px;border-left:1px solid #000; border-top:1px solid #000;height:100%;}
|
||||||
|
.documentation-table{border-right:1px solid #000;border-bottom:1px solid #000;}
|
||||||
|
</style>
|
||||||
|
|
||||||
|
<table border=0 cellpadding=0 class="documentation-table">
|
||||||
<tr>
|
<tr>
|
||||||
<th class="head">name</th>
|
<th class="head"><div class="cell-border">name</div></th>
|
||||||
<th class="head">description</th>
|
<th class="head"><div class="cell-border">description</div></th>
|
||||||
<th class="head">returned</th>
|
<th class="head"><div class="cell-border">returned</div></th>
|
||||||
<th class="head">type</th>
|
<th class="head"><div class="cell-border">type</div></th>
|
||||||
<th class="head">sample</th>
|
<th class="head"><div class="cell-border">sample</div></th>
|
||||||
</tr>
|
</tr>
|
||||||
{% for entry in returndocs %}
|
{% for key, value in returndocs.items() recursive %}
|
||||||
|
<tr class="return-value-column">
|
||||||
<tr>
|
|
||||||
<td>@{ entry }@</td>
|
|
||||||
<td>
|
<td>
|
||||||
{% if returndocs[entry].description is string %}
|
<div class="outer-elbow-container">
|
||||||
<div>@{ returndocs[entry].description | replace('\n', '\n ') | html_ify }@</div>
|
{% for i in range(1, loop.depth) %}
|
||||||
{% else %}
|
<div class="elbow-placeholder">
|
||||||
{% for desc in returndocs[entry].description %}
|
</div>
|
||||||
<div>@{ desc | replace('\n', '\n ') | html_ify }@</div>
|
{% endfor %}
|
||||||
{% endfor %}
|
<div class="elbow-key">
|
||||||
{% endif %}
|
@{ key }@
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
</td>
|
</td>
|
||||||
<td align=center>@{ returndocs[entry].returned }@</td>
|
|
||||||
<td align=center>@{ returndocs[entry].type }@</td>
|
|
||||||
<td align=center>@{ returndocs[entry].sample | replace('\n', '\n ') | html_ify }@</td>
|
|
||||||
</tr>
|
|
||||||
{% if returndocs[entry].type == 'complex' %}
|
|
||||||
|
|
||||||
<tr>
|
|
||||||
<td>contains:</td>
|
|
||||||
<td colspan=4>
|
|
||||||
<table border=1 cellpadding=2>
|
|
||||||
|
|
||||||
<tr>
|
|
||||||
<th class="head">name</th>
|
|
||||||
<th class="head">description</th>
|
|
||||||
<th class="head">returned</th>
|
|
||||||
<th class="head">type</th>
|
|
||||||
<th class="head">sample</th>
|
|
||||||
</tr>
|
|
||||||
{% for sub in returndocs[entry].contains %}
|
|
||||||
|
|
||||||
<tr>
|
|
||||||
<td>@{ sub }@</td>
|
|
||||||
<td>
|
<td>
|
||||||
{% if returndocs[entry].contains[sub].description is string %}
|
{% if value.description is string %}
|
||||||
<div>@{ returndocs[entry].contains[sub].description | replace('\n', '\n ') | html_ify }@</div>
|
<div class="cell-border">@{ value.description | replace('\n', '\n ') | html_ify }@</div>
|
||||||
{% else %}
|
{% else %}
|
||||||
{% for desc in returndocs[entry].contains[sub].description %}
|
{% for desc in value.description %}
|
||||||
<div>@{ desc | replace('\n', '\n ') | html_ify }@</div>
|
<div class="cell-border">@{ desc | replace('\n', '\n ') | html_ify }@</div>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</td>
|
</td>
|
||||||
<td align=center>@{ returndocs[entry].contains[sub].returned }@</td>
|
<td align=center><div class="cell-border">@{ value.returned }@</div></td>
|
||||||
<td align=center>@{ returndocs[entry].contains[sub].type }@</td>
|
<td align=center><div class="cell-border">@{ value.type }@</div></td>
|
||||||
<td align=center>@{ returndocs[entry].contains[sub].sample }@</td>
|
<td align=center><div class="cell-border">@{ value.sample | replace('\n', '\n ') | html_ify }@</div></td>
|
||||||
</tr>
|
</tr>
|
||||||
{% endfor %}
|
{# ---------------------------------------------------------
|
||||||
</table>
|
# sadly we cannot blindly iterate through the child dicts,
|
||||||
</td></tr>
|
# since in some documentations,
|
||||||
{% endif %}
|
# lists are used instead of dicts. This handles both types
|
||||||
{% endfor %}
|
# ---------------------------------------------------------#}
|
||||||
|
{% if value.contains %}
|
||||||
|
{% if value.contains.items %}
|
||||||
|
@{ loop(value.contains.items()) }@
|
||||||
|
{% elif value.contains[0].items %}
|
||||||
|
@{ loop(value.contains[0].items()) }@
|
||||||
|
{% endif %}
|
||||||
|
{% endif %}
|
||||||
|
{% endfor %}
|
||||||
</table>
|
</table>
|
||||||
</br></br>
|
</br></br>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
Loading…
Reference in a new issue