Skip to content
This repository has been archived by the owner on Feb 28, 2022. It is now read-only.

Commit

Permalink
Merge pull request #38 from ericholscher/jinhwa/support_enum
Browse files Browse the repository at this point in the history
add enum desc to summary (temp solution, need refine in future)
  • Loading branch information
bianliu1013 committed Jun 12, 2017
2 parents 06cdbf0 + a7b0ffe commit 0155d5b
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
6 changes: 6 additions & 0 deletions docfx_yaml/extension.py
Original file line number Diff line number Diff line change
Expand Up @@ -460,6 +460,12 @@ def convert_module_to_package_if_needed(obj):
if 'example' in obj['syntax'] and obj['syntax']['example']:
obj.setdefault('example', []).append(obj['syntax'].pop('example'))

# append 'enum_attribute' to summary
if 'enum_attribute' in obj['syntax'] and obj['syntax']['enum_attribute']:
enum_attribute = obj['syntax'].pop('enum_attribute')
if 'summary' in obj:
obj['summary'] += ('\n\n' + '\n\n'.join(enum_attribute) + '\n')

if 'references' in obj:
references.extend(obj.pop('references'))

Expand Down
14 changes: 14 additions & 0 deletions docfx_yaml/monkeypatch.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from sphinx import directives, addnodes
from sphinx import addnodes

from sphinx.addnodes import desc, desc_signature
from .utils import transform_node as _transform_node


Expand All @@ -26,6 +27,14 @@ def _get_desc_data(node):
return full_name, uid


def _is_desc_of_enum_class(node):
assert node.tagname == 'desc_content'
if node[0] and node[0].tagname == 'paragraph' and node[0].astext() == 'Bases: enum.Enum':
return True

return False


def _hacked_transform(typemap, node):
"""
Taken from docfields.py from sphinx.
Expand Down Expand Up @@ -208,6 +217,11 @@ def transform_all(self, node):
name, uid = _get_desc_data(node.parent)
for child in node:
if isinstance(child, addnodes.desc):
if _is_desc_of_enum_class(node):
for item in child:
if isinstance(item, desc_signature):
data.setdefault('enum_attribute', []).append(item.astext())

# Don't recurse into child nodes
continue
elif isinstance(child, nodes.field_list):
Expand Down

0 comments on commit 0155d5b

Please sign in to comment.