-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathmodule.md.j2
101 lines (75 loc) · 2.78 KB
/
module.md.j2
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
# {{ module }}
{% if description %}
{% for line in description %}
{{ line }}
{% endfor %}
{% endif %}
- [Examples](#examples)
- [Parameters](#parameters)
- [Return Values](#return-values)
## Examples
{% for example in examples %}```yaml{{ example }}
```
{% endfor %}
{% set blocks = {} %}
{% macro accumulate_blocks(opts) %}
{% for name, spec in opts.items() %}{% if spec.suboptions %}{{ blocks.__setitem__(name, spec.suboptions) or '' }}{{ accumulate_blocks(spec.suboptions) or '' }}{% endif %}{% endfor %}
{% endmacro %}
{{ accumulate_blocks(options) }}
{% macro options_display_req(opts, required) %}
{% for name, spec in opts.items() %}
{% if not spec.doc_hide and ((spec.required and required) or (not spec.required and not required)) %}
{% set required_text = '**Required**' if spec.required else 'Optional' %}
{% set type_text = '`%s`' % spec.type if spec.type else '' %}
{% set name_fmt = '[`%s` (sub-options)](#%s)' % (name, name) if spec.suboptions else '`%s`' % name %}
{% set extras_fmt = [] %}
{% set choices_fmt = [] %}
{% if spec.choices -%}
{% for choice in spec.choices -%}
{{ choices_fmt.append('`{}`'.format(choice|string)) or ''}}
{%- endfor %}
{{ extras_fmt.append("Choices: " + ', '.join(choices_fmt)) or '' }}
{%- endif %}
{% if spec.default or spec.default == False -%}
{{ extras_fmt.append('Default: `{}`'.format(spec.default)) or ''}}
{%- endif %}
{% if spec.editable -%}
{{ extras_fmt.append("Updatable") or '' }}
{%- endif %}
| {{ name_fmt }} | <center>{{type_text}}</center> | <center>{{ required_text }}</center> | {% for line in spec.description %}{{ line }} {% endfor %} {% if extras_fmt | length > 0 %}**({{ extras_fmt|join('; ') }})**{% endif %} |
{% endif %}
{% endfor %}
{% endmacro %}
{% macro options_display(opts) %}
{{ options_display_req(opts, True) }}{{ options_display_req(opts, False) }}
{% endmacro %}
{% macro options_table(opts) %}
| Field | Type | Required | Description |
|-----------|------|----------|------------------------------------------------------------------------------|
{{ options_display(opts) }}
{% endmacro %}
{% if options | length > 0 %}
## Parameters
{{ options_table(options) }}
{% for name, spec in blocks.items() %}
### {{ name }}
{{ options_table(spec) }}
{% endfor %}
{% endif %}
## Return Values
{% for name, spec in return_values.items() %}
- `{{ name }}`{% if spec.description %} - {% for line in spec.description %}{{ line }}{% endfor %}{% endif %}
{% if spec.sample %}
- Sample Value:
{% for sample in spec.sample %}
```json
{% for line in sample.split('\n') %}
{{ line }}
{% endfor %}
```
{% endfor %}
{% endif %}
{% if spec.docs_url %}
- See the [API documentation]({{spec.docs_url}}) for a list of returned fields
{% endif %}
{% endfor %}