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 #17 from ericholscher/jinhwa_dev
Browse files Browse the repository at this point in the history
refactor & cleanup
  • Loading branch information
bianliu1013 committed May 18, 2017
2 parents a5e957e + 0cd6f98 commit 1f147e0
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 27 deletions.
25 changes: 5 additions & 20 deletions docfx_yaml/extension.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,6 @@
EXCEPTION = 'exception'
ATTRIBUTE = 'attribute'

# We need to map the Python type names to what DocFX is expecting
TYPE_MAPPING = {
METHOD: 'Method',
FUNCTION: 'Method',
MODULE: 'Namespace',
CLASS: 'Class',
EXCEPTION: 'Class', # Hack this for now
ATTRIBUTE: 'Property', # Ditto
}


def build_init(app):
"""
Expand Down Expand Up @@ -117,11 +107,6 @@ def _create_datam(app, cls, module, name, _type, obj, lines=None):
"""
Build the data structure for an autodoc class
"""
try:
mapped_type = TYPE_MAPPING[_type]
except TypeError:
print('Invalid Type Mapping: %s' % _type)
mapped_type = _type

if lines is None:
lines = []
Expand Down Expand Up @@ -164,8 +149,7 @@ def _create_datam(app, cls, module, name, _type, obj, lines=None):
datam = {
'module': module,
'uid': name,
'type': mapped_type,
'_type': _type,
'type': _type,
'name': short_name,
'fullName': name,
'source': {
Expand Down Expand Up @@ -269,15 +253,15 @@ def insert_children_on_module(app, _type, datam):
for obj in insert_module:
# Add standardlone function to global class
if _type in [FUNCTION] and \
obj['_type'] == MODULE and \
obj['type'] == MODULE and \
obj[MODULE] == datam[MODULE]:
obj['children'].append(datam['uid'])
insert_module.append(datam)
obj['references'].append(_create_reference(datam, parent=obj['uid']))
break
# Add classes & exceptions to module
if _type in [CLASS, EXCEPTION] and \
obj['_type'] == MODULE and \
obj['type'] == MODULE and \
obj[MODULE] == datam[MODULE]:
obj['children'].append(datam['uid'])
obj['references'].append(_create_reference(datam, parent=obj['uid']))
Expand All @@ -294,7 +278,7 @@ def insert_children_on_class(app, _type, datam):
insert_class = app.env.docfx_yaml_classes[datam[CLASS]]
# Find the class which the datam belongs to
for obj in insert_class:
if obj['_type'] != CLASS:
if obj['type'] != CLASS:
continue
# Add methods & attributes to class
if _type in [METHOD, ATTRIBUTE] and \
Expand Down Expand Up @@ -358,6 +342,7 @@ def build_finished(app, exception):
# Raise up seealso
if 'seealso' in obj['syntax'] and obj['syntax']['seealso']:
obj['seealsoContent'] = obj['syntax'].pop('seealso')

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

Expand Down
6 changes: 2 additions & 4 deletions docfx_yaml/extract_nodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ def extract_yaml(app, doctree, ignore_patterns):
'module': str(module),
'uid': str(module),
'type': 'Namespace',
'_type': 'module',
'type': 'module',
'name': str(module),
'children': []
}]
Expand All @@ -138,12 +138,10 @@ def extract_yaml(app, doctree, ignore_patterns):
if args:
full_name += "({args})".format(args=', '.join(args))

# We need to map the Python type names to what DocFX is expecting

datam = {
'module': str(module),
'uid': uid,
'_type': _type,
'type': _type,
'name': name,
'fullName': full_name,
'summary': summary,
Expand Down
5 changes: 4 additions & 1 deletion docfx_yaml/monkeypatch.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,10 @@ def transform_all(self, node):
data['example'] = transform_node(child_copy)
else:
content = transform_node(child)
summary.append(content)

# skip 'Bases' in summary
if not content.startswith('Bases: '):
summary.append(content)
if summary:
data['summary'] = '\n'.join(summary)
# Don't include empty data
Expand Down
4 changes: 2 additions & 2 deletions tests/test_yaml.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ def test_napoleon(self):
)
self.assertEqual(
item['seealsoContent'],
'See also: Some cool stuff online.'
'Some cool stuff online.'
)

def test_xref(self):
Expand All @@ -187,7 +187,7 @@ def test_xref(self):
if item['uid'] == 'example.nap.Base.ref':
self.assertEqual(
item['seealsoContent'],
'See also: Depends on @example.example.Foo Relative reference on @example.nap.Base.foo'
'Depends on @example.example.Foo Relative reference on @example.nap.Base.foo'
)

def test_toc(self):
Expand Down

0 comments on commit 1f147e0

Please sign in to comment.