mirror of
https://github.com/google/pybadges.git
synced 2026-01-05 10:50:08 +01:00
Support the title element
This commit is contained in:
@@ -117,7 +117,11 @@ def badge(left_text: str, right_text: str, left_link: Optional[str] = None,
|
||||
whole_link: Optional[str] = None, logo: Optional[str] = None,
|
||||
left_color: str = '#555', right_color: str = '#007ec6',
|
||||
measurer: Optional[text_measurer.TextMeasurer] = None,
|
||||
embed_logo: bool = False) -> str:
|
||||
embed_logo: bool = False,
|
||||
whole_title: Optional[str] = None,
|
||||
left_title: Optional[str] = None,
|
||||
right_title: Optional[str] = None,
|
||||
) -> str:
|
||||
"""Creates a github-style badge as an SVG image.
|
||||
|
||||
>>> badge(left_text='coverage', right_text='23%', right_color='red')
|
||||
@@ -181,6 +185,9 @@ def badge(left_text: str, right_text: str, left_link: Optional[str] = None,
|
||||
logo=logo,
|
||||
left_color=_NAME_TO_COLOR.get(left_color, left_color),
|
||||
right_color=_NAME_TO_COLOR.get(right_color, right_color),
|
||||
whole_title=whole_title,
|
||||
left_title=left_title,
|
||||
right_title=right_title,
|
||||
)
|
||||
xml = minidom.parseString(svg)
|
||||
_remove_blanks(xml)
|
||||
|
||||
@@ -92,6 +92,20 @@ def main():
|
||||
help='the path to the ttf font file containing DejaVu Sans. If not ' +
|
||||
'present on your system, you can download it from ' +
|
||||
'https://www.fontsquirrel.com/fonts/dejavu-sans')
|
||||
parser.add_argument(
|
||||
'--whole-title',
|
||||
default=None,
|
||||
help='the url to redirect to when the badge is clicked')
|
||||
parser.add_argument(
|
||||
'--left-title',
|
||||
default=None,
|
||||
help='the url to redirect to when the left-hand of the badge is ' +
|
||||
'clicked')
|
||||
parser.add_argument(
|
||||
'--right-title',
|
||||
default=None,
|
||||
help='the url to redirect to when the right-hand of the badge is ' +
|
||||
'clicked')
|
||||
|
||||
args = parser.parse_args()
|
||||
|
||||
@@ -120,7 +134,10 @@ def main():
|
||||
right_color=args.right_color,
|
||||
logo=args.logo,
|
||||
measurer=measurer,
|
||||
embed_logo=args.embed_logo)
|
||||
embed_logo=args.embed_logo,
|
||||
whole_title=args.whole_title,
|
||||
left_title=args.left_title,
|
||||
right_title=args.right_title)
|
||||
|
||||
if args.browser:
|
||||
_, badge_path = tempfile.mkstemp(suffix='.svg')
|
||||
|
||||
@@ -3,6 +3,9 @@
|
||||
{% set left_width = left_text_width + 10 + logo_width + logo_padding %}
|
||||
{% set right_width = right_text_width + 10 %}
|
||||
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="{{ left_width + right_width }}" height="20">
|
||||
{% if whole_title %}
|
||||
<title>{{ whole_title }}</title>
|
||||
{% endif %}
|
||||
<linearGradient id="smooth" x2="0" y2="100%">
|
||||
<stop offset="0" stop-color="#bbb" stop-opacity=".1"/>
|
||||
<stop offset="1" stop-opacity=".1"/>
|
||||
@@ -13,8 +16,16 @@
|
||||
</clipPath>
|
||||
|
||||
<g clip-path="url(#round)">
|
||||
<rect width="{{ left_width }}" height="20" fill="{{ left_color }}"/>
|
||||
<rect x="{{ left_width }}" width="{{ right_width }}" height="20" fill="{{ right_color }}"/>
|
||||
<rect width="{{ left_width }}" height="20" fill="{{ left_color }}">
|
||||
{% if left_title %}
|
||||
<title>{{ left_title }}</title>
|
||||
{% endif %}
|
||||
</rect>
|
||||
<rect x="{{ left_width }}" width="{{ right_width }}" height="20" fill="{{ right_color }}">
|
||||
{% if right_title %}
|
||||
<title>{{ right_title }}</title>
|
||||
{% endif %}
|
||||
</rect>
|
||||
<rect width="{{ left_width + right_width }}" height="20" fill="url(#smooth)"/>
|
||||
</g>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user