summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGeorg Brandl <georg@python.org>2008-11-04 08:34:35 +0100
committerGeorg Brandl <georg@python.org>2008-11-04 08:34:35 +0100
commita6f09758e3510dc7d685d78a456d28eefd565779 (patch)
tree668c9b00c1a94d77561b8d9a729f27be777d49a0
parente666b6d203c1b763535c6a29271d0141b72c5969 (diff)
downloadsphinx-git-a6f09758e3510dc7d685d78a456d28eefd565779.tar.gz
Add -A option to pass values into HTML templates.
-rw-r--r--sphinx/__init__.py24
-rw-r--r--sphinx/builder.py1
-rw-r--r--sphinx/config.py1
-rw-r--r--tests/root/_templates/layout.html4
-rw-r--r--tests/root/conf.py2
-rw-r--r--tests/test_build.py1
6 files changed, 31 insertions, 2 deletions
diff --git a/sphinx/__init__.py b/sphinx/__init__.py
index d53fdafd2..2af1de31a 100644
--- a/sphinx/__init__.py
+++ b/sphinx/__init__.py
@@ -39,6 +39,7 @@ Options: -b <builder> -- builder to use; default is html
-c <path> -- path where configuration file (conf.py) is located
(default: same as sourcedir)
-D <setting=value> -- override a setting in configuration
+ -A <name=value> -- pass a value into the templates, for HTML builder
-N -- do not do colored output
-q -- no output on stdout, just warnings on stderr
-P -- run Pdb on exception
@@ -59,7 +60,7 @@ def main(argv=sys.argv):
nocolor()
try:
- opts, args = getopt.getopt(argv[1:], 'ab:d:c:D:NEqP')
+ opts, args = getopt.getopt(argv[1:], 'ab:d:c:D:A:NEqP')
srcdir = confdir = path.abspath(args[0])
if not path.isdir(srcdir):
print >>sys.stderr, 'Error: Cannot find source directory.'
@@ -89,6 +90,7 @@ def main(argv=sys.argv):
freshenv = use_pdb = False
status = sys.stdout
confoverrides = {}
+ htmlcontext = {}
doctreedir = path.join(outdir, '.doctrees')
for opt, val in opts:
if opt == '-b':
@@ -107,12 +109,29 @@ def main(argv=sys.argv):
'Error: Configuration directory doesn\'t contain conf.py file.'
return 1
elif opt == '-D':
- key, val = val.split('=')
+ try:
+ key, val = val.split('=')
+ except ValueError:
+ print >>sys.stderr, \
+ 'Error: -D option argument must be in the form name=value.'
+ return 1
try:
val = int(val)
except ValueError:
pass
confoverrides[key] = val
+ elif opt == '-A':
+ try:
+ key, val = val.split('=')
+ except ValueError:
+ print >>sys.stderr, \
+ 'Error: -A option argument must be in the form name=value.'
+ return 1
+ try:
+ val = int(val)
+ except ValueError:
+ pass
+ htmlcontext[key] = val
elif opt == '-N':
nocolor()
elif opt == '-E':
@@ -121,6 +140,7 @@ def main(argv=sys.argv):
status = StringIO()
elif opt == '-P':
use_pdb = True
+ confoverrides['html_context'] = htmlcontext
try:
app = Sphinx(srcdir, confdir, outdir, doctreedir, buildername,
diff --git a/sphinx/builder.py b/sphinx/builder.py
index d466bd703..b3e36b455 100644
--- a/sphinx/builder.py
+++ b/sphinx/builder.py
@@ -449,6 +449,7 @@ class StandaloneHTMLBuilder(Builder):
logo = logo,
favicon = favicon,
)
+ self.globalcontext.update(self.config.html_context)
def get_doc_context(self, docname, body, metatags):
"""Collect items for the template context of a page."""
diff --git a/sphinx/config.py b/sphinx/config.py
index 3da2ad814..012668e79 100644
--- a/sphinx/config.py
+++ b/sphinx/config.py
@@ -71,6 +71,7 @@ class Config(object):
html_use_opensearch = ('', False),
html_file_suffix = (None, False),
html_show_sphinx = (True, False),
+ html_context = ({}, False),
# HTML help only options
htmlhelp_basename = ('pydoc', False),
diff --git a/tests/root/_templates/layout.html b/tests/root/_templates/layout.html
new file mode 100644
index 000000000..1f4688e60
--- /dev/null
+++ b/tests/root/_templates/layout.html
@@ -0,0 +1,4 @@
+{% extends "!layout.html" %}
+{% block extrahead %}
+<meta name="hc" content="{{ hckey }}" />
+{% endblock %}
diff --git a/tests/root/conf.py b/tests/root/conf.py
index f81422056..8d2b276f9 100644
--- a/tests/root/conf.py
+++ b/tests/root/conf.py
@@ -133,6 +133,8 @@ html_last_updated_fmt = '%b %d, %Y'
# If nonempty, this is the file name suffix for HTML files (e.g. ".xhtml").
#html_file_suffix = ''
+html_context = {'hckey': 'hcval'}
+
# Output file base name for HTML help builder.
htmlhelp_basename = 'SphinxTestsdoc'
diff --git a/tests/test_build.py b/tests/test_build.py
index a3d10df16..07a946964 100644
--- a/tests/test_build.py
+++ b/tests/test_build.py
@@ -67,6 +67,7 @@ HTML_XPATH = {
".//a[@href='#mod.Cls']": '',
},
'contents.html': {
+ ".//meta[@name='hc'][@content='hcval']": '',
".//td[@class='label']": '[Ref1]',
},
}