.. _{{ directive_name }}:

{{ '=' * (directive_name | length + 6) }}
``{{ directive_name }}``
{{ '=' * (directive_name | length + 6) }}

**Library:** {{ library }}

**Machine name:** {{ machine_name }}

.. rst:directive:: .. {{ directive_name }}::
{% if has_body %}

   **Body:** {{ body_label }}
   {{ body_description }}
{% endif %}
{% if options %}

   **Options:**

   .. list-table::
      :header-rows: 1
      :widths: 20 10 10 60

      * - Option
        - Type
        - Required
        - Description
{% for opt in options %}
      * - ``:{{ opt.name }}:``
        - {{ opt.field_type }}
        - {{ "Yes" if opt.required else "No" }}
        - {{ opt.description or opt.label }}
{% if opt.field_type == 'boolean' %}
      * - ``:{{ opt.negated_name }}:``
        - flag
        - No
        - Negated form of ``:{{ opt.name }}:``
{% endif %}
{% if opt.field_type == 'select' %}

        Allowed values:
{% for choice in opt.choices %}
        - ``{{ choice.value }}``: {{ choice.label }}
{% endfor %}
{% endif %}
{% endfor %}
{% endif %}
{% if structural_children %}

   **Nested directives:**
{% for child in structural_children %}

   - ``.. {{ child.directive_name }}::``{% if child.min_count > 0 %} (required, min {{ child.min_count }}){% endif %}{% if child.max_count %} (max {{ child.max_count }}){% endif %}

{% endfor %}
{% endif %}
{% if library_children %}

   **Library children:**
{% for child in library_children %}

   - ``.. {{ child.directive_name }}::`` ({{ child.libraries | join(', ') }})
{% endfor %}
{% endif %}

Example
-------

.. code-block:: rst

   .. {{ directive_name }}::
{% if options %}
{% for opt in options[:3] %}
{% if opt.field_type == 'boolean' %}
      :{{ opt.name }}:
{% elif opt.field_type == 'select' and opt.choices %}
      :{{ opt.name }}: {{ opt.choices[0].value }}
{% else %}
      :{{ opt.name }}: value
{% endif %}
{% endfor %}
{% endif %}
{% if has_body %}

      {{ body_label }} goes here.
{% endif %}
