diff --git a/sphinx/application.py b/sphinx/application.py index 7d9ee49db..c9dac9817 100644 --- a/sphinx/application.py +++ b/sphinx/application.py @@ -334,17 +334,21 @@ class Sphinx(object): if depart: setattr(translator, 'depart_'+node.__name__, depart) - def add_directive(self, name, obj, content=None, arguments=None, **options): + def _directive_helper(self, obj, content=None, arguments=None, **options): if isinstance(obj, clstypes) and issubclass(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)) + return directive_dwim(obj) else: obj.content = content obj.arguments = arguments obj.options = options - directives.register_directive(name, obj) + return obj + + def add_directive(self, name, obj, content=None, arguments=None, **options): + directives.register_directive( + name, self._directive_helper(obj, content, arguments, **options)) def add_role(self, name, role): roles.register_local_role(name, role) @@ -356,10 +360,23 @@ class Sphinx(object): roles.register_local_role(name, role) def add_domain(self, domain): + # XXX needs to be documented if domain.name in all_domains: raise ExtensionError('domain %s already registered' % domain.name) all_domains[domain.name] = domain + def add_directive_to_domain(self, domain, name, obj): + # XXX needs to be documented + if domain not in all_domains: + raise ExtensionError('domain %s not yet registered' % domain) + all_domains[domain].directives[name] = self._directive_helper(obj) + + def add_role_to_domain(self, domain, name, role): + # XXX needs to be documented + if domain not in all_domains: + raise ExtensionError('domain %s not yet registered' % domain) + all_domains[domain].roles[name] = role + def add_description_unit(self, directivename, rolename, indextemplate='', parse_node=None, ref_nodeclass=None): additional_xref_types[directivename] = (rolename, indextemplate, diff --git a/sphinx/environment.py b/sphinx/environment.py index 2f64b147b..9cd7fc2a2 100644 --- a/sphinx/environment.py +++ b/sphinx/environment.py @@ -319,6 +319,7 @@ class BuildEnvironment: # These are set while parsing a file self.docname = None # current document name + # XXX remove currmodule and currclass from here self.currmodule = None # current module name self.currclass = None # current class name self.currdesc = None # current descref name