mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
* Add support for theme options.
* Make the right-/stickysidebar alternatives for the default design options. * Add theme-related options to quickstart.
This commit is contained in:
parent
2d62179bb0
commit
25b71e4143
4
doc/_templates/layout.html
vendored
4
doc/_templates/layout.html
vendored
@ -1,8 +1,8 @@
|
|||||||
{% extends "!layout.html" %}
|
{% extends "!layout.html" %}
|
||||||
|
|
||||||
{% block rootrellink %}
|
{% block rootrellink %}
|
||||||
<li><a href="{{ pathto('index') }}">Sphinx home </a> | </li>
|
<li><a href="{{ pathto('index') }}">Sphinx home</a> | </li>
|
||||||
<li><a href="{{ pathto('contents') }}">Documentation </a> »</li>
|
<li><a href="{{ pathto('contents') }}">Documentation</a> »</li>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
{% block header %}
|
{% block header %}
|
||||||
|
@ -179,6 +179,9 @@ class StandaloneHTMLBuilder(Builder):
|
|||||||
logo = logo,
|
logo = logo,
|
||||||
favicon = favicon,
|
favicon = favicon,
|
||||||
)
|
)
|
||||||
|
self.globalcontext.update(
|
||||||
|
('theme_' + key, val) for (key, val) in
|
||||||
|
self.theme.get_options(self.config.html_theme_options).iteritems())
|
||||||
self.globalcontext.update(self.config.html_context)
|
self.globalcontext.update(self.config.html_context)
|
||||||
|
|
||||||
def _get_local_toctree(self, docname):
|
def _get_local_toctree(self, docname):
|
||||||
|
@ -58,6 +58,7 @@ class Config(object):
|
|||||||
# HTML options
|
# HTML options
|
||||||
html_theme = ('default', False),
|
html_theme = ('default', False),
|
||||||
html_theme_path = ([], False),
|
html_theme_path = ([], False),
|
||||||
|
html_theme_options = ({}, False),
|
||||||
html_title = (lambda self: '%s v%s documentation' %
|
html_title = (lambda self: '%s v%s documentation' %
|
||||||
(self.project, self.release),
|
(self.project, self.release),
|
||||||
False),
|
False),
|
||||||
|
@ -18,6 +18,12 @@ from sphinx.util import mtimes_of_files
|
|||||||
from sphinx.application import TemplateBridge
|
from sphinx.application import TemplateBridge
|
||||||
|
|
||||||
|
|
||||||
|
def _tobool(val):
|
||||||
|
if isinstance(val, basestring):
|
||||||
|
return val.lower() in ('true', '1', 'yes', 'on')
|
||||||
|
return bool(val)
|
||||||
|
|
||||||
|
|
||||||
class BuiltinTemplateLoader(TemplateBridge, jinja2.BaseLoader):
|
class BuiltinTemplateLoader(TemplateBridge, jinja2.BaseLoader):
|
||||||
"""
|
"""
|
||||||
Interfaces the rendering environment of jinja2 for use in Sphinx.
|
Interfaces the rendering environment of jinja2 for use in Sphinx.
|
||||||
@ -38,6 +44,8 @@ class BuiltinTemplateLoader(TemplateBridge, jinja2.BaseLoader):
|
|||||||
chain[0:0] = [path.join(builder.confdir, tp)
|
chain[0:0] = [path.join(builder.confdir, tp)
|
||||||
for tp in builder.config.templates_path]
|
for tp in builder.config.templates_path]
|
||||||
|
|
||||||
|
self.pathchain = chain
|
||||||
|
|
||||||
# make the paths into loaders
|
# make the paths into loaders
|
||||||
self.loaders = map(jinja2.FileSystemLoader, chain)
|
self.loaders = map(jinja2.FileSystemLoader, chain)
|
||||||
|
|
||||||
@ -45,6 +53,7 @@ class BuiltinTemplateLoader(TemplateBridge, jinja2.BaseLoader):
|
|||||||
extensions = use_i18n and ['jinja2.ext.i18n'] or []
|
extensions = use_i18n and ['jinja2.ext.i18n'] or []
|
||||||
self.environment = jinja2.Environment(loader=self,
|
self.environment = jinja2.Environment(loader=self,
|
||||||
extensions=extensions)
|
extensions=extensions)
|
||||||
|
self.environment.filters['tobool'] = _tobool
|
||||||
if use_i18n:
|
if use_i18n:
|
||||||
self.environment.install_gettext_translations(builder.translator)
|
self.environment.install_gettext_translations(builder.translator)
|
||||||
|
|
||||||
@ -52,7 +61,7 @@ class BuiltinTemplateLoader(TemplateBridge, jinja2.BaseLoader):
|
|||||||
return self.environment.get_template(template).render(context)
|
return self.environment.get_template(template).render(context)
|
||||||
|
|
||||||
def newest_template_mtime(self):
|
def newest_template_mtime(self):
|
||||||
return max(mtimes_of_files(self.theme.get_dirchain(), '.html'))
|
return max(mtimes_of_files(self.pathchain, '.html'))
|
||||||
|
|
||||||
# Loader interface
|
# Loader interface
|
||||||
|
|
||||||
|
@ -114,10 +114,17 @@ pygments_style = 'sphinx'
|
|||||||
|
|
||||||
# -- Options for HTML output ---------------------------------------------------
|
# -- Options for HTML output ---------------------------------------------------
|
||||||
|
|
||||||
# The style sheet to use for HTML and HTML Help pages. A file of that name
|
# The theme to use for HTML and HTML Help pages. Major themes that come with
|
||||||
# must exist either in Sphinx' static/ path, or in one of the custom paths
|
# Sphinx are currently 'default' and 'sphinxdoc'.
|
||||||
# given in html_static_path.
|
html_theme = 'default'
|
||||||
html_style = 'default.css'
|
|
||||||
|
# Theme options are theme-specific and customize the look and feel of a theme
|
||||||
|
# further. For a list of options available for each theme, see the
|
||||||
|
# documentation.
|
||||||
|
#html_theme_options = {}
|
||||||
|
|
||||||
|
# Add any paths that contain custom themes here, relative to this directory.
|
||||||
|
#html_theme_path = []
|
||||||
|
|
||||||
# The name for this set of Sphinx documents. If None, it defaults to
|
# The name for this set of Sphinx documents. If None, it defaults to
|
||||||
# "<project> v<release> documentation".
|
# "<project> v<release> documentation".
|
||||||
|
@ -27,7 +27,7 @@
|
|||||||
{%- endmacro %}
|
{%- endmacro %}
|
||||||
|
|
||||||
{%- macro sidebar() %}
|
{%- macro sidebar() %}
|
||||||
{%- if not embedded %}
|
{%- if not embedded %}{% if not theme_nosidebar|tobool %}
|
||||||
<div class="sphinxsidebar">
|
<div class="sphinxsidebar">
|
||||||
<div class="sphinxsidebarwrapper">
|
<div class="sphinxsidebarwrapper">
|
||||||
{%- block sidebarlogo %}
|
{%- block sidebarlogo %}
|
||||||
@ -86,7 +86,7 @@
|
|||||||
{%- endblock %}
|
{%- endblock %}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
{%- endif %}
|
{%- endif %}{% endif %}
|
||||||
{%- endmacro %}
|
{%- endmacro %}
|
||||||
|
|
||||||
<html xmlns="http://www.w3.org/1999/xhtml">
|
<html xmlns="http://www.w3.org/1999/xhtml">
|
||||||
@ -155,15 +155,15 @@
|
|||||||
{%- block document %}
|
{%- block document %}
|
||||||
<div class="document">
|
<div class="document">
|
||||||
<div class="documentwrapper">
|
<div class="documentwrapper">
|
||||||
{%- if not embedded %}
|
{%- if not embedded %}{% if not theme_nosidebar|tobool %}
|
||||||
<div class="bodywrapper">
|
<div class="bodywrapper">
|
||||||
{%- endif %}
|
{%- endif %}{% endif %}
|
||||||
<div class="body">
|
<div class="body">
|
||||||
{% block body %} {% endblock %}
|
{% block body %} {% endblock %}
|
||||||
</div>
|
</div>
|
||||||
{%- if not embedded %}
|
{%- if not embedded %}{% if not theme_nosidebar|tobool %}
|
||||||
</div>
|
</div>
|
||||||
{%- endif %}
|
{%- endif %}{% endif %}
|
||||||
</div>
|
</div>
|
||||||
{%- endblock %}
|
{%- endblock %}
|
||||||
|
|
||||||
|
@ -2,3 +2,6 @@
|
|||||||
inherit = none
|
inherit = none
|
||||||
stylesheet = basic.css
|
stylesheet = basic.css
|
||||||
pygments_style = none
|
pygments_style = none
|
||||||
|
|
||||||
|
[options]
|
||||||
|
nosidebar = false
|
||||||
|
12
sphinx/themes/default/layout.html
Normal file
12
sphinx/themes/default/layout.html
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
{% extends "basic/layout.html" %}
|
||||||
|
{% block extrahead %}
|
||||||
|
{%- if theme_rightsidebar|tobool %}
|
||||||
|
<link rel="stylesheet" href="{{ pathto('_static/rightsidebar.css', 1) }}"
|
||||||
|
type="text/css" />
|
||||||
|
{%- endif %}
|
||||||
|
{%- if theme_stickysidebar|tobool %}
|
||||||
|
<link rel="stylesheet" href="{{ pathto('_static/stickysidebar.css', 1) }}"
|
||||||
|
type="text/css" />
|
||||||
|
{%- endif %}
|
||||||
|
{{ super() }}
|
||||||
|
{% endblock %}
|
@ -1,10 +1,8 @@
|
|||||||
/**
|
/* rightsidebar overrides for default design */
|
||||||
* Sphinx Doc Design -- Right Side Bar Overrides
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
div.sphinxsidebar {
|
div.sphinxsidebar {
|
||||||
float: right;
|
float: right;
|
||||||
|
right: 0; /* for sticky sidebar */
|
||||||
}
|
}
|
||||||
|
|
||||||
div.bodywrapper {
|
div.bodywrapper {
|
||||||
|
@ -1,15 +1,17 @@
|
|||||||
/**
|
/* stickysidebar overrides for default design */
|
||||||
* Sphinx Doc Design -- Sticky sidebar Overrides
|
|
||||||
*/
|
|
||||||
|
|
||||||
div.sphinxsidebar {
|
div.sphinxsidebar {
|
||||||
top: 30px;
|
top: 30px;
|
||||||
left: 0px;
|
height: 100%;
|
||||||
|
overflow: auto;
|
||||||
position: fixed;
|
position: fixed;
|
||||||
margin: 0;
|
margin: 0;
|
||||||
float: none;
|
background-color: #1c4e63;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* this is nice, but it it leads to hidden headings when jumping
|
||||||
|
to an anchor */
|
||||||
|
/*
|
||||||
div.related {
|
div.related {
|
||||||
position: fixed;
|
position: fixed;
|
||||||
}
|
}
|
||||||
@ -17,3 +19,4 @@ div.related {
|
|||||||
div.documentwrapper {
|
div.documentwrapper {
|
||||||
margin-top: 30px;
|
margin-top: 30px;
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
@ -2,3 +2,7 @@
|
|||||||
inherit = basic
|
inherit = basic
|
||||||
stylesheet = default.css
|
stylesheet = default.css
|
||||||
pygments_style = sphinx
|
pygments_style = sphinx
|
||||||
|
|
||||||
|
[options]
|
||||||
|
rightsidebar = false
|
||||||
|
stickysidebar = false
|
||||||
|
@ -108,7 +108,7 @@ class Theme(object):
|
|||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
return self.themeconf.get(section, name)
|
return self.themeconf.get(section, name)
|
||||||
except ConfigParser.NoOptionError:
|
except (ConfigParser.NoOptionError, ConfigParser.NoSectionError):
|
||||||
if self.base is not None:
|
if self.base is not None:
|
||||||
return self.base.get_confstr(section, name)
|
return self.base.get_confstr(section, name)
|
||||||
if default is NODEFAULT:
|
if default is NODEFAULT:
|
||||||
@ -117,6 +117,27 @@ class Theme(object):
|
|||||||
else:
|
else:
|
||||||
return default
|
return default
|
||||||
|
|
||||||
|
def get_options(self, overrides):
|
||||||
|
"""
|
||||||
|
Return a dictionary of theme options and their values.
|
||||||
|
"""
|
||||||
|
chain = [self.themeconf]
|
||||||
|
base = self.base
|
||||||
|
while base is not None:
|
||||||
|
chain.append(base.themeconf)
|
||||||
|
base = base.base
|
||||||
|
options = {}
|
||||||
|
for conf in reversed(chain):
|
||||||
|
try:
|
||||||
|
options.update(conf.items('options'))
|
||||||
|
except ConfigParser.NoSectionError:
|
||||||
|
pass
|
||||||
|
for option, value in overrides.iteritems():
|
||||||
|
if option not in options:
|
||||||
|
raise ThemeError('unsupported theme option %r given' % option)
|
||||||
|
options[option] = value
|
||||||
|
return options
|
||||||
|
|
||||||
def get_dirchain(self):
|
def get_dirchain(self):
|
||||||
"""
|
"""
|
||||||
Return a list of theme directories, beginning with this theme's,
|
Return a list of theme directories, beginning with this theme's,
|
||||||
|
Loading…
Reference in New Issue
Block a user