Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add_docs: generate the index.rst #56

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 14 additions & 3 deletions collection_prep/cmd/add_docs.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ def convert_descriptions(data):
convert_descriptions(definition["contains"])


def jinja_environment():
def jinja_environment(tpl_name):
"""Define the jinja environment

:return: A jinja template, with the env set
Expand All @@ -110,7 +110,7 @@ def jinja_environment():
env.filters["html_ify"] = html_ify
env.globals["to_kludge_ns"] = to_kludge_ns
env.globals["from_kludge_ns"] = from_kludge_ns
template = env.get_template("plugin.rst.j2")
template = env.get_template(tpl_name)
return template


Expand Down Expand Up @@ -300,7 +300,7 @@ def process(collection, path): # pylint: disable-msg=too-many-locals
:param path: The path to the collection
:type path: str
"""
template = jinja_environment()
template = jinja_environment("plugin.rst.j2")
docs_path = Path(path, "docs")
if docs_path.is_dir():
logging.info("Purging content from directory %s", docs_path)
Expand Down Expand Up @@ -390,6 +390,11 @@ def process(collection, path): # pylint: disable-msg=too-many-locals
return content


def generate_index_rst(path, content, galaxy, version):
template = jinja_environment("index.rst.j2")
index_path = Path(path, "docs") / "index.rst"
index_path.write_text(template.render(content, galaxy=galaxy, version=version))

def load_galaxy(path):
"""Load collection details from the galaxy.yml file in the collection

Expand Down Expand Up @@ -530,6 +535,11 @@ def main():
default=False,
help="Link the collection in ~/.ansible/collections",
)
parser.add_argument(
"--version",
help="Overwrite the version from galaxy.yaml",
required=False,
)

if argcomplete:
argcomplete.autocomplete(parser)
Expand All @@ -546,6 +556,7 @@ def main():
if args.link_collection:
link_collection(path, galaxy)
content = process(collection=collection, path=path)
generate_index_rst(path, content, galaxy, args.version)
update_readme(
content=content,
path=args.path,
Expand Down
36 changes: 36 additions & 0 deletions collection_prep/cmd/index.rst.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@

.. _plugins_in_@{galaxy['namespace']}@.@{galaxy['name']}@:


@{galaxy['namespace'].capitalize()}@.@{galaxy['name'].capitalize()}@
@{ "=" * (galaxy['namespace']|length + galaxy['name']|length +1)}@

Collection version @{galaxy.get('version', version)}@

.. toctree::
:maxdepth: 1

Plugin Index
------------

These are the plugins in the @{galaxy['namespace']}@.@{galaxy['name']}@ collection


Modules
~~~~~~~

{% for m in modules %}
* :ref:`@{m.split('.')[1]}@ <ansible_collections.@{m}@>` -- @{modules[m]["comment"]}@
{% endfor %}

.. seealso::

List of :ref:`collections <list_of_collections>` with docs hosted here.

.. toctree::
:maxdepth: 1
:hidden:

{% for m in modules %}
@{m}@
{% endfor %}