Skip to content

Commit

Permalink
Documentation: show non-string non-iterable defaults for choices (#40… (
Browse files Browse the repository at this point in the history
#42075)

* 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

(cherry picked from commit 0752dc1)

* for 2.6 compatibility, removes dependency on collections.py, take two

* fix blank line error
  • Loading branch information
Alicia Cozine authored and mattclay committed Jul 17, 2018
1 parent 498aca8 commit b0dae4f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
9 changes: 8 additions & 1 deletion docs/bin/plugin_formatter.py
Expand Up @@ -29,7 +29,7 @@
import re
import sys
import warnings
from collections import defaultdict
from collections import defaultdict, Sequence
from distutils.version import LooseVersion
from pprint import PrettyPrinter

Expand Down Expand Up @@ -154,6 +154,12 @@ def rst_xline(width, char="="):
return char * width


def test_list(value):
''' Return true if the object is a list or tuple '''

return isinstance(value, Sequence) and not isinstance(value, string_types)


def write_data(text, output_dir, outputname, module=None):
''' dumps module output to a file or the screen, as requested '''

Expand Down Expand Up @@ -334,6 +340,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':
Expand Down
2 changes: 1 addition & 1 deletion docs/templates/plugin.rst.j2
Expand Up @@ -143,7 +143,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) %}
<li><div style="color: blue"><b>@{ choice | escape }@</b>&nbsp;&larr;</div></li>
{% else %}
<li>@{ choice | escape }@</li>
Expand Down

0 comments on commit b0dae4f

Please sign in to comment.