mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
epub_use_index instead of html_use_index for epub builder (Issue #1106)
The change adds the method get_builder_config. This allows use of the option epub_use_index instead of html_use_index for epub output.
This commit is contained in:
parent
35c44b63fb
commit
a567d77e51
@ -43,6 +43,7 @@ epub_exclude_files = ['_static/opensearch.xml', '_static/doctools.js',
|
||||
epub_fix_images = False
|
||||
epub_max_image_width = 0
|
||||
epub_show_urls = 'inline'
|
||||
epub_use_index = False
|
||||
|
||||
latex_documents = [('contents', 'sphinx.tex', 'Sphinx Documentation',
|
||||
'Georg Brandl', 'manual', 1)]
|
||||
|
@ -948,6 +948,11 @@ the `Dublin Core metadata <http://dublincore.org/>`_.
|
||||
|
||||
.. versionadded:: 1.2
|
||||
|
||||
.. confval:: epub_use_index
|
||||
|
||||
If true, add an index to the epub document. It defaults to the
|
||||
:confval:`html_use_index` option but can be set independently for epub
|
||||
creation.
|
||||
|
||||
.. _latex-options:
|
||||
|
||||
|
@ -318,6 +318,21 @@ class Builder(object):
|
||||
"""
|
||||
pass
|
||||
|
||||
def get_builder_config(self, option, default):
|
||||
"""Return a builder specific option.
|
||||
|
||||
This method allows customization of common builder settings by
|
||||
inserting the name of the current builder in the option key.
|
||||
If the key does not exist, use default as builder name.
|
||||
"""
|
||||
# At the moment, only XXX_use_index is looked up this way.
|
||||
# Every new builder variant must be registered in Config.config_values.
|
||||
try:
|
||||
optname = '%s_%s' % (self.name, option)
|
||||
return getattr(self.config, optname)
|
||||
except AttributeError:
|
||||
optname = '%s_%s' % (default, option)
|
||||
return getattr(self.config, optname)
|
||||
|
||||
BUILTIN_BUILDERS = {
|
||||
'html': ('html', 'StandaloneHTMLBuilder'),
|
||||
|
@ -489,7 +489,7 @@ class EpubBuilder(StandaloneHTMLBuilder):
|
||||
spine.append(_spine_template % {
|
||||
'idref': self.esc(self.make_id(info[0] + self.out_suffix))
|
||||
})
|
||||
if self.config.html_use_index:
|
||||
if self.get_builder_config('use_index', 'epub'):
|
||||
spine.append(_spine_template % {
|
||||
'idref': self.esc(self.make_id('genindex' + self.out_suffix))
|
||||
})
|
||||
|
@ -308,7 +308,7 @@ class StandaloneHTMLBuilder(Builder):
|
||||
self.relations = self.env.collect_relations()
|
||||
|
||||
rellinks = []
|
||||
if self.config.html_use_index:
|
||||
if self.get_builder_config('use_index', 'html'):
|
||||
rellinks.append(('genindex', _('General Index'), 'I', _('index')))
|
||||
for indexname, indexcls, content, collapse in self.domain_indices:
|
||||
# if it has a short name
|
||||
@ -451,7 +451,7 @@ class StandaloneHTMLBuilder(Builder):
|
||||
self.handle_page(pagename, context, template)
|
||||
|
||||
# the global general index
|
||||
if self.config.html_use_index:
|
||||
if self.get_builder_config('use_index', 'html'):
|
||||
self.write_genindex()
|
||||
|
||||
# the global domain-specific indices
|
||||
|
@ -143,6 +143,7 @@ class Config(object):
|
||||
epub_fix_images = (False, 'env'),
|
||||
epub_max_image_width = (0, 'env'),
|
||||
epub_show_urls = ('inline', 'html'),
|
||||
epub_use_index = (lambda self: self.html_use_index, 'html'),
|
||||
|
||||
# LaTeX options
|
||||
latex_documents = (lambda self: [(self.master_doc,
|
||||
|
@ -343,6 +343,9 @@ epub_copyright = u'%(copyright_str)s'
|
||||
|
||||
# If 'no', URL addresses will not be shown.
|
||||
#epub_show_urls = 'inline'
|
||||
|
||||
# If false, no index is generated.
|
||||
#epub_use_index = True
|
||||
'''
|
||||
|
||||
INTERSPHINX_CONFIG = u'''
|
||||
|
Loading…
Reference in New Issue
Block a user