diff options
author | Stephen Finucane <sfinucan@redhat.com> | 2017-07-05 10:58:50 +0100 |
---|---|---|
committer | Stephen Finucane <sfinucan@redhat.com> | 2017-07-05 11:05:23 +0100 |
commit | 9697fede88b629e6865b21a7671bc04febb2ef15 (patch) | |
tree | bd8a450daedc9b3d50736eae1c4018797757d925 | |
parent | b6aaf0094af305d80080f2b8befb10aeabbe0c07 (diff) | |
download | oslo-policy-9697fede88b629e6865b21a7671bc04febb2ef15.tar.gz |
sphinxext: Use field lists in output
The 'sphinxext' module provided by 'oslo.config' uses field lists [1] for
its defaults. Provide some cross-promotional, deal mechanics, revenue
streams, jargon synergy between these two plugins (i.e. make them look
similar).
This message was approved by Jack Donaghy [2].
[1] http://docutils.sourceforge.net/docs/user/rst/quickref.html#field-lists
[2] https://youtu.be/aocZo3oeNxw
Change-Id: I6e478152a278a877ae37588be930b0b833eb09cd
-rw-r--r-- | oslo_policy/sphinxext.py | 36 | ||||
-rw-r--r-- | oslo_policy/tests/test_sphinxext.py | 24 |
2 files changed, 24 insertions, 36 deletions
diff --git a/oslo_policy/sphinxext.py b/oslo_policy/sphinxext.py index f685640..e3d7e1e 100644 --- a/oslo_policy/sphinxext.py +++ b/oslo_policy/sphinxext.py @@ -43,37 +43,31 @@ def _format_policy_rule(rule): For example: ``os_compute_api:servers:create`` - Create a server + :Default: ``rule:admin_or_owner`` + :Operations: + - **POST** ``/servers`` - Default:: + Create a server + """ + yield '``{}``'.format(rule.name) - rule:admin_or_owner + yield _indent(':Default: ``{}``'.format(rule.check_str)) - Operations: + if hasattr(rule, 'operations'): + yield _indent(':Operations:') + for operation in rule.operations: + yield _indent(_indent('- **{}** ``{}``'.format( + operation['method'], operation['path']))) - - **POST** ``/servers`` - """ - yield '``{}``'.format(rule.name) + yield '' if rule.description: for line in statemachine.string2lines( rule.description, tab_width=4, convert_whitespace=True): if line: yield _indent(line) - - yield '' - - yield _indent('Default::') - yield '' - yield _indent(_indent(rule.check_str)) - - if hasattr(rule, 'operations'): - yield '' - yield _indent('Operations:') - yield '' - for operation in rule.operations: - yield _indent('- **{}** ``{}``'.format(operation['method'], - operation['path'])) + else: + yield _indent('(no description provided)') yield '' diff --git a/oslo_policy/tests/test_sphinxext.py b/oslo_policy/tests/test_sphinxext.py index 101eae3..7834b35 100644 --- a/oslo_policy/tests/test_sphinxext.py +++ b/oslo_policy/tests/test_sphinxext.py @@ -31,9 +31,9 @@ class FormatPolicyTest(base.BaseTestCase): === ``rule_a`` - Default:: + :Default: ``@`` - @ + (no description provided) """).lstrip(), results) def test_with_description(self): @@ -46,11 +46,9 @@ class FormatPolicyTest(base.BaseTestCase): === ``rule_a`` - My sample rule - - Default:: + :Default: ``@`` - @ + My sample rule """).lstrip(), results) def test_with_operations(self): @@ -66,14 +64,10 @@ class FormatPolicyTest(base.BaseTestCase): === ``rule_a`` - My sample rule + :Default: ``@`` + :Operations: + - **GET** ``/foo`` + - **POST** ``/some`` - Default:: - - @ - - Operations: - - - **GET** ``/foo`` - - **POST** ``/some`` + My sample rule """).lstrip(), results) |