Skip to content

Commit

Permalink
馃摑馃殤馃挬 Add Travis CI badge to docs
Browse files Browse the repository at this point in the history
Also patch alabaster theme to work around the bug which should be fixed
by merging sphinx-doc/alabaster#147.
  • Loading branch information
webknjaz committed Mar 17, 2019
1 parent 63c80d3 commit e5756d9
Show file tree
Hide file tree
Showing 2 changed files with 85 additions and 0 deletions.
52 changes: 52 additions & 0 deletions docs/_templates/about.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
{% if theme_logo %}
<p class="logo">
<a href="{{ pathto(master_doc) }}">
<img class="logo" src="{{ pathto('_static/' ~ theme_logo, 1) }}" alt="Logo"/>
{% if theme_logo_name|lower == 'true' %}
<h1 class="logo logo-name">{{ project }}</h1>
{% endif %}
</a>
</p>
{% else %}
<h1 class="logo"><a href="{{ pathto(master_doc) }}">{{ project }}</a></h1>
{% endif %}

{% if theme_description %}
<p class="blurb">{{ theme_description }}</p>
{% endif %}

{% if theme_github_user and theme_github_repo %}
{% if theme_github_button|lower == 'true' %}
<p>
<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"
allowtransparency="true" frameborder="0" scrolling="0" width="200px" height="35px"></iframe>
</p>
{% endif %}
{% endif %}

{% if theme_travis_button|lower != 'false' %}
<p>
<a class="badge" href="{{ theme_travis_build_url }}">
<img
alt="Travis CI build badge"
src="{{ theme_travis_badge_url }}"
/>
</a>
</p>
{% endif %}

{% if theme_codecov_button|lower != 'false' %}
{% if theme_codecov_button|lower == 'true' %}
{% set path = theme_github_user + '/' + theme_github_repo %}
{% else %}
{% set path = theme_codecov_button %}
{% endif %}
<p>
<a class="badge" href="https://codecov.io/github/{{ path }}">
<img
alt="https://codecov.io/github/{{ path }}/coverage.svg?branch={{ theme_badge_branch }}"
src="https://codecov.io/github/{{ path }}/coverage.svg?branch={{ theme_badge_branch }}"
/>
</a>
</p>
{% endif %}
33 changes: 33 additions & 0 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,8 @@ def get_github_data(project_urls):
'github_repo': PRJ_GITHUB_REPO,
'github_type': 'star',
'github_banner': True,
'travis_button': True,
# 'travis_tld': 'com',
'show_relbars': True,
'show_related': True,
'extra_nav_links': {
Expand Down Expand Up @@ -275,3 +277,34 @@ def get_github_data(project_urls):

# If true, `todo` and `todoList` produce output, else they produce nothing.
todo_include_todos = True


# Patch alabaster theme
# Ref: https://github.com/bitprophet/alabaster/pull/147
# FIXME: drop this hack once the PR is merged & released; pylint: disable=fixme
def set_up_travis_context(
app, pagename, templatename, # pylint: disable=unused-argument
context,
doctree, # pylint: disable=unused-argument
):
"""Add complete Travis URLs to Jinja2 context."""
github_slug = '/'.join(
(context['theme_github_user'], context['theme_github_repo']),
)

travis_button = str(context['theme_travis_button']).lower()
travis_button_enabled = travis_button == 'true'

travis_slug = github_slug if travis_button_enabled else travis_button

travis_tld = 'com' # context["theme_travis_tld"].strip(".").lower()
travis_base_uri = 'travis-ci.{}/{}'.format(travis_tld, travis_slug)
context['theme_travis_build_url'] = 'https://{}'.format(travis_base_uri)
context['theme_travis_badge_url'] = 'https://api.{}.svg?branch={}'.format(
travis_base_uri, context['theme_badge_branch'],
)


def setup(app):
"""Patch the sphinx theme set up stage."""
app.connect('html-page-context', set_up_travis_context)

0 comments on commit e5756d9

Please sign in to comment.