comparison sat/tools/common/template.py @ 3274:430204a3cc10

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.
author Goffi <goffi@goffi.org>
date Mon, 18 May 2020 23:41:36 +0200
parents 85c9cfcd4f5e
children 3af0909629a2
comparison
equal deleted inserted replaced
3273:4230aaeab9a7 3274:430204a3cc10
909 return safe('<svg class="svg-icon{cls}" xmlns="http://www.w3.org/2000/svg" ' 909 return safe('<svg class="svg-icon{cls}" xmlns="http://www.w3.org/2000/svg" '
910 'viewBox="0 0 100 100">\n' 910 'viewBox="0 0 100 100">\n'
911 ' <use href="#{name}"/>' 911 ' <use href="#{name}"/>'
912 '</svg>\n'.format(name=name, cls=(" " + cls) if cls else "")) 912 '</svg>\n'.format(name=name, cls=(" " + cls) if cls else ""))
913 913
914 def _icon_from_client(self, client):
915 """Get icon name to represent a disco client"""
916 if client is None:
917 return 'desktop'
918 elif 'pc' in client:
919 return 'desktop'
920 elif 'phone' in client:
921 return 'mobile'
922 elif 'web' in client:
923 return 'globe'
924 elif 'console' in client:
925 return 'terminal'
926 else:
927 return 'desktop'
928
914 def render(self, template, site=None, theme=None, locale=C.DEFAULT_LOCALE, 929 def render(self, template, site=None, theme=None, locale=C.DEFAULT_LOCALE,
915 media_path="", css_files=None, css_inline=False, **kwargs): 930 media_path="", css_files=None, css_inline=False, **kwargs):
916 """Render a template 931 """Render a template
917 932
918 @param template(unicode): template to render (e.g. blog/articles.html) 933 @param template(unicode): template to render (e.g. blog/articles.html)
961 if css_files is None: 976 if css_files is None:
962 css_files, css_files_noscript = self.getCSSFiles(template_data) 977 css_files, css_files_noscript = self.getCSSFiles(template_data)
963 978
964 kwargs["icon_defs"] = self._icon_defs 979 kwargs["icon_defs"] = self._icon_defs
965 kwargs["icon"] = self._icon_use 980 kwargs["icon"] = self._icon_use
981 kwargs["icon_from_client"] = self._icon_from_client
966 982
967 if css_inline: 983 if css_inline:
968 css_contents = [] 984 css_contents = []
969 for files, suffix in ((css_files, ""), 985 for files, suffix in ((css_files, ""),
970 (css_files_noscript, "_noscript")): 986 (css_files_noscript, "_noscript")):