comparison libervia/backend/tools/common/template.py @ 4084:f742f28b3934

tools/common (template): add `id` argument to `_icon_use`
author Goffi <goffi@goffi.org>
date Wed, 07 Jun 2023 22:26:54 +0200
parents 84f6bee6440d
children e7ee611fc860
comparison
equal deleted inserted replaced
4083:2ea567afc0cf 4084:f742f28b3934
953 if not icon_svg_elt.tag == "{http://www.w3.org/2000/svg}svg": 953 if not icon_svg_elt.tag == "{http://www.w3.org/2000/svg}svg":
954 raise exceptions.DataError("invalid SVG element") 954 raise exceptions.DataError("invalid SVG element")
955 defs_elt.append(icon_svg_elt) 955 defs_elt.append(icon_svg_elt)
956 return safe(etree.tostring(svg_elt, encoding="unicode")) 956 return safe(etree.tostring(svg_elt, encoding="unicode"))
957 957
958 def _icon_use(self, name, cls=""): 958 def _icon_use(self, name, cls="", id=""):
959 return safe('<svg class="svg-icon{cls}" xmlns="http://www.w3.org/2000/svg" ' 959 if id:
960 id = id.replace('"', '_')
961 return safe('<svg class="svg-icon{cls}"{id} xmlns="http://www.w3.org/2000/svg" '
960 'viewBox="0 0 100 100">\n' 962 'viewBox="0 0 100 100">\n'
961 ' <use href="#{name}"/>' 963 ' <use href="#{name}"/>'
962 '</svg>\n'.format(name=name, cls=(" " + cls) if cls else "")) 964 '</svg>\n'.format(
965 name=name,
966 cls=(" " + cls) if cls else "",
967 id=f' id="{id}"' if id else ""
968 )
969 )
963 970
964 def _icon_from_client(self, client): 971 def _icon_from_client(self, client):
965 """Get icon name to represent a disco client""" 972 """Get icon name to represent a disco client"""
966 if client is None: 973 if client is None:
967 return 'desktop' 974 return 'desktop'