Add type to role variables

This brings this documentation into line with other values like attr
where you can specify the type of the variable.

The type output is added to each entry where appropriate, one minor
change is that we need to be less strict on the type lookup for
the hint suffix on sub-entries for types like "bool"

The documentation/test-case is updated.

Change-Id: Icc01ec6f04af97beeb085f6dbcf37b0d9dbed1fd
This commit is contained in:
Ian Wienand 2019-03-06 11:11:46 +11:00
parent 1a2258eb5c
commit 6a0034ebca
2 changed files with 22 additions and 1 deletions

View File

@ -25,6 +25,21 @@ Roles
This is an item in a list. This is an item in a list.
.. rolevar:: dict
:type: dict
This variable is a dict.
.. rolevar:: key
This is a key which should be assigned a value.
.. rolevar:: flag-value
:type: bool
:default: False
A variable which should be assigned a True/False value.
This is an (Ansible) role (Sphinx) role: :role:`example` This is an (Ansible) role (Sphinx) role: :role:`example`
This is an (Ansible) role variable (Sphinx) role: :rolevar:`example.items.baz` This is an (Ansible) role variable (Sphinx) role: :rolevar:`example.items.baz`

View File

@ -404,7 +404,7 @@ class ZuulVarDirective(ZuulObjectDescription):
} }
def get_type_str(self): def get_type_str(self):
if 'type' in self.options: if 'type' in self.options and self.options['type'] in self.type_map:
return self.type_map[self.options['type']] return self.type_map[self.options['type']]
return '' return ''
@ -443,6 +443,12 @@ class ZuulVarDirective(ZuulObjectDescription):
line += nodes.literal(self.options['default'], line += nodes.literal(self.options['default'],
self.options['default']) self.options['default'])
signode += line signode += line
if 'type' in self.options:
line = addnodes.desc_signature_line()
line += addnodes.desc_type('Type: ', 'Type: ')
line += nodes.emphasis(self.options['type'],
self.options['type'])
signode += line
return sig return sig