From 0752dc12b79f81029341bc23a01df0757d81e475 Mon Sep 17 00:00:00 2001 From: Felix Fontein Date: Thu, 28 Jun 2018 04:31:47 +0200 Subject: [PATCH] Documentation: show non-string non-iterable defaults for choices (#40212) * Also marking non-string defaults. * Adding list filter from #37517 to plugin_formatter. * Simplifying list test. * Redistribute imports --- docs/bin/plugin_formatter.py | 6 ++++++ docs/templates/plugin.rst.j2 | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/docs/bin/plugin_formatter.py b/docs/bin/plugin_formatter.py index 330a7540ab8..03639b3c6dd 100755 --- a/docs/bin/plugin_formatter.py +++ b/docs/bin/plugin_formatter.py @@ -31,6 +31,7 @@ import sys import warnings from collections import defaultdict from distutils.version import LooseVersion +from functools import partial from pprint import PrettyPrinter try: @@ -49,6 +50,7 @@ from six import iteritems, string_types from ansible.errors import AnsibleError from ansible.module_utils._text import to_bytes, to_text +from ansible.module_utils.common.collections import is_sequence from ansible.plugins.loader import fragment_loader from ansible.utils import plugin_docs from ansible.utils.display import Display @@ -154,6 +156,9 @@ def rst_xline(width, char="="): return char * width +test_list = partial(is_sequence, include_strings=False) + + def write_data(text, output_dir, outputname, module=None): ''' dumps module output to a file or the screen, as requested ''' @@ -334,6 +339,7 @@ def jinja2_environment(template_dir, typ, plugin_type): env.filters['html_ify'] = html_ify env.filters['fmt'] = rst_fmt env.filters['xline'] = rst_xline + env.tests['list'] = test_list templates['plugin'] = env.get_template('plugin.rst.j2') if plugin_type == 'module': diff --git a/docs/templates/plugin.rst.j2 b/docs/templates/plugin.rst.j2 index d3ebc7c5607..c385ac9c635 100644 --- a/docs/templates/plugin.rst.j2 +++ b/docs/templates/plugin.rst.j2 @@ -142,7 +142,7 @@ Parameters {% elif choice is sameas false %} {% set choice = 'no' %} {% endif %} - {% if (value.default is string and value.default == choice) or (value.default is iterable and value.default is not string and choice in value.default) %} + {% if (value.default is not list and value.default == choice) or (value.default is list and choice in value.default) %}
  • @{ choice | escape }@ ←
  • {% else %}
  • @{ choice | escape }@