diff --git a/sphinx/application.py b/sphinx/application.py index cd9baf9c0..7d4e3cac8 100644 --- a/sphinx/application.py +++ b/sphinx/application.py @@ -405,6 +405,13 @@ class Sphinx(object): raise ExtensionError('domain %s not yet registered' % domain) self.domains[domain].roles[name] = role + # XXX needs documentation + def add_index_to_domain(self, domain, name, localname, shortname, func): + if domain not in self.domains: + raise ExtensionError('domain %s not yet registered' % domain) + self.domains[domain].indices.append((name, longname, shortname)) + setattr(self.domains[domain], '_get_%s_index' % name, func) + def add_object_type(self, directivename, rolename, indextemplate='', parse_node=None, ref_nodeclass=None, objname=''): StandardDomain.object_types[directivename] = \ diff --git a/sphinx/builders/html.py b/sphinx/builders/html.py index 6dcdc27ec..cc3a56289 100644 --- a/sphinx/builders/html.py +++ b/sphinx/builders/html.py @@ -273,7 +273,8 @@ class StandaloneHTMLBuilder(Builder): if self.config.html_use_index: rellinks.append(('genindex', _('General Index'), 'I', _('index'))) for index in self.domain_indices: - rellinks.append(('%s-%s' % index[0:2], index[2], '', index[3])) + if index[3]: + rellinks.append(('%s-%s' % index[0:2], index[2], '', index[3])) if self.config.html_style is not None: stylename = self.config.html_style diff --git a/sphinx/domains/__init__.py b/sphinx/domains/__init__.py index b67d090c3..a03a74db5 100644 --- a/sphinx/domains/__init__.py +++ b/sphinx/domains/__init__.py @@ -181,8 +181,14 @@ class Domain(object): """ Return True if there are entries for the index given by *name*. If *docnames* is given, restrict to entries referring to these docnames. + + Do not overwrite this method, add a method ``has__entries(self, + docnames=None)`` method for every index. """ - return False + func = getattr(self, 'has_%s_entries' % name, None) + if not func: + return bool(self.get_index(name, docnames)) + return func(docnames) def get_index(self, name, docnames=None): """ @@ -212,8 +218,14 @@ class Domain(object): - `descr` -- description for the entry Qualifier and description are not rendered e.g. in LaTeX output. + + Do not overwrite this method, add a method ``get__index(self, + docnames=None)`` method for every index. """ - return [], False + func = getattr(self, 'get_%s_index' % name, None) + if not func: + return [] + return func(docnames) from sphinx.domains.c import CDomain diff --git a/sphinx/domains/python.py b/sphinx/domains/python.py index fcd2216db..1678929c5 100644 --- a/sphinx/domains/python.py +++ b/sphinx/domains/python.py @@ -459,7 +459,7 @@ class PythonDomain(Domain): 'modules': {}, # modname -> docname, synopsis, platform, deprecated } indices = [ - ('modindex', l_('Global Module Index'), l_('modules')), + ('modindex', l_('Python Module Index'), l_('modules')), ] def clear_doc(self, docname): @@ -545,9 +545,7 @@ class PythonDomain(Domain): for refname, (docname, type) in self.data['objects'].iteritems(): yield (refname, type, docname, refname, 1) - def has_index_entries(self, name, docnames=None): - if name != 'modindex': - return False + def has_modindex_entries(self, docnames=None): if not docnames: return bool(self.data['modules']) else: @@ -556,10 +554,7 @@ class PythonDomain(Domain): return True return False - def get_index(self, name, docnames=None): - if name != 'modindex': - return None, None - + def get_modindex_index(self, docnames=None): content = {} # list of prefixes to ignore ignores = self.env.config['modindex_common_prefix']