Skip to content

Commit e5756d9

Browse files
committed
📝🚑💩 Add Travis CI badge to docs
Also patch alabaster theme to work around the bug which should be fixed by merging sphinx-doc/alabaster#147.
1 parent 63c80d3 commit e5756d9

File tree

2 files changed

+85
-0
lines changed

2 files changed

+85
-0
lines changed

docs/_templates/about.html

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
{% if theme_logo %}
2+
<p class="logo">
3+
<a href="{{ pathto(master_doc) }}">
4+
<img class="logo" src="{{ pathto('_static/' ~ theme_logo, 1) }}" alt="Logo"/>
5+
{% if theme_logo_name|lower == 'true' %}
6+
<h1 class="logo logo-name">{{ project }}</h1>
7+
{% endif %}
8+
</a>
9+
</p>
10+
{% else %}
11+
<h1 class="logo"><a href="{{ pathto(master_doc) }}">{{ project }}</a></h1>
12+
{% endif %}
13+
14+
{% if theme_description %}
15+
<p class="blurb">{{ theme_description }}</p>
16+
{% endif %}
17+
18+
{% if theme_github_user and theme_github_repo %}
19+
{% if theme_github_button|lower == 'true' %}
20+
<p>
21+
<iframe src="https://ghbtns.com/github-btn.html?user={{ theme_github_user }}&repo={{ theme_github_repo }}&type={{ theme_github_type }}&count={{ theme_github_count }}&size=large&v=2"
22+
allowtransparency="true" frameborder="0" scrolling="0" width="200px" height="35px"></iframe>
23+
</p>
24+
{% endif %}
25+
{% endif %}
26+
27+
{% if theme_travis_button|lower != 'false' %}
28+
<p>
29+
<a class="badge" href="{{ theme_travis_build_url }}">
30+
<img
31+
alt="Travis CI build badge"
32+
src="{{ theme_travis_badge_url }}"
33+
/>
34+
</a>
35+
</p>
36+
{% endif %}
37+
38+
{% if theme_codecov_button|lower != 'false' %}
39+
{% if theme_codecov_button|lower == 'true' %}
40+
{% set path = theme_github_user + '/' + theme_github_repo %}
41+
{% else %}
42+
{% set path = theme_codecov_button %}
43+
{% endif %}
44+
<p>
45+
<a class="badge" href="https://codecov.io/github/{{ path }}">
46+
<img
47+
alt="https://codecov.io/github/{{ path }}/coverage.svg?branch={{ theme_badge_branch }}"
48+
src="https://codecov.io/github/{{ path }}/coverage.svg?branch={{ theme_badge_branch }}"
49+
/>
50+
</a>
51+
</p>
52+
{% endif %}

docs/conf.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,8 @@ def get_github_data(project_urls):
155155
'github_repo': PRJ_GITHUB_REPO,
156156
'github_type': 'star',
157157
'github_banner': True,
158+
'travis_button': True,
159+
# 'travis_tld': 'com',
158160
'show_relbars': True,
159161
'show_related': True,
160162
'extra_nav_links': {
@@ -275,3 +277,34 @@ def get_github_data(project_urls):
275277

276278
# If true, `todo` and `todoList` produce output, else they produce nothing.
277279
todo_include_todos = True
280+
281+
282+
# Patch alabaster theme
283+
# Ref: https://github.com/bitprophet/alabaster/pull/147
284+
# FIXME: drop this hack once the PR is merged & released; pylint: disable=fixme
285+
def set_up_travis_context(
286+
app, pagename, templatename, # pylint: disable=unused-argument
287+
context,
288+
doctree, # pylint: disable=unused-argument
289+
):
290+
"""Add complete Travis URLs to Jinja2 context."""
291+
github_slug = '/'.join(
292+
(context['theme_github_user'], context['theme_github_repo']),
293+
)
294+
295+
travis_button = str(context['theme_travis_button']).lower()
296+
travis_button_enabled = travis_button == 'true'
297+
298+
travis_slug = github_slug if travis_button_enabled else travis_button
299+
300+
travis_tld = 'com' # context["theme_travis_tld"].strip(".").lower()
301+
travis_base_uri = 'travis-ci.{}/{}'.format(travis_tld, travis_slug)
302+
context['theme_travis_build_url'] = 'https://{}'.format(travis_base_uri)
303+
context['theme_travis_badge_url'] = 'https://api.{}.svg?branch={}'.format(
304+
travis_base_uri, context['theme_badge_branch'],
305+
)
306+
307+
308+
def setup(app):
309+
"""Patch the sphinx theme set up stage."""
310+
app.connect('html-page-context', set_up_travis_context)

0 commit comments

Comments
 (0)