Skip to content

Commit f06fb19

Browse files
committed
Integrate inventory template and various tweaks
1 parent bf1d4a6 commit f06fb19

File tree

7 files changed

+137
-88
lines changed

7 files changed

+137
-88
lines changed

docs/extra.css

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
/*
2+
* The default max-width is 61rem which does not provide nearly enough space to present code examples or larger tables
3+
*/
4+
.md-grid {
5+
margin-left: auto;
6+
margin-right: auto;
7+
max-width: 95%;
8+
}

docs/requirements.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
---
22
collections:
33
- name: "ansible.posix"
4+
- name: "networktocode.nautobot"

mkdocs.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,21 @@ theme:
3737
icon: "material/weather-night"
3838
name: "Switch to light mode"
3939

40+
extra_css:
41+
- "extra.css"
42+
4043
plugins:
4144
- "search"
4245
- "ansible-collection":
4346
"collections":
4447
- "ansible.builtin"
4548
- "ansible.posix"
49+
- "networktocode.nautobot"
50+
51+
# - name: "ansible.builtin"
52+
# plugin_types:
53+
# - inventory
54+
# - module
4655

4756
markdown_extensions:
4857
- "admonition"

mkdocs_ansible_collection/plugin.py

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ class AnsibleDocsPlugin(mkdocs.plugins.BasePlugin[AnsibleDocsPluginConfig]):
2525
"""MkDocs Plugin Class."""
2626

2727
# TODO: Remove once all plugin types have a corresponding jinja template
28-
PLUGIN_MAP = {"filter": "filter"}
28+
PLUGIN_MAP = {"filter": "filter", "inventory": "inventory"}
2929

3030
def __init__(self, *args, **kwargs):
3131
"""Instantiation."""
@@ -39,6 +39,7 @@ def __init__(self, *args, **kwargs):
3939
loader=FileSystemLoader(package_files("mkdocs_ansible_collection") / "templates"),
4040
autoescape=select_autoescape(default=True),
4141
trim_blocks=True,
42+
lstrip_blocks=True,
4243
)
4344

4445
def on_pre_build(self, config):
@@ -75,6 +76,8 @@ def on_files(self, files, config):
7576
collection_metadata = AnsibleDocsPlugin._get_ansible_doc_metadata(fqcn)
7677

7778
# Generate the index for the collection sub-path
79+
# TODO: extract requirements from all plugins and list on this page
80+
# TODO: extract collection version
7881
files.append(
7982
self._generate_page(
8083
path=f"{fqcn}/index.md",
@@ -103,17 +106,25 @@ def on_files(self, files, config):
103106
)
104107
)
105108

106-
for plugin in plugins:
107-
plugin_name = plugin.removeprefix(fqcn + ".")
109+
for plugin_fqname, plugin_data in plugins.items():
110+
if plugin_data.get("error") is not None:
111+
log.warning(
112+
f"Error returned for {plugin_fqname} by ansible-doc: {plugin_data['error']}"
113+
)
114+
continue
115+
log.debug(f"Generating page for {plugin_fqname}")
116+
plugin_name = plugin_fqname.removeprefix(fqcn + ".")
108117
files.append(
109118
self._generate_page(
110119
path=f"{fqcn}/{plugin_type}/{plugin_name}.md",
111120
site_dir=config.site_dir,
112121
# TODO: replace line once the mapping is not needed
113122
# template=f"{plugin_type}.md.jinja",
114123
template=f"{AnsibleDocsPlugin.PLUGIN_MAP.get(plugin_type, 'default')}.md.jinja", # noqa
115-
plugin=plugin,
116-
plugin_data=plugins[plugin],
124+
fqcn=fqcn,
125+
plugin=plugin_fqname,
126+
plugin_name=plugin_name,
127+
plugin_data=plugin_data,
117128
)
118129
)
119130

mkdocs_ansible_collection/templates/_templates/inventory.md.j2

Lines changed: 0 additions & 83 deletions
This file was deleted.

mkdocs_ansible_collection/templates/collection_index.md.jinja

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,30 @@
11
# Collection - {{ fqcn }}
22

3+
## Useful Links
4+
5+
- Ansible Galaxy: [{{ fqcn }}](https://galaxy.ansible.com/{{ fqcn | replace(".", "/") }})
6+
7+
{# TODO: Find a way to extract useful URLs for the collection, like source repo, issues tracker etc. #}
8+
9+
!!! note "Usage Note"
10+
To install the collection, run:
11+
12+
```
13+
ansible-galaxy collection install {{ fqcn }}
14+
```
15+
16+
For more information about available versions, visit the [Ansible Galaxy](https://galaxy.ansible.com/{{ fqcn | replace(".", "/") }}) page.
17+
18+
{# {% if requirements is defined and requirements is not none %}
19+
The following Python packages are needed on the host that executes this module:
20+
21+
{% for req in requirements %}
22+
- [{{ req }}](https://pypi.org/project/{{ req }}/)
23+
{% endfor %}
24+
{% endif %} #}
25+
26+
## Plugins
27+
328
This collection contains the following plugin types:
429

530
| Plugin Type | Count |
@@ -9,3 +34,4 @@ This collection contains the following plugin types:
934
| [{{ plugin_type }}](./{{ plugin_type }}/index.md) | {{ plugin_types[plugin_type] | length }}
1035
{% endif %}
1136
{% endfor %}
37+
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
{% set pd = plugin_data['doc'] %}
2+
# {{ plugin_name }}
3+
4+
!!! note "Collection Note"
5+
This module is part of the [{{ fqcn }} collection](https://galaxy.ansible.com/{{ fqcn | replace(".", "/") }}). To install the collection, use:
6+
7+
```
8+
ansible-galaxy collection install {{ fqcn }}
9+
```
10+
{% if pd['requirements'] is defined and pd['requirements'] is not none %}
11+
You need further requirements to be able to use this module, see the [Requirements](#requirements) section for details.
12+
{% endif %}
13+
14+
## Synopsis
15+
16+
{% for desc_item in pd['description'] %}
17+
- {{ desc_item}}
18+
{% endfor %}
19+
20+
{% if pd['requirements'] is defined and pd['requirements'] is not none %}
21+
## Requirements
22+
23+
The following Python packages are needed on the host that executes this module:
24+
25+
{% for req in pd['requirements'] %}
26+
- [{{ req }}](https://pypi.org/project/{{ req }}/)
27+
{% endfor %}
28+
{% endif %}
29+
30+
{% if pd['options'] is defined and pd['options'] is not none %}
31+
## Parameters
32+
33+
| Parameter | Data Type | Environment Variable | Version Added | Comments |
34+
| --------- | --------- | -------------------- | ------------- | -------- |
35+
{% for param_name, param_values in pd['options'].items() %}
36+
{% if param_values['description'] is string %}
37+
| {{ param_name }} | {{ param_values['type'] }} | {% for env_var in param_values['env'] %} {{ env_var['name'] }} {% endfor %} | {{ param_values['version_added'] | default('') }} | {{ param_values['description'] }} |
38+
{% else %}
39+
| {{ param_name }} | {{ param_values['type'] }} | {% for env_var in param_values['env'] %} {{ env_var['name'] }} {% endfor %} | {{ param_values['version_added'] | default('') }} | {{ param_values['description'] | join(' ') }} |
40+
{% endif %}
41+
{% endfor %}
42+
{% endif %}
43+
44+
{% if pd['notes'] is defined and pd['notes'] is not none %}
45+
## Notes
46+
47+
!!! note "Note"
48+
{% for note in pd['notes'] %}
49+
- {{ note }}
50+
{% endfor %}
51+
{% endif %}
52+
53+
## Examples
54+
55+
```yaml
56+
{{ plugin_data['examples'] }}
57+
```
58+
59+
{% if plugin_data['return'] is not none %}
60+
## Return Values
61+
62+
| Key | Data Type | Description | Returned |
63+
| --- | --------- | ----------- | -------- |
64+
{% for key, values in plugin_data['return'].items() %}
65+
{% if values['description'] is string %}
66+
| {{ key }} | {{ values['type'] }} | {{ values['description'] }} | {{ values['returned'] }} |
67+
{% else %}
68+
| {{ key }} | {{ values['type'] }} | {{ values['description'] | join(" ") }} | {{ values['returned'] }} |
69+
{% endif %}
70+
{% endfor %}
71+
{% endif %}
72+
73+
## Authors
74+
75+
{% for author in pd['author'] %}
76+
- {{ author }}
77+
{% endfor %}

0 commit comments

Comments
 (0)