Added edit on github links to pages

Signed-off-by: Ian Bell <ian.h.bell@gmail.com>
This commit is contained in:
Ian Bell
2014-07-07 15:08:53 +02:00
parent e7640020b8
commit 368f418c2c
4 changed files with 66 additions and 3 deletions

View File

@@ -10,6 +10,4 @@ REM ~ copy /Y CoolPropdoc.pdf ..\..\_static\
REM ~ cd ..\..
rem sphinx-apidoc -f -o apidoc ../CoolProp
python -V
python -c "import IPython.sphinxext.ipython_console_highlighting as I; print I.__file__"
mingw32-make html

View File

@@ -0,0 +1,45 @@
"""
Sphinx extension to add ReadTheDocs-style "Edit on GitHub" links to the
sidebar.
Loosely based on https://github.com/astropy/astropy/pull/347
"""
import os
import warnings
__licence__ = 'BSD (3 clause)'
def get_github_url(app, view, path):
return 'https://github.com/{project}/{view}/{branch}/{path}'.format(
project=app.config.edit_on_github_project,
view=view,
branch=app.config.edit_on_github_branch,
path=path)
def html_page_context(app, pagename, templatename, context, doctree):
if templatename != 'page.html':
return
if not app.config.edit_on_github_project:
warnings.warn("edit_on_github_project not specified")
return
path = os.path.relpath(doctree.get('source'), app.builder.srcdir)
path_prefix = app.config.edit_on_github_path_prefix
show_url = get_github_url(app, 'blob', path_prefix + '/' + path)
edit_url = get_github_url(app, 'edit', path_prefix + '/' + path)
context['show_on_github_url'] = show_url
context['edit_on_github_url'] = edit_url
def setup(app):
app.add_config_value('edit_on_github_project', '', True)
app.add_config_value('edit_on_github_branch', 'master', True)
app.add_config_value('edit_on_github_path_prefix', '', True)
app.connect('html-page-context', html_page_context)

View File

@@ -0,0 +1,15 @@
{%- if show_source and has_source and sourcename %}
<h3>{{ _('This Page') }}</h3>
<ul class="this-page-menu">
<li><a href="{{ pathto('_sources/' + sourcename, true)|e }}"
rel="nofollow">{{ _('Show Source') }}</a></li>
{%- if show_on_github_url %}
<li><a href="{{ show_on_github_url }}"
rel="nofollow">{{ _('Show on GitHub') }}</a></li>
{%- endif %}
{%- if edit_on_github_url %}
<li><a href="{{ edit_on_github_url }}"
rel="nofollow">{{ _('Edit on GitHub') }}</a></li>
{%- endif %}
</ul>
{%- endif %}

View File

@@ -13,7 +13,7 @@
# serve to show the default.
import sys, os
print sys.path
sys.path.insert(0, os.path.abspath('_ext'))
try:
import sphinxcontrib.doxylink
except ImportError:
@@ -41,6 +41,7 @@ extensions = ['IPython.sphinxext.ipython_console_highlighting',
'sphinx.ext.extlinks',
'sphinxcontrib.napoleon',
'sphinxcontrib.doxylink',
'edit_on_github', # see https://gist.github.com/mgedmin/6052926#file-edit_on_github-pyb
# cloud's extensions
#'cloud_sptheme.ext.autodoc_sections',
@@ -162,6 +163,10 @@ html_theme_options = { "roottarget": "index",
"logotarget": "index"
}
edit_on_github_project = 'CoolProp/CoolProp'
edit_on_github_branch = 'master'
edit_on_github_path_prefix = 'Web'
# The theme to use for HTML and HTML Help pages. Major themes that come with
# Sphinx are currently 'default' and 'sphinxdoc'.
## html_theme = 'sphinxdoc'