mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
Add -A option to pass values into HTML templates.
This commit is contained in:
parent
e666b6d203
commit
a6f09758e3
@ -39,6 +39,7 @@ Options: -b <builder> -- builder to use; default is html
|
|||||||
-c <path> -- path where configuration file (conf.py) is located
|
-c <path> -- path where configuration file (conf.py) is located
|
||||||
(default: same as sourcedir)
|
(default: same as sourcedir)
|
||||||
-D <setting=value> -- override a setting in configuration
|
-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
|
-N -- do not do colored output
|
||||||
-q -- no output on stdout, just warnings on stderr
|
-q -- no output on stdout, just warnings on stderr
|
||||||
-P -- run Pdb on exception
|
-P -- run Pdb on exception
|
||||||
@ -59,7 +60,7 @@ def main(argv=sys.argv):
|
|||||||
nocolor()
|
nocolor()
|
||||||
|
|
||||||
try:
|
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])
|
srcdir = confdir = path.abspath(args[0])
|
||||||
if not path.isdir(srcdir):
|
if not path.isdir(srcdir):
|
||||||
print >>sys.stderr, 'Error: Cannot find source directory.'
|
print >>sys.stderr, 'Error: Cannot find source directory.'
|
||||||
@ -89,6 +90,7 @@ def main(argv=sys.argv):
|
|||||||
freshenv = use_pdb = False
|
freshenv = use_pdb = False
|
||||||
status = sys.stdout
|
status = sys.stdout
|
||||||
confoverrides = {}
|
confoverrides = {}
|
||||||
|
htmlcontext = {}
|
||||||
doctreedir = path.join(outdir, '.doctrees')
|
doctreedir = path.join(outdir, '.doctrees')
|
||||||
for opt, val in opts:
|
for opt, val in opts:
|
||||||
if opt == '-b':
|
if opt == '-b':
|
||||||
@ -107,12 +109,29 @@ def main(argv=sys.argv):
|
|||||||
'Error: Configuration directory doesn\'t contain conf.py file.'
|
'Error: Configuration directory doesn\'t contain conf.py file.'
|
||||||
return 1
|
return 1
|
||||||
elif opt == '-D':
|
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:
|
try:
|
||||||
val = int(val)
|
val = int(val)
|
||||||
except ValueError:
|
except ValueError:
|
||||||
pass
|
pass
|
||||||
confoverrides[key] = val
|
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':
|
elif opt == '-N':
|
||||||
nocolor()
|
nocolor()
|
||||||
elif opt == '-E':
|
elif opt == '-E':
|
||||||
@ -121,6 +140,7 @@ def main(argv=sys.argv):
|
|||||||
status = StringIO()
|
status = StringIO()
|
||||||
elif opt == '-P':
|
elif opt == '-P':
|
||||||
use_pdb = True
|
use_pdb = True
|
||||||
|
confoverrides['html_context'] = htmlcontext
|
||||||
|
|
||||||
try:
|
try:
|
||||||
app = Sphinx(srcdir, confdir, outdir, doctreedir, buildername,
|
app = Sphinx(srcdir, confdir, outdir, doctreedir, buildername,
|
||||||
|
@ -449,6 +449,7 @@ class StandaloneHTMLBuilder(Builder):
|
|||||||
logo = logo,
|
logo = logo,
|
||||||
favicon = favicon,
|
favicon = favicon,
|
||||||
)
|
)
|
||||||
|
self.globalcontext.update(self.config.html_context)
|
||||||
|
|
||||||
def get_doc_context(self, docname, body, metatags):
|
def get_doc_context(self, docname, body, metatags):
|
||||||
"""Collect items for the template context of a page."""
|
"""Collect items for the template context of a page."""
|
||||||
|
@ -71,6 +71,7 @@ class Config(object):
|
|||||||
html_use_opensearch = ('', False),
|
html_use_opensearch = ('', False),
|
||||||
html_file_suffix = (None, False),
|
html_file_suffix = (None, False),
|
||||||
html_show_sphinx = (True, False),
|
html_show_sphinx = (True, False),
|
||||||
|
html_context = ({}, False),
|
||||||
|
|
||||||
# HTML help only options
|
# HTML help only options
|
||||||
htmlhelp_basename = ('pydoc', False),
|
htmlhelp_basename = ('pydoc', False),
|
||||||
|
4
tests/root/_templates/layout.html
Normal file
4
tests/root/_templates/layout.html
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
{% extends "!layout.html" %}
|
||||||
|
{% block extrahead %}
|
||||||
|
<meta name="hc" content="{{ hckey }}" />
|
||||||
|
{% endblock %}
|
@ -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").
|
# If nonempty, this is the file name suffix for HTML files (e.g. ".xhtml").
|
||||||
#html_file_suffix = ''
|
#html_file_suffix = ''
|
||||||
|
|
||||||
|
html_context = {'hckey': 'hcval'}
|
||||||
|
|
||||||
# Output file base name for HTML help builder.
|
# Output file base name for HTML help builder.
|
||||||
htmlhelp_basename = 'SphinxTestsdoc'
|
htmlhelp_basename = 'SphinxTestsdoc'
|
||||||
|
|
||||||
|
@ -67,6 +67,7 @@ HTML_XPATH = {
|
|||||||
".//a[@href='#mod.Cls']": '',
|
".//a[@href='#mod.Cls']": '',
|
||||||
},
|
},
|
||||||
'contents.html': {
|
'contents.html': {
|
||||||
|
".//meta[@name='hc'][@content='hcval']": '',
|
||||||
".//td[@class='label']": '[Ref1]',
|
".//td[@class='label']": '[Ref1]',
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user