Coverage for app/venv/lib/python3.14/site-packages/weblate/utils/templatetags/icons.py: 93%

14 statements  

« prev     ^ index     » next       coverage.py v7.15.2, created at 2026-10-07 07:15 +0000

1# Copyright © Michal Čihař <michal@weblate.org> 

2# 

3# SPDX-License-Identifier: GPL-3.0-or-later 

4 

5from __future__ import annotations 

6 

7from django import template 

8from django.utils.html import format_html 

9from django.utils.safestring import mark_safe 

10 

11from weblate.utils.icons import load_icon 

12 

13register = template.Library() 

14 

15ICONS_CACHE: dict[str, str] = {} 

16 

17SPIN = '<span class="icon-spin" {} {}>{}</span>' 

18 

19 

20@register.simple_tag 

21def icon(name: str) -> str: 

22 """ 

23 Inlines SVG icon. 

24 

25 Inlining is necessary to be able to apply CSS styles on the path. 

26 """ 

27 return mark_safe(load_icon(name).decode()) # noqa: S308 

28 

29 

30@register.simple_tag 

31def loading_icon(name=None, hidden=True): 

32 return format_html( 

33 SPIN, 

34 format_html('id="loading-{}"', name) if name else "", 

35 mark_safe('style="display: none"') if hidden else "", 

36 icon("loading.svg"), 

37 )