From 6a0034ebcabc86ec60f8fbb96303840e6b503a2e Mon Sep 17 00:00:00 2001 From: Ian Wienand Date: Wed, 6 Mar 2019 11:11:46 +1100 Subject: [PATCH] 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 --- doc/source/example-roles.rst | 15 +++++++++++++++ zuul_sphinx/zuul.py | 8 +++++++- 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/doc/source/example-roles.rst b/doc/source/example-roles.rst index b32022e..afa9539 100644 --- a/doc/source/example-roles.rst +++ b/doc/source/example-roles.rst @@ -25,6 +25,21 @@ Roles 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 variable (Sphinx) role: :rolevar:`example.items.baz` diff --git a/zuul_sphinx/zuul.py b/zuul_sphinx/zuul.py index 37a6bd3..32b5e0c 100644 --- a/zuul_sphinx/zuul.py +++ b/zuul_sphinx/zuul.py @@ -404,7 +404,7 @@ class ZuulVarDirective(ZuulObjectDescription): } 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 '' @@ -443,6 +443,12 @@ class ZuulVarDirective(ZuulObjectDescription): line += nodes.literal(self.options['default'], self.options['default']) 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