mirror of
https://github.com/google/pybadges.git
synced 2026-01-06 03:10:07 +01:00
Made right_text optional
This commit is contained in:
@@ -114,7 +114,7 @@ def _embed_image(url: str) -> str:
|
||||
|
||||
def badge(
|
||||
left_text: str,
|
||||
right_text: str,
|
||||
right_text: Optional[str] = None,
|
||||
left_link: Optional[str] = None,
|
||||
right_link: Optional[str] = None,
|
||||
whole_link: Optional[str] = None,
|
||||
@@ -190,11 +190,15 @@ def badge(
|
||||
if logo and embed_logo:
|
||||
logo = _embed_image(logo)
|
||||
|
||||
right_text_width = None
|
||||
if right_text:
|
||||
right_text_width = measurer.text_width(right_text) / 10.0
|
||||
|
||||
svg = template.render(
|
||||
left_text=left_text,
|
||||
right_text=right_text,
|
||||
left_text_width=measurer.text_width(left_text) / 10.0,
|
||||
right_text_width=measurer.text_width(right_text) / 10.0,
|
||||
right_text_width=right_text_width,
|
||||
left_link=left_link,
|
||||
right_link=right_link,
|
||||
whole_link=whole_link,
|
||||
|
||||
@@ -37,7 +37,7 @@ def main():
|
||||
help='the text to show on the left-hand-side of the badge')
|
||||
parser.add_argument(
|
||||
'--right-text',
|
||||
default='APACHE',
|
||||
default=None,
|
||||
help='the text to show on the right-hand-side of the badge')
|
||||
parser.add_argument('--whole-link',
|
||||
default=None,
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{% set logo_width = 14 if logo else 0 %}
|
||||
{% set logo_padding = 3 if (logo and left_text) else 0 %}
|
||||
{% set left_width = left_text_width + 10 + logo_width + logo_padding %}
|
||||
{% set right_width = right_text_width + 10 %}
|
||||
{% set right_width = right_text_width + 10 if right_text_width else 0 %}
|
||||
{% set id_smooth = 'smooth' + id_suffix %}
|
||||
{% set id_round = 'round' + id_suffix %}
|
||||
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="{{ left_width + right_width }}" height="20">
|
||||
@@ -37,8 +37,10 @@
|
||||
{% endif %}
|
||||
<text x="{{ (((left_width+logo_width+logo_padding)/2)+1)*10 }}" y="150" fill="#010101" fill-opacity=".3" transform="scale(0.1)" textLength="{{ (left_width-(10+logo_width+logo_padding))*10 }}" lengthAdjust="spacing">{{ left_text }}</text>
|
||||
<text x="{{ (((left_width+logo_width+logo_padding)/2)+1)*10 }}" y="140" transform="scale(0.1)" textLength="{{ (left_width-(10+logo_width+logo_padding))*10 }}" lengthAdjust="spacing">{{ left_text }}</text>
|
||||
{% if right_text %}
|
||||
<text x="{{ (left_width+right_width/2-1)*10 }}" y="150" fill="#010101" fill-opacity=".3" transform="scale(0.1)" textLength="{{ (right_width-10)*10 }}" lengthAdjust="spacing">{{ right_text }}</text>
|
||||
<text x="{{ (left_width+right_width/2-1)*10 }}" y="140" transform="scale(0.1)" textLength="{{ (right_width-10)*10 }}" lengthAdjust="spacing">{{ right_text}}</text>
|
||||
<text x="{{ (left_width+right_width/2-1)*10 }}" y="140" transform="scale(0.1)" textLength="{{ (right_width-10)*10 }}" lengthAdjust="spacing">{{ right_text }}</text>
|
||||
{% endif %}
|
||||
|
||||
{% if left_link or whole_link %}
|
||||
<a xlink:href="{{ left_link or wholelink }}">
|
||||
|
||||
Reference in New Issue
Block a user