tools (common/template): new icon_from_client method:

this method is available from template, and returns the name of the icon to use according
to disco client data.
This commit is contained in:
Goffi 2020-05-18 23:41:36 +02:00
commit 205bd5cdb4

View file

@ -911,6 +911,21 @@ class Renderer(object):
' <use href="#{name}"/>'
'</svg>\n'.format(name=name, cls=(" " + cls) if cls else ""))
def _icon_from_client(self, client):
"""Get icon name to represent a disco client"""
if client is None:
return 'desktop'
elif 'pc' in client:
return 'desktop'
elif 'phone' in client:
return 'mobile'
elif 'web' in client:
return 'globe'
elif 'console' in client:
return 'terminal'
else:
return 'desktop'
def render(self, template, site=None, theme=None, locale=C.DEFAULT_LOCALE,
media_path="", css_files=None, css_inline=False, **kwargs):
"""Render a template
@ -963,6 +978,7 @@ class Renderer(object):
kwargs["icon_defs"] = self._icon_defs
kwargs["icon"] = self._icon_use
kwargs["icon_from_client"] = self._icon_from_client
if css_inline:
css_contents = []