Skip to content

Commit

Permalink
Merge pull request #25362 from noahdesu/mimic-docs
Browse files Browse the repository at this point in the history
mimic: docs: backport edit on github changes

Reviewed-by: Josh Durgin <jdurgin@redhat.com>
  • Loading branch information
dotnwat committed Dec 7, 2018
2 parents 802ee23 + ee35ddf commit 88b1cef
Show file tree
Hide file tree
Showing 5 changed files with 119 additions and 0 deletions.
Empty file added doc/README.md
Empty file.
43 changes: 43 additions & 0 deletions doc/_ext/edit_on_github.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
"""
Adapted from https://gist.github.com/mgedmin/6052926
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}/doc/{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)
show_url = get_github_url(app, 'blob', path)
edit_url = get_github_url(app, 'edit', 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.connect('html-page-context', html_page_context)
41 changes: 41 additions & 0 deletions doc/_static/js/ceph.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
$(function() {
var releases_url = "http://docs.ceph.com/docs/master/releases.json";

function show_edit(branch, data) {
if (branch) {
if (branch === "master") {
$("#dev-warning").show();
return true;
}
if (data && data.releases && branch in data.releases) {
var eol = ("actual_eol" in data.releases[branch]);
if (eol) {
$("#eol-warning").show();
}
return !eol;
}
}
$("#dev-warning").show();
return false;
}

function get_branch() {
var url = window.location.href;
var res = url.match(/docs.ceph.com\/docs\/([a-z]+)\/?/i)
if (res) {
return res[1]
}
return null;
}

$.getJSON(releases_url, function(data) {
var branch = get_branch();
if (show_edit(branch, data)) {
// patch the edit-on-github URL for correct branch
var url = $("#edit-on-github").attr("href");
url = url.replace("master", branch);
$("#edit-on-github").attr("href", url);
$("#docubetter").show();
}
});
});
21 changes: 21 additions & 0 deletions doc/_templates/page.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{% extends "!page.html" %}
{% block body %}

<div id="dev-warning" class="admonition note" style="display:none;">
<p class="first admonition-title">Notice</p>
<p class="last">This document is for a development version of Ceph.</p>
</div>

<div id="eol-warning" class="admonition warning" style="display:none;">
<p class="first admonition-title">Warning</p>
<p class="last">This document is for an unsupported version of Ceph.</p>
</div>

{%- if edit_on_github_url %}
<div id="docubetter" align="right" style="display:none; padding: 15px; font-weight: bold;">
<a id="edit-on-github" href="{{ edit_on_github_url }}" rel="nofollow">{{ _('Edit on GitHub')}}</a> | <a href="https://github.com/ceph/ceph/projects/4">Report a Documentation Bug</a>
</div>
{%- endif %}

{{ super() }}
{% endblock %}
14 changes: 14 additions & 0 deletions doc/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,16 +36,20 @@
html_logo = 'logo.png'
html_favicon = 'favicon.ico'
html_show_sphinx = False
html_static_path = ["_static"]
html_sidebars = {
'**': ['smarttoc.html', 'searchbox.html'],
}

sys.path.insert(0, os.path.abspath('_ext'))

extensions = [
'sphinx.ext.autodoc',
'sphinx.ext.graphviz',
'sphinx.ext.todo',
'sphinxcontrib.ditaa',
'breathe',
'edit_on_github',
]
ditaa = 'ditaa'
todo_include_todos = True
Expand All @@ -67,6 +71,16 @@
}
breathe_domain_by_extension = {'py': 'py', 'c': 'c', 'h': 'c', 'cc': 'cxx', 'hpp': 'cxx'}

# the docs are rendered with github links pointing to master. the javascript
# snippet in _static/ceph.js rewrites the edit links when a page is loaded, to
# point to the correct branch.
edit_on_github_project = 'ceph/ceph'
edit_on_github_branch = 'master'

# handles edit-on-github and old version warning display
def setup(app):
app.add_javascript('js/ceph.js')

# mocking ceph_module offered by ceph-mgr. `ceph_module` is required by
# mgr.mgr_module
class Dummy(object):
Expand Down

0 comments on commit 88b1cef

Please sign in to comment.