{#
 # Template for Ansible role spec files for use by ansible-doc-template-extractor.
 # This template uses the role spec file format defined in the ansible-doc-template-extractor project.
 # This template produces an .md file.
 # For the input variables that are set, run: ansible-doc-template-extractor --help-template.
 #}
{% macro para_generation(paras, level) %}
{# Macro that generates a list of paragraphs #}
{% if paras is string %}
{{ "  " * level }}{{ paras | to_md }}

{% elif paras is iterable %}
{%   for para in paras %}
{{ "  " * level }}{{ para | to_md }}

{%   endfor %}
{% else %}
{{ "  " * level }}{{ para | to_md }}
{% endif %}
{% endmacro %}
{% macro indent(multiline, level) %}
{# Macro that generates an indented multi-line string #}
{%   for line in multiline.split('\n') %}
{{ "  " * level }}{{ line }}
{%   endfor %}
{% endmacro %}
{% macro option_generation(opts, level) %}
{# Macro that generates a list of options, recursively #}
{%   set sorted = false %}{# Flag to sort options by name #}
{%   for name, spec in (opts | dictsort if sorted else opts.items()) %}
{%     if spec.required | default(False) == True %}
{%       set required_txt = "Required." %}
{%     elif spec.default is defined %}
{%       set required_txt = "Optional, default: {}.".format(spec.default) %}
{%     else %}
{%       set required_txt = "Optional." %}
{%     endif %}
{%     if spec.type == 'list' %}
{%       set type_txt = "list of {}".format(spec.elements) %}
{%     else %}
{%       set type_txt = spec.type %}
{%     endif %}
{%     if spec.choices is defined %}
{%       set choices_txt = "Choices: {}.".format(spec.choices | join(', ')) %}
{%     else %}
{%       set choices_txt = "" %}
{%     endif %}
{{ "  " * level }}* **{{ name }}** ({{ type_txt }}):

{{ para_generation(spec.description, level + 1) }}
{{ "  " * level }}  {{ required_txt | to_md }}
{%     if spec.choices is defined %}

{{ "  " * level }}  {{ choices_txt | to_md }}
{%     endif %}
{%     if spec.options is defined %}
{{ option_generation(spec.options, level + 1) }}
{%     endif %}

{%   endfor %}
{% endmacro %}

<!-- This file has been generated by ansible-doc-template-extractor. -->
<!-- Do not modify this file manually, but modify its spec file source! -->

{% for role_name, role_dict in spec_file_dict.argument_specs.items() %}
{%   if role_name == 'main' %}
{%     set title = "Role {} -- {}".format(name, role_dict.short_description) %}
{%   else %}
{%     set title = "Subrole {}.{} -- {}".format(name, role_name, role_dict.short_description) %}
{%   endif %}
# {{ title }}

## Synopsis

{%   if role_dict.description is iterable and role_dict.description is not string %}
{%     for item in role_dict.description %}
{{ para_generation(item, 0) }}
{%     endfor %}
{%   else %}
{{ para_generation(role_dict.description, 0) }}
{%   endif %}
{%   if role_dict.version_added is defined %}

## Version added

{{ role_dict.version_added }}
{%   endif %}
{%   if role_dict.options.keys() | list | length > 0 %}

## Input Parameters

{{ option_generation(role_dict.options, 0) }}
{%   endif %}
{%   if role_dict.output is defined and role_dict.output | length > 0 %}

## Output Parameters

{{ option_generation(role_dict.output, 0) }}
{%   endif %}
{%   if role_dict.local is defined and role_dict.local | length > 0 %}

## Local Variables

{{ option_generation(role_dict.local, 0) }}
{%   endif %}
{% if role_dict.examples is defined %}

## Examples

{%     for example in role_dict.examples %}
* {{ para_generation(example.short_description, 0) }}
{%       if example.description is defined %}

{{ para_generation(example.description, 1) }}
{%       endif %}

  ```
{{ (indent(example.code | trim, 1)) | trim('\n') }}
  ```

{%   endfor %}
{% endif %}
{%   if role_dict.author is defined %}

## Authors

{%     if role_dict.author is iterable and role_dict.author is not string %}
{%       for item in role_dict.author %}
* {{ item }}
{%       endfor %}
{%     else %}
* {{ role_dict.author }}
{%     endif %}
{%   endif %}
{% endfor %}
