Skip to content

Commit

Permalink
Merge pull request #3632 from fenilgandhi/master
Browse files Browse the repository at this point in the history
Add support for different badge styles
  • Loading branch information
ericholscher authored Jun 6, 2018
2 parents 17c5b2f + 0af69a4 commit 8aa4262
Show file tree
Hide file tree
Showing 18 changed files with 57 additions and 10 deletions.
20 changes: 18 additions & 2 deletions docs/badges.rst
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,30 @@ Here are a few examples:
You can see it in action in the `Read the Docs README`_.
They will link back to your project's documentation page on Read the Docs.

Style
-----

Now you can pass the ``style`` GET argument,
to get custom styled badges same as you would for shields.io.
If no argument is passed, ``flat`` is used as default.

STYLE | BADGE
------------ | -------------
flat | ![Flat Badge](https://readthedocs.org/projects/pip/badge/?version=latest&style=flat)
flat-square | ![Flat-Square Badge](https://readthedocs.org/projects/pip/badge/?version=latest&style=flat-square)
for-the-badge | ![ Badge](https://readthedocs.org/projects/pip/badge/?version=latest&style=for-the-badge)
plastic | ![Plastic Badge](https://readthedocs.org/projects/pip/badge/?version=latest&style=plastic)
social | ![Social Badge](https://readthedocs.org/projects/pip/badge/?version=latest&style=social)


Project Pages
-------------

You will now see badges embedded in your `project page`_.
The default badge will be pointed at the *default version* you have specified for your project.
The badge URLs look like this::

https://readthedocs.org/projects/pip/badge/?version=latest
https://readthedocs.org/projects/pip/badge/?version=latest&style=plastic

You can replace the version argument with any version that you want to show a badge for.
If you click on the badge icon,
Expand All @@ -47,4 +63,4 @@ since it will stay up to date with your Read the Docs project::
.. |red| image:: https://media.readthedocs.org/static/projects/badges/failing.svg
.. |yellow| image:: https://media.readthedocs.org/static/projects/badges/unknown.svg
.. |nbsp| unicode:: 0xA0
:trim:
:trim:
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 4 additions & 1 deletion readthedocs/projects/views/public.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,10 @@ def get_context_data(self, **kwargs):
@never_cache
def project_badge(request, project_slug):
"""Return a sweet badge for the project."""
badge_path = 'projects/badges/%s.svg'
style = request.GET.get('style', 'flat')
if style not in ("flat", "plastic", "flat-square", "for-the-badge", "social"):
style = "flat"
badge_path = 'projects/badges/%s-' + style + '.svg'
version_slug = request.GET.get('version', LATEST)
try:
version = Version.objects.public(request.user).get(
Expand Down
Loading

0 comments on commit 8aa4262

Please sign in to comment.