mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
Add method for adding custom indexes.
This commit is contained in:
@@ -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] = \
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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_<name>_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_<name>_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
|
||||
|
||||
@@ -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']
|
||||
|
||||
Reference in New Issue
Block a user