Skip to content

Commit

Permalink
Refactor autodoc so that it gets easy to add support for custom types…
Browse files Browse the repository at this point in the history
… of objects.
  • Loading branch information
birkenfeld committed Feb 17, 2009
1 parent 82842e8 commit f2f6250
Show file tree
Hide file tree
Showing 3 changed files with 775 additions and 485 deletions.
22 changes: 17 additions & 5 deletions sphinx/application.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ def __str__(self):
from sphinx.directives import desc_directive, target_directive, \
additional_xref_types
from sphinx.environment import SphinxStandaloneReader
from sphinx.util.compat import Directive, directive_dwim
from sphinx.util.console import bold


Expand Down Expand Up @@ -282,11 +283,17 @@ def add_node(self, node, **kwds):
if depart:
setattr(translator, 'depart_'+node.__name__, depart)

def add_directive(self, name, func, content, arguments, **options):
func.content = content
func.arguments = arguments
func.options = options
directives.register_directive(name, func)
def add_directive(self, name, obj, content=None, arguments=None, **options):
if isinstance(obj, Directive):
if content or arguments or options:
raise ExtensionError('when adding directive classes, no '
'additional arguments may be given')
directives.register_directive(name, directive_dwim(obj))
else:
obj.content = content
obj.arguments = arguments
obj.options = options
directives.register_directive(name, obj)

def add_role(self, name, role):
roles.register_canonical_role(name, role)
Expand Down Expand Up @@ -325,6 +332,11 @@ def add_lexer(self, alias, lexer):
return
lexers[alias] = lexer

def add_autodocumenter(self, cls):
from sphinx.ext import autodoc
autodoc.add_documenter(cls)
self.add_directive('auto' + cls.objtype, autodoc.AutoDirective)


class TemplateBridge(object):
"""
Expand Down
Loading

0 comments on commit f2f6250

Please sign in to comment.