summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoland Meister <Roland Meister@localhost>2013-03-06 18:43:21 +0100
committerRoland Meister <Roland Meister@localhost>2013-03-06 18:43:21 +0100
commita567d77e516c559e8fbfa00ff42fe7233e68ffcc (patch)
tree3b731c5d31a7f1e708a43744d639fd4868538212
parent35c44b63fb3598e49f347faa8717dfa3617c85ec (diff)
downloadsphinx-git-a567d77e516c559e8fbfa00ff42fe7233e68ffcc.tar.gz
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.
-rw-r--r--doc/conf.py1
-rw-r--r--doc/config.rst5
-rw-r--r--sphinx/builders/__init__.py15
-rw-r--r--sphinx/builders/epub.py2
-rw-r--r--sphinx/builders/html.py4
-rw-r--r--sphinx/config.py1
-rw-r--r--sphinx/quickstart.py3
7 files changed, 28 insertions, 3 deletions
diff --git a/doc/conf.py b/doc/conf.py
index ef3ff68d7..8dc1e2fb1 100644
--- a/doc/conf.py
+++ b/doc/conf.py
@@ -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)]
diff --git a/doc/config.rst b/doc/config.rst
index b74be3206..92b53c058 100644
--- a/doc/config.rst
+++ b/doc/config.rst
@@ -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:
diff --git a/sphinx/builders/__init__.py b/sphinx/builders/__init__.py
index 97932c4c7..58c338a0b 100644
--- a/sphinx/builders/__init__.py
+++ b/sphinx/builders/__init__.py
@@ -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'),
diff --git a/sphinx/builders/epub.py b/sphinx/builders/epub.py
index 6803753bf..389f29a4d 100644
--- a/sphinx/builders/epub.py
+++ b/sphinx/builders/epub.py
@@ -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))
})
diff --git a/sphinx/builders/html.py b/sphinx/builders/html.py
index 1d1dfa799..198824ee2 100644
--- a/sphinx/builders/html.py
+++ b/sphinx/builders/html.py
@@ -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
diff --git a/sphinx/config.py b/sphinx/config.py
index 2e548986d..496ce77f0 100644
--- a/sphinx/config.py
+++ b/sphinx/config.py
@@ -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,
diff --git a/sphinx/quickstart.py b/sphinx/quickstart.py
index 2184ba619..bfc6d723b 100644
--- a/sphinx/quickstart.py
+++ b/sphinx/quickstart.py
@@ -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'''