Browse Source

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
tags/0.4.0^0
Ian Wienand 2 months ago
parent
commit
6a0034ebca
2 changed files with 22 additions and 1 deletions
  1. 15
    0
      doc/source/example-roles.rst
  2. 7
    1
      zuul_sphinx/zuul.py

+ 15
- 0
doc/source/example-roles.rst View File

@@ -25,6 +25,21 @@ Roles
25 25
 
26 26
          This is an item in a list.
27 27
 
28
+   .. rolevar:: dict
29
+      :type: dict
30
+
31
+      This variable is a dict.
32
+
33
+      .. rolevar:: key
34
+
35
+         This is a key which should be assigned a value.
36
+
37
+   .. rolevar:: flag-value
38
+      :type: bool
39
+      :default: False
40
+
41
+      A variable which should be assigned a True/False value.
42
+
28 43
 This is an (Ansible) role (Sphinx) role: :role:`example`
29 44
 
30 45
 This is an (Ansible) role variable (Sphinx) role: :rolevar:`example.items.baz`

+ 7
- 1
zuul_sphinx/zuul.py View File

@@ -404,7 +404,7 @@ class ZuulVarDirective(ZuulObjectDescription):
404 404
     }
405 405
 
406 406
     def get_type_str(self):
407
-        if 'type' in self.options:
407
+        if 'type' in self.options and self.options['type'] in self.type_map:
408 408
             return self.type_map[self.options['type']]
409 409
         return ''
410 410
 
@@ -443,6 +443,12 @@ class ZuulVarDirective(ZuulObjectDescription):
443 443
             line += nodes.literal(self.options['default'],
444 444
                                   self.options['default'])
445 445
             signode += line
446
+        if 'type' in self.options:
447
+            line = addnodes.desc_signature_line()
448
+            line += addnodes.desc_type('Type: ', 'Type: ')
449
+            line += nodes.emphasis(self.options['type'],
450
+                                   self.options['type'])
451
+            signode += line
446 452
         return sig
447 453
 
448 454
 

Loading…
Cancel
Save