Repository: clld/clldutils

Issue:
The `badge` function should be more flexible
`badge.badge` should accept all atomic parts of the label/URL it creates as input argument; such that it exposes all functionality of the `shields.io` service.

Discussion:

Patch:
diff --git a/clldutils/badge.py b/clldutils/badge.py
index 14829b5..a74fca1 100644
--- a/clldutils/badge.py
+++ b/clldutils/badge.py
@@ -19,12 +19,8 @@ class Colors(object):
     blue = 'blue'
 
 
-def badge(subject, status, color, fmt='svg', markdown=True, **kw):
-    query = ''
-    if kw:
-        query = '?' + urlencode(kw)
+def badge(subject, status, color, fmt='svg', markdown=True, label=None, **kw):
+    label = label or ': '.join([subject, status])
     url = 'https://img.shields.io/badge/{0}-{1}-{2}.{3}{4}'.format(
-        quote(subject), quote(status), color, fmt, query)
-    if markdown:
-        return '![{0}]({1} "{0}")'.format(': '.join([subject, status]), url)
-    return url
+        quote(subject), quote(status), color, fmt, '?' + urlencode(kw) if kw else '')
+    return '![{0}]({1} "{0}")'.format(label, url) if markdown else url


Test patch:
diff --git a/clldutils/tests/test_badge.py b/clldutils/tests/test_badge.py
index 272560c..66bcabb 100644
--- a/clldutils/tests/test_badge.py
+++ b/clldutils/tests/test_badge.py
@@ -12,3 +12,4 @@ def test_badge():
         '![cov: 20%](https://img.shields.io/badge/cov-20%25-orange.svg "cov: 20%")'
     assert _badge(markdown=False, style='plastic') == \
         'https://img.shields.io/badge/cov-20%25-orange.svg?style=plastic'
+    assert '[abc]' in badge('subject', 'status', 'color', label='abc')