summaryrefslogtreecommitdiff
path: root/docs
diff options
context:
space:
mode:
authorToshio Kuratomi <a.badger@gmail.com>2021-06-03 13:13:43 -0700
committerGitHub <noreply@github.com>2021-06-03 15:13:43 -0500
commit0691475caf484bde674267e154865ab8c7a99a76 (patch)
treeb6f12dec67c2d8df3e0bd47103ef21ebf1e8843e /docs
parentd53fb60af3c7a918d47e09297a9335a951429c80 (diff)
downloadansible-0691475caf484bde674267e154865ab8c7a99a76.tar.gz
Workaround bug in jinja2-3.0.0 and 3.0.1 (#74795)
Jinja2-3.0.0 and 3.0.1 has a bug where undefined values cannot be checked to see if they contain a value: https://github.com/pallets/jinja/issues/1448#issuecomment-846029509 We workaround this in two ways, either of which would be sufficient: * Normalize the data so that choices is an empty iterable when it isn't specified in the documentation. This is what antsibull-docs (and thus documentation builds on 2.10+) do. * Change the logic in the template to check whether choices exists before checking containment. This better expresses the logic at that point in the template (if there is a default value but there is not a list of choices, then display the default in its own string) so it's a good change to make as well.
Diffstat (limited to 'docs')
-rw-r--r--docs/templates/plugin.rst.j29
1 files changed, 7 insertions, 2 deletions
diff --git a/docs/templates/plugin.rst.j2 b/docs/templates/plugin.rst.j2
index b829dd42a5..a2f6046445 100644
--- a/docs/templates/plugin.rst.j2
+++ b/docs/templates/plugin.rst.j2
@@ -144,6 +144,7 @@ Parameters
{% elif choice is sameas false %}
{% set choice = 'no' %}
{% endif %}
+ {# Format default values differently (whenever a choice is one of the default values) #}
{% if (value.default is not list and value.default == choice) or (value.default is list and choice in value.default) %}
<li><div style="color: blue"><b>@{ choice | escape }@</b>&nbsp;&larr;</div></li>
{% else %}
@@ -152,8 +153,12 @@ Parameters
{% endfor %}
</ul>
{% endif %}
- {# Show default value, when multiple choice or no choices #}
- {% if value.default is defined and value.default not in value.choices %}
+ {# Show default value on a separate line when there is a non-None default (None
+ is usually a sentinel that shows the user didn't specify it) and there
+ either are no choices (like a freeform string) or the default does not exist
+ in choices
+ #}
+ {% if value.default is defined and value.default is not none and (not value.choices or value.default not in value.choices) %}
<b>Default:</b><br/><div style="color: blue">@{ value.default | tojson | escape }@</div>
{% endif %}
</td>