diff --git a/docs/badges.rst b/docs/badges.rst
index fcdb8dc76c7..d8d5f10b3d7 100644
--- a/docs/badges.rst
+++ b/docs/badges.rst
@@ -19,6 +19,22 @@ 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
-------------
@@ -26,7 +42,7 @@ 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,
@@ -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:
\ No newline at end of file
diff --git a/readthedocs/projects/static/projects/badges/failing-flat-square.svg b/readthedocs/projects/static/projects/badges/failing-flat-square.svg
new file mode 100644
index 00000000000..b962087a960
--- /dev/null
+++ b/readthedocs/projects/static/projects/badges/failing-flat-square.svg
@@ -0,0 +1 @@
+
\ No newline at end of file
diff --git a/readthedocs/projects/static/projects/badges/failing.svg b/readthedocs/projects/static/projects/badges/failing-flat.svg
similarity index 60%
rename from readthedocs/projects/static/projects/badges/failing.svg
rename to readthedocs/projects/static/projects/badges/failing-flat.svg
index c9ff866c6f0..efd7d091ea9 100644
--- a/readthedocs/projects/static/projects/badges/failing.svg
+++ b/readthedocs/projects/static/projects/badges/failing-flat.svg
@@ -1 +1 @@
-
\ No newline at end of file
+
\ No newline at end of file
diff --git a/readthedocs/projects/static/projects/badges/failing-for-the-badge.svg b/readthedocs/projects/static/projects/badges/failing-for-the-badge.svg
new file mode 100644
index 00000000000..026369a5615
--- /dev/null
+++ b/readthedocs/projects/static/projects/badges/failing-for-the-badge.svg
@@ -0,0 +1 @@
+
\ No newline at end of file
diff --git a/readthedocs/projects/static/projects/badges/failing-plastic.svg b/readthedocs/projects/static/projects/badges/failing-plastic.svg
new file mode 100644
index 00000000000..4fadaf7b363
--- /dev/null
+++ b/readthedocs/projects/static/projects/badges/failing-plastic.svg
@@ -0,0 +1 @@
+
\ No newline at end of file
diff --git a/readthedocs/projects/static/projects/badges/failing-social.svg b/readthedocs/projects/static/projects/badges/failing-social.svg
new file mode 100644
index 00000000000..a72c1c138c5
--- /dev/null
+++ b/readthedocs/projects/static/projects/badges/failing-social.svg
@@ -0,0 +1 @@
+
\ No newline at end of file
diff --git a/readthedocs/projects/static/projects/badges/passing-flat-square.svg b/readthedocs/projects/static/projects/badges/passing-flat-square.svg
new file mode 100644
index 00000000000..0940a34ae9f
--- /dev/null
+++ b/readthedocs/projects/static/projects/badges/passing-flat-square.svg
@@ -0,0 +1 @@
+
\ No newline at end of file
diff --git a/readthedocs/projects/static/projects/badges/passing.svg b/readthedocs/projects/static/projects/badges/passing-flat.svg
similarity index 54%
rename from readthedocs/projects/static/projects/badges/passing.svg
rename to readthedocs/projects/static/projects/badges/passing-flat.svg
index 39ff2cbda3a..c387fcc6808 100644
--- a/readthedocs/projects/static/projects/badges/passing.svg
+++ b/readthedocs/projects/static/projects/badges/passing-flat.svg
@@ -1 +1 @@
-
\ No newline at end of file
+
\ No newline at end of file
diff --git a/readthedocs/projects/static/projects/badges/passing-for-the-badge.svg b/readthedocs/projects/static/projects/badges/passing-for-the-badge.svg
new file mode 100644
index 00000000000..98109fb22b9
--- /dev/null
+++ b/readthedocs/projects/static/projects/badges/passing-for-the-badge.svg
@@ -0,0 +1 @@
+
\ No newline at end of file
diff --git a/readthedocs/projects/static/projects/badges/passing-plastic.svg b/readthedocs/projects/static/projects/badges/passing-plastic.svg
new file mode 100644
index 00000000000..6f8a7f0d024
--- /dev/null
+++ b/readthedocs/projects/static/projects/badges/passing-plastic.svg
@@ -0,0 +1 @@
+
\ No newline at end of file
diff --git a/readthedocs/projects/static/projects/badges/passing-social.svg b/readthedocs/projects/static/projects/badges/passing-social.svg
new file mode 100644
index 00000000000..749da15d2f3
--- /dev/null
+++ b/readthedocs/projects/static/projects/badges/passing-social.svg
@@ -0,0 +1 @@
+
\ No newline at end of file
diff --git a/readthedocs/projects/static/projects/badges/unknown-flat-square.svg b/readthedocs/projects/static/projects/badges/unknown-flat-square.svg
new file mode 100644
index 00000000000..56a974b3b18
--- /dev/null
+++ b/readthedocs/projects/static/projects/badges/unknown-flat-square.svg
@@ -0,0 +1 @@
+
\ No newline at end of file
diff --git a/readthedocs/projects/static/projects/badges/unknown.svg b/readthedocs/projects/static/projects/badges/unknown-flat.svg
similarity index 60%
rename from readthedocs/projects/static/projects/badges/unknown.svg
rename to readthedocs/projects/static/projects/badges/unknown-flat.svg
index 1514f0526ba..86371bf284b 100644
--- a/readthedocs/projects/static/projects/badges/unknown.svg
+++ b/readthedocs/projects/static/projects/badges/unknown-flat.svg
@@ -1 +1 @@
-
\ No newline at end of file
+
\ No newline at end of file
diff --git a/readthedocs/projects/static/projects/badges/unknown-for-the-badge.svg b/readthedocs/projects/static/projects/badges/unknown-for-the-badge.svg
new file mode 100644
index 00000000000..30de983dad8
--- /dev/null
+++ b/readthedocs/projects/static/projects/badges/unknown-for-the-badge.svg
@@ -0,0 +1 @@
+
\ No newline at end of file
diff --git a/readthedocs/projects/static/projects/badges/unknown-plastic.svg b/readthedocs/projects/static/projects/badges/unknown-plastic.svg
new file mode 100644
index 00000000000..de44b38f373
--- /dev/null
+++ b/readthedocs/projects/static/projects/badges/unknown-plastic.svg
@@ -0,0 +1 @@
+
\ No newline at end of file
diff --git a/readthedocs/projects/static/projects/badges/unknown-social.svg b/readthedocs/projects/static/projects/badges/unknown-social.svg
new file mode 100644
index 00000000000..418db684db3
--- /dev/null
+++ b/readthedocs/projects/static/projects/badges/unknown-social.svg
@@ -0,0 +1 @@
+
\ No newline at end of file
diff --git a/readthedocs/projects/views/public.py b/readthedocs/projects/views/public.py
index 61f6cfeca64..2068cf55ca4 100644
--- a/readthedocs/projects/views/public.py
+++ b/readthedocs/projects/views/public.py
@@ -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(
diff --git a/readthedocs/rtd_tests/tests/test_project_views.py b/readthedocs/rtd_tests/tests/test_project_views.py
index b52dbe40f75..313a38e6343 100644
--- a/readthedocs/rtd_tests/tests/test_project_views.py
+++ b/readthedocs/rtd_tests/tests/test_project_views.py
@@ -424,25 +424,41 @@ def get_project_queryset(self):
class TestBadges(TestCase):
"""Test a static badge asset is served for each build."""
+ # To set `flat` as default style as done in code.
+ def get_badge_path(self, version, style='flat'):
+ return static(self.BADGE_PATH % (version, style))
+
def setUp(self):
- self.BADGE_PATH = 'projects/badges/%s.svg'
+ self.BADGE_PATH = 'projects/badges/%s-%s.svg'
self.project = get(Project, slug='badgey')
self.version = Version.objects.get(project=self.project)
self.badge_url = reverse('project_badge', args=[self.project.slug])
def test_unknown_badge(self):
res = self.client.get(self.badge_url, {'version': self.version.slug})
- static_badge = static(self.BADGE_PATH % 'unknown')
+ static_badge = self.get_badge_path('unknown')
self.assertEquals(res.url, static_badge)
def test_passing_badge(self):
get(Build, project=self.project, version=self.version, success=True)
res = self.client.get(self.badge_url, {'version': self.version.slug})
- static_badge = static(self.BADGE_PATH % 'passing')
+ static_badge = self.get_badge_path('passing')
self.assertEquals(res.url, static_badge)
def test_failing_badge(self):
get(Build, project=self.project, version=self.version, success=False)
res = self.client.get(self.badge_url, {'version': self.version.slug})
- static_badge = static(self.BADGE_PATH % 'failing')
+ static_badge = self.get_badge_path('failing')
+ self.assertEquals(res.url, static_badge)
+
+ def test_plastic_failing_badge(self):
+ get(Build, project=self.project, version=self.version, success=False)
+ res = self.client.get(self.badge_url, {'version': self.version.slug, 'style': 'plastic'})
+ static_badge = self.get_badge_path('failing', 'plastic')
+ self.assertEquals(res.url, static_badge)
+
+ def test_social_passing_badge(self):
+ get(Build, project=self.project, version=self.version, success=True)
+ res = self.client.get(self.badge_url, {'version': self.version.slug , 'style': 'social'})
+ static_badge = self.get_badge_path('passing', 'social')
self.assertEquals(res.url, static_badge)