Commit 9c210703 authored by Spencer Williams's avatar Spencer Williams
Browse files

initial

parents
# Rigado Sphinx Themes and Extensions
Include this repository as a submodule of your Sphinx project repository, then wire it up to use its themes and extensions!
from sphinx.builders.html import StandaloneHTMLBuilder
class InventoryBuilder(StandaloneHTMLBuilder):
name = 'inventory'
def write_doc(self, docname, doctree):
pass
def finish(self):
self.dump_inventory()
def setup(app):
app.add_builder(InventoryBuilder)
# -*- coding: utf-8 -*-
"""
An extension that adds tablelist and figurelist directives
that will populate with lists of the tables and figures
contained in the current document.
Only works with html builders
Usage:
.. tablelist::
.. figurelist::
"""
from docutils import nodes
from docutils.parsers.rst import Directive
from sphinx.util.nodes import clean_astext
from docutils.nodes import fully_normalize_name
def setup(app):
app.add_node(tablelist,
html=(visit_pass, depart_pass))
app.add_node(figurelist,
html=(visit_pass, depart_pass))
app.add_directive('tablelist', TablelistDirective)
app.add_directive('figurelist', FigurelistDirective)
app.connect('doctree-resolved', process_tablelists)
app.connect('doctree-resolved', process_figurelists)
return {'version': '0.1'}
def visit_pass(self, node):
pass
def depart_pass(self, node):
pass
class tablelist(nodes.General, nodes.Element):
pass
class figurelist(nodes.General, nodes.Element):
pass
class TablelistDirective(Directive):
def run(self):
return [tablelist('')]
class FigurelistDirective(Directive):
def run(self):
return [figurelist('')]
def process_tablelists(app, doctree, fromdocname):
process_lists(app, doctree, fromdocname, tablelist, nodes.table)
def process_figurelists(app, doctree, fromdocname):
process_lists(app, doctree, fromdocname, figurelist, nodes.figure)
def ancestorOfClass(node, ancestorclassname):
if node.__class__.__name__ == ancestorclassname:
return node
elif hasattr(node, 'parent'):
return ancestorOfClass(node.parent, ancestorclassname)
else:
return False
def process_lists(app, doctree, fromdocname, list_directive, target_directive):
ns = dict((k, app.config[k]) for k in app.config.values)
ns.update(app.config.__dict__.copy())
ns['builder'] = app.builder.name
# Replace all figurelist nodes with a list of the collected figures.
# Augment each figure name with a backlink to the original location.
for node in doctree.traverse(list_directive):
# lists of figures and tables in latex are handled elsewhere
if app.builder.name == 'latex':
node.replace_self(nodes.Text(''))
continue
content = ""
for subnode in doctree.traverse(target_directive):
# make sure subnode isn't in an ifconfig block that would remove it from output
ifconfigAncestor = ancestorOfClass(subnode, 'ifconfig')
ifconfigOK = True
if ifconfigAncestor:
try:
ifconfigOK = eval(ifconfigAncestor['expr'], ns)
except Exception as err:
pass
if ifconfigOK:
made = makecontent(subnode, fromdocname, app.builder.env)
if app.builder.name == 'html':
content += made['html']
else:
content += made['text']
if app.builder.name == 'html':
content = '<p>%s</p>' % (content)
node.replace_self(nodes.raw(content, content, format='html'))
else:
node.replace_self(nodes.Text(content))
def makecontent(node, docname, env):
figname = get_fig_title(node)
figtype = get_fig_type(node)
try:
figid = node['ids'][0]
fignumber = env.toc_fignumbers[docname][figtype][figid]
except (KeyError, IndexError):
# target_node is found, but fignumber is not assigned.
# Maybe it is defined in orphaned document.
env.warn(docname, "no number is assigned for %s: %s" % (figtype, figname), lineno=node.line)
return {'html': '', 'text': ''}
title = env.config.numfig_format.get(figtype, '')
try:
newtitle = title % '.'.join(map(str, fignumber))
except TypeError:
env.warn(fromdocname, 'invalid numfig_format: %s' % title,
lineno=node.line)
return {'html': '', 'text': ''}
html = '<a href="#%s">%s%s</a><br />' % (figid, newtitle, figname)
text = '%s%s\n' % (newtitle, figname)
return {'html': html, 'text': text}
def get_fig_title(node):
for subnode in node:
if subnode.tagname in ('caption', 'title'):
return clean_astext(subnode)
return ""
enumerable_nodes = {
nodes.table: 'table',
nodes.figure: 'figure',
nodes.container: 'code-block'
}
def get_fig_type(node):
def has_child(node, cls):
return any(isinstance(child, cls) for child in node)
if isinstance(node, nodes.container):
if node.get('literal_block') and has_child(node, nodes.literal_block):
return 'code-block'
else:
return None
else:
figtype = enumerable_nodes.get(node.__class__, None)
return figtype
{#
rigado/globaltoc.html
~~~~~~~~~~~~~~~~~~~~
Sphinx sidebar template: global table of contents.
#}
<h3><a href="{{ pathto(master_doc) }}">{{ _('Document Contents') }}</a></h3>
{{ toctree() }}
{#
rigado/layout.html
~~~~~~~~~~~~~~~~~~~
Sphinx layout template for the Rigado theme.
:copyright: Copyright 2017 by Rigado
:license: All rights reserved
#}
{% extends "classic/layout.html" %}
{% set css_files = css_files + ['_static/css/rigado.css'] %}
{%- block linktags %}
<link href="https://fonts.googleapis.com/css?family=Source+Sans+Pro:400,600,400italic,600italic" rel="stylesheet" type="text/css">
{{ super() }}
{%- endblock %}
{# remove breadcrumbs from relbar, add logo to relbar #}
{%- block relbar1 %}
<div class="related" role="navigation" aria-label="related navigation">
<h3>{{ _('Navigation') }}</h3>
<ul>
<li class="right"><a href="{{ pathto(master_doc) }}" title="Top">Top</a></li>
{%- for rellink in rellinks %}
<li class="right">
<a href="{{ pathto(rellink[0]) }}" title="{{ rellink[1]|striptags|e }}"
{{ accesskey(rellink[2]) }}>{{ rellink[3]|capitalize }}</a>
{{ reldelim2 }}</li>
{%- endfor %}
<li class="nav-item nav-item-0">
<a href="/"><img class="logo" src="{{ pathto('_static/' + logo, 1) }}" alt="{{ shorttitle|e }}"/></a>
</li>
</ul>
</div>
{%- endblock %}
{# no relbar2 please! #}
{%- block relbar2 %}{%- endblock %}
{# reformat the search form a little #}
{# had to copy in the entire sidebar because it was just going to include the files and the sidebarsearch block was defined in the layout, not in the included file #}
{%- block sidebar2 %}
{%- if render_sidebar %}
<div class="sphinxsidebar" role="navigation" aria-label="main navigation">
<div class="sphinxsidebarwrapper">
{%- if sidebars != None %}
{#- new style sidebar: explicitly include/exclude templates #}
{%- for sidebartemplate in sidebars %}
{%- include sidebartemplate %}
{%- endfor %}
{%- else %}
{%- block sidebarsearch %}
{%- include "searchbar.html" %}
{%- endblock %}
{%- if theme_use_global_toc %}
{%- include "globaltoc.html" %}
{%- endif %}
{%- block sidebartoc %}
{%- include "localtoc.html" %}
{%- endblock %}
{%- block sidebarsourcelink %}
{%- include "sourcelink.html" %}
{%- endblock %}
{%- endif %}
</div>
</div>
{%- endif %}
{%- endblock %}
{%- block footer %}
<div class="footer" role="contentinfo">
{%- if show_copyright %}
{%- if hasdoc('copyright') %}
{% trans path=pathto('copyright'), copyright=copyright|e %}
&#169; <a href="{{ path }}">Copyright</a> {{ copyright }}.
{% endtrans %}
{%- else %}
{% trans copyright=copyright|e %}
&#169; Copyright {{ copyright }}.
{% endtrans %}
{%- endif %}
<br />
{%- endif %}
Release {{ release|e }}.
{%- if last_updated %}
{% trans last_updated=last_updated|e %}
Last updated on {{ last_updated }}.
{% endtrans %}
{%- endif %}
{%- if commit %}
{% trans commit=commit %}
Revision <code>{{ commit }}</code>.
{% endtrans %}
{%- endif %}
<br />
{%- if show_sphinx %}
{% trans sphinx_version=sphinx_version|e %}
Created using <a href="http://sphinx-doc.org/">Sphinx</a> {{ sphinx_version }}.
{% endtrans %}
{%- endif %}
</div>
{%- endblock %}
{#
rigado/localtoc.html
~~~~~~~~~~~~~~~~~~~~
Sphinx sidebar template: local table of contents.
#}
{%- if display_toc %}
<div id="localtoc">
<h3><a href="{{ pathto(master_doc) }}">{{ _('Section Contents') }}</a></h3>
{{ toc }}
</div>
{%- endif %}
{#
rigado/page.html
~~~~~~~~~~~~~~~
Master template for simple pages.
#}
{%- extends "layout.html" %}
{% block body %}
{{ body }}
<div class="body-rellinks">
{%- if prev %}
<div class="body-rellink body-prevlink">
<h4>{{ _('Previous topic') }}</h4>
<p class="topless"><a href="{{ prev.link|e }}"
title="{{ _('previous chapter') }}">{{ prev.title }}</a></p>
</div>
{%- endif %}
{%- if next %}
<div class="body-rellink body-nextlink">
<h4>{{ _('Next topic') }}</h4>
<p class="topless"><a href="{{ next.link|e }}"
title="{{ _('next chapter') }}">{{ next.title }}</a></p>
</div>
{%- endif %}
<div class="clearer"></div>
</div>
<div class="clearer"></div>
{% endblock %}
{#
rigado/searchbar.html
~~~~~~~~~~~~~~~~~~~~~~
Sphinx sidebar template: search bar.
#}
{%- if theme_use_search and pagename != "search" and builder != "singlehtml" %}
<div id="searchbox" role="search">
<form class="search" action="{{ pathto('search') }}" method="get">
<div><input type="text" name="q" placeholder="Search" /></div>
<input type="hidden" name="check_keywords" value="yes" />
<input type="hidden" name="area" value="default" />
<div class="clearer"></div>
</form>
</div>
<script type="text/javascript">$('#searchbox').show(0);</script>
{%- endif %}
{#
rigado/sourcelink.html
~~~~~~~~~~~~~~~~~~~~~~
Sphinx sidebar template: "show source" link.
#}
{%- if show_source and has_source and sourcename %}
<h4>{{ _('This Page') }}</h4>
<p class="topless"><a href="{{ pathto('_sources/' + sourcename, true)|e }}"
rel="nofollow" title="{{ _('show source') }}">{{ _('Show Source') }}</a></p>
{%- endif %}
/*
* rigado.css_t
* ~~~~~~~~~~~~
*
* Sphinx stylesheet -- rigado theme.
*
*/
div.body a, div.body a:hover, div.body a:visited {
text-decoration: underline;
}
div.related a:hover,
div.sphinxsidebar h3 a:hover,
div.sphinxsidebar a:hover,
a:hover, a.headerlink:hover {
color: #c04b27;
}
div.related a.button:hover,
div.sphinxsidebar a.button:hover {
color: #fafafa;
}
div.sphinxsidebar h2 {
color: #1f5b8d;
font-weight: bold;
font-size: 1.25em;
margin-bottom: 0;
}
div.related .right a {
padding-right: 8px;
}
div a.button, button {
background: #1f5b8d;
color: #fafafa;
width: 100%;
padding: 0.5em 0;
display: block;
text-decoration: none;
border-radius: 0.5em;
text-align: center;
}
button {
width: inherit;
display: inline;
border: none;
padding: 0.5em 1.5em;
}
div.related .right a.button {
padding: 0 0.2em;
}
div.sphinxsidebar a.button {
width: 185px;
}
a.headerlink:hover {
background-color: transparent;
}
div.body h1, div.body h2, div.body h3, div.body h4, div.body h5, div.body h6 {
border: 0 none transparent;
}
div.sphinxsidebar input {
border-color: #757575;
}
div.admonition {
border: 1px solid #1f5b8d;
background-color: #BFE3F6;
}
div.admonition.note, div.seealso,
div.viewcode-block:target,
div.topic,
code, th {
border-color: #757575;
background-color: #eee;
}
div.admonition.warning {
border-color: #c04b27;
background-color: #ffe4e4;
}
div.admonition.tip {
border: none;
background: inherit;
}
div.admonition.tip p.admonition-title {
font-style: italic;
}
pre {
border-color: #757575;
}
code, pre {
font-size: 1.1em;
}
img.logo {
max-width: 180px;
margin: 10px 0 10px 130px;
}
div.body {
border-left: 1px solid #cecece;
}
div.related {
margin-bottom: 20px;
}
div.related li.right {
margin-top: 10px;
margin-right: 8px;
font-size: 0.85em;
}
div.bodywrapper {
margin-left: 216px;
}
div.sphinxsidebar {
width: 216px;
}
div.body {
padding-left: 23px;
padding-top: 15px;
max-width: 80%;
}
div.body h1, div.body h2, div.body h3, div.body h4, div.body h5, div.body h6 {
margin: 0;
padding: 0;
}
div.body h1 {
margin-bottom: 0.2em;
}
div.body h2 {
font-weight: bold;
font-size: 1.2em;
}
div.body h3, div.body h4, div.body h5, div.body h6 {
font-weight: bold;
font-size: 1em;
}
div.body p {
margin-bottom: 0.5em;
text-align: left;
line-height: 150%;
}
div.body div.section {
margin-bottom: 1.5em;
}
div.body-rellinks {
margin-top: 6em;
background-color: #fafafa;
padding 0 .5em;
}
div.body-rellink {
width: 40%;
padding: .5em;
}
div.body-rellink h4 {
background-color: #fafafa;
}
div.body-prevlink {
float: left;
}
div.body-nextlink {
float: right;
}
div.sphinxsidebarwrapper {
padding-left: 20px;
}
div.sphinxsidebar h3, div.sphinxsidebar h4 {
font-weight: bold;
font-size: 0.9em;
}
div.sphinxsidebar ul ul, div.sphinxsidebar ul.want-points {
list-style-type: none;
}
div.sphinxsidebarwrapper > ul,
div.sphinxsidebarwrapper > ul > li > ul,
div#localtoc > ul,
div#localtoc > ul > li > ul,
div.sphinxsidebar p.topless,
#searchbox,
div.sphinxsidebar a.button {
margin: 0 0 20px;
}
div.sphinxsidebar input[type='text'] {
border-radius: 1em;
padding: 0.25em 0.5em;
}
div.sphinxsidebar code {
font-family: {{ theme_bodyfont }};
font-weight: normal;
font-size: 1em;
padding: 0;
}
div.sphinxsidebar li {
margin-top: 0.25em;
}
[theme]
inherit = classic
stylesheets = rigado.css
pygments_style = none
[options]
analytics_ua =
analytics_domain =
use_search = True
use_global_toc =
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment