{#
 # Template for Ansible playbooks that have a spec file for use with ansible-doc-template-extractor.
 # 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 schema_generation(obj, level) %}
{# Macro that generates a list of properties defined in an object within a JSON schema, recursively #}
{%   for name, spec in obj.properties.items() if not name.startswith('_') %}
{%     set required = name in obj.required %}
{%     if required %}
{%       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 == 'array' %}
{%       if spec.__getitem__('items') is defined %}
{%         set type_txt = "list of {}".format(spec.__getitem__('items').type) %}
{%       else %}
{%         set type_txt = "list" %}
{%       endif %}
{%     else %}
{%       set type_txt = spec.type %}
{%     endif %}
{%     if spec.enum is defined %}
{%       set choices_txt = "Choices: {}.".format(spec.enum | 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.type == 'array' and spec.__getitem__('items') is defined %}

{{ schema_generation(spec.__getitem__('items'), level + 1) }}
{%     elif spec.type == 'object' and spec.properties is defined %}

{{ schema_generation(spec, 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! -->

{% set playbook_dict = spec_file_dict.playbook %}
{% set title = "Playbook {} -- {}".format(name, playbook_dict.short_description) %}
# {{ title }}

## Synopsis

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

## Requirements

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

## Version added

{{ playbook_dict.version_added }}
{% endif %}
{% if playbook_dict.input_schema is defined %}

## Input Parameters

{%   if playbook_dict.input_schema.description is defined %}
{{ para_generation(playbook_dict.input_schema.description, 0) }}

{%   endif %}
{{ schema_generation(playbook_dict.input_schema, 0) }}
{% endif %}
{% if playbook_dict.output_schema is defined %}

## Output Parameters

{%   if playbook_dict.output_schema.description is defined %}
{{ para_generation(playbook_dict.output_schema.description, 0) }}

{%   endif %}
{{ schema_generation(playbook_dict.output_schema, 0) }}
{% endif %}
{% if playbook_dict.examples is defined %}

## Examples

{%   for example in playbook_dict.examples %}
* {{ para_generation(example.description, 0) }}

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

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

## Authors

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