Skip to content

Commit 8b09d9e

Browse files
authored
Merge pull request #951 from sphinx-contrib/simplify-autodocs-in-v2
translator: simplify v2 autodocs renderings
2 parents c01af01 + d0460de commit 8b09d9e

File tree

8 files changed

+145
-28
lines changed

8 files changed

+145
-28
lines changed

sphinxcontrib/confluencebuilder/storage/translator.py

Lines changed: 8 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -575,32 +575,16 @@ def depart_field_list(self, node):
575575
self.body.append(self.context.pop()) # table
576576

577577
def visit_field(self, node):
578-
if self.v2:
579-
self.body.append(self._start_tag(node, 'ac:layout'))
580-
self.context.append(self._end_tag(node, suffix=''))
581-
582-
self.body.append(self._start_tag(node, 'ac:layout-section',
583-
**{
584-
'ac:type': 'two_left_sidebar',
585-
'ac:breakout-mode': 'default',
586-
}))
587-
self.context.append(self._end_tag(node))
588-
else:
578+
if not self.v2:
589579
self.body.append(self._start_tag(node, 'tr', suffix=self.nl))
590580
self.context.append(self._end_tag(node))
591581

592582
def depart_field(self, node):
593-
if self.v2:
594-
self.body.append(self.context.pop()) # ac:layout-section
595-
self.body.append(self.context.pop()) # ac:layout
596-
else:
583+
if not self.v2:
597584
self.body.append(self.context.pop()) # tr
598585

599586
def visit_field_name(self, node):
600-
if self.v2:
601-
self.body.append(self._start_tag(node, 'ac:layout-cell'))
602-
self.context.append(self._end_tag(node))
603-
else:
587+
if not self.v2:
604588
self.body.append(self._start_tag(node, 'td',
605589
**{'style': 'border: none'}))
606590
self.context.append(self._end_tag(node))
@@ -612,22 +596,18 @@ def depart_field_name(self, node):
612596
self.body.append(':')
613597
self.body.append(self.context.pop()) # strong
614598

615-
if self.v2:
616-
self.body.append(self.context.pop()) # ac:layout-cell
617-
else:
599+
if not self.v2:
618600
self.body.append(self.context.pop()) # td
619601

620602
def visit_field_body(self, node):
621-
if self.v2:
622-
self.body.append(self._start_tag(node, 'ac:layout-cell'))
623-
else:
603+
if not self.v2:
624604
self.body.append(self._start_tag(node, 'td',
625605
**{'style': 'border: none'}))
626-
627-
self.context.append(self._end_tag(node))
606+
self.context.append(self._end_tag(node))
628607

629608
def depart_field_body(self, node):
630-
self.body.append(self.context.pop()) # td/ac:layout-cell
609+
if not self.v2:
610+
self.body.append(self.context.pop()) # td
631611

632612
# -----------------------------
633613
# body elements -- option lists
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
sphinx.ext.autodocs
2+
===================
3+
4+
This page shows an example of various autodoc capabilities.
5+
6+
autodocs - automodule
7+
---------------------
8+
9+
The automodule directive:
10+
11+
.. automodule:: Hello
12+
:members:
13+
14+
----
15+
16+
The autoclass directive:
17+
18+
.. autoclass:: Hello
19+
:members: say_hello
20+
:noindex:
21+
22+
.. method:: foo(arg1, arg2)
23+
:noindex:
24+
25+
An overwritten description of the method ``foo``.
26+
27+
----
28+
29+
The autofunction directive:
30+
31+
.. currentmodule:: func
32+
33+
.. autofunction:: my_custom_function
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
sphinx.ext.autosummary
2+
======================
3+
4+
An example of a local docstring:
5+
6+
.. autosummary::
7+
8+
Hello
9+
10+
An example of an external module docstring:
11+
12+
.. currentmodule:: sphinx
13+
14+
.. autosummary::
15+
16+
environment.BuildEnvironment
17+
util.relative_uri

tests/sample-sets/autodocs/conf.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
from pathlib import Path
2+
import sys
3+
4+
5+
extensions = [
6+
'sphinx.ext.autodoc',
7+
'sphinx.ext.autosummary',
8+
'sphinxcontrib.confluencebuilder',
9+
]
10+
11+
12+
test_dir = Path(__file__).parent.resolve()
13+
src_dir = test_dir / 'src'
14+
sys.path.insert(0, str(src_dir))
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
Autodocs
2+
========
3+
4+
.. toctree::
5+
:maxdepth: 1
6+
7+
autodocs
8+
autosummary
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
"""
2+
This is a module docstring
3+
"""
4+
5+
6+
class Hello:
7+
"""
8+
This is a Hello class docstring
9+
"""
10+
11+
def __init__(self, name, name2):
12+
"""
13+
This is an __init__ method docstring.
14+
Creates a new :class:`Hello` instance.
15+
:param name: name for the hello
16+
:param name2: name2 for the hello
17+
:param name3: name3 for the hello
18+
:type name: str
19+
"""
20+
self.name = name
21+
22+
def say_hello(self):
23+
"""
24+
This is a say_hello method decorator
25+
"""
26+
print('Hello %s' % self.name)
27+
28+
def foo(self, arg1, arg2):
29+
"""
30+
A method's docstring with parameters and return value.
31+
32+
Use all the cool Sphinx capabilities in this description, e.g. to give
33+
usage examples ...
34+
35+
:Example:
36+
37+
>>> another_class.foo('', AClass())
38+
39+
:param arg1: first argument
40+
:type arg1: string
41+
:param arg2: second argument
42+
:type arg2: :class:`module.AClass`
43+
:return: something
44+
:rtype: string
45+
:raises: TypeError
46+
"""
47+
return '' + 1
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
2+
def my_custom_function(obj):
3+
"""
4+
A function's docstring with a parameter.
5+
6+
:param obj: the function argument
7+
"""

tests/sample-sets/autodocs/tox.ini

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
[tox]
2+
package_root={toxinidir}{/}..{/}..{/}..
3+
4+
[testenv]
5+
commands =
6+
{envpython} -m tests.test_sample {posargs}
7+
setenv =
8+
PYTHONDONTWRITEBYTECODE=1
9+
TOX_INI_DIR={toxinidir}
10+
passenv = *
11+
use_develop = true

0 commit comments

Comments
 (0)