@@ -35,6 +35,7 @@ import (
35
35
"code.gitea.io/gitea/modules/emoji"
36
36
"code.gitea.io/gitea/modules/git"
37
37
giturl "code.gitea.io/gitea/modules/git/url"
38
+ gitea_html "code.gitea.io/gitea/modules/html"
38
39
"code.gitea.io/gitea/modules/json"
39
40
"code.gitea.io/gitea/modules/log"
40
41
"code.gitea.io/gitea/modules/markup"
@@ -348,7 +349,7 @@ func NewFuncMap() []template.FuncMap {
348
349
}
349
350
return false
350
351
},
351
- "svg" : SVG ,
352
+ "svg" : svg . RenderHTML ,
352
353
"avatar" : Avatar ,
353
354
"avatarHTML" : AvatarHTML ,
354
355
"avatarByAction" : AvatarByAction ,
@@ -363,17 +364,17 @@ func NewFuncMap() []template.FuncMap {
363
364
if len (urlSort ) == 0 && isDefault {
364
365
// if sort is sorted as default add arrow tho this table header
365
366
if isDefault {
366
- return SVG ("octicon-triangle-down" , 16 )
367
+ return svg . RenderHTML ("octicon-triangle-down" , 16 )
367
368
}
368
369
} else {
369
370
// if sort arg is in url test if it correlates with column header sort arguments
370
371
// the direction of the arrow should indicate the "current sort order", up means ASC(normal), down means DESC(rev)
371
372
if urlSort == normSort {
372
373
// the table is sorted with this header normal
373
- return SVG ("octicon-triangle-up" , 16 )
374
+ return svg . RenderHTML ("octicon-triangle-up" , 16 )
374
375
} else if urlSort == revSort {
375
376
// the table is sorted with this header reverse
376
- return SVG ("octicon-triangle-down" , 16 )
377
+ return svg . RenderHTML ("octicon-triangle-down" , 16 )
377
378
}
378
379
}
379
380
// the table is NOT sorted with this header
@@ -594,29 +595,6 @@ func NewTextFuncMap() []texttmpl.FuncMap {
594
595
}}
595
596
}
596
597
597
- var (
598
- widthRe = regexp .MustCompile (`width="[0-9]+?"` )
599
- heightRe = regexp .MustCompile (`height="[0-9]+?"` )
600
- )
601
-
602
- func parseOthers (defaultSize int , defaultClass string , others ... interface {}) (int , string ) {
603
- size := defaultSize
604
- if len (others ) > 0 && others [0 ].(int ) != 0 {
605
- size = others [0 ].(int )
606
- }
607
-
608
- class := defaultClass
609
- if len (others ) > 1 && others [1 ].(string ) != "" {
610
- if defaultClass == "" {
611
- class = others [1 ].(string )
612
- } else {
613
- class = defaultClass + " " + others [1 ].(string )
614
- }
615
- }
616
-
617
- return size , class
618
- }
619
-
620
598
// AvatarHTML creates the HTML for an avatar
621
599
func AvatarHTML (src string , size int , class , name string ) template.HTML {
622
600
sizeStr := fmt .Sprintf (`%d` , size )
@@ -628,26 +606,9 @@ func AvatarHTML(src string, size int, class, name string) template.HTML {
628
606
return template .HTML (`<img class="` + class + `" src="` + src + `" title="` + html .EscapeString (name ) + `" width="` + sizeStr + `" height="` + sizeStr + `"/>` )
629
607
}
630
608
631
- // SVG render icons - arguments icon name (string), size (int), class (string)
632
- func SVG (icon string , others ... interface {}) template.HTML {
633
- size , class := parseOthers (16 , "" , others ... )
634
-
635
- if svgStr , ok := svg .SVGs [icon ]; ok {
636
- if size != 16 {
637
- svgStr = widthRe .ReplaceAllString (svgStr , fmt .Sprintf (`width="%d"` , size ))
638
- svgStr = heightRe .ReplaceAllString (svgStr , fmt .Sprintf (`height="%d"` , size ))
639
- }
640
- if class != "" {
641
- svgStr = strings .Replace (svgStr , `class="` , fmt .Sprintf (`class="%s ` , class ), 1 )
642
- }
643
- return template .HTML (svgStr )
644
- }
645
- return template .HTML ("" )
646
- }
647
-
648
609
// Avatar renders user avatars. args: user, size (int), class (string)
649
610
func Avatar (item interface {}, others ... interface {}) template.HTML {
650
- size , class := parseOthers (avatars .DefaultAvatarPixelSize , "ui avatar vm" , others ... )
611
+ size , class := gitea_html . ParseSizeAndClass (avatars .DefaultAvatarPixelSize , "ui avatar vm" , others ... )
651
612
652
613
switch t := item .(type ) {
653
614
case * user_model.User :
@@ -678,7 +639,7 @@ func AvatarByAction(action *activities_model.Action, others ...interface{}) temp
678
639
679
640
// RepoAvatar renders repo avatars. args: repo, size(int), class (string)
680
641
func RepoAvatar (repo * repo_model.Repository , others ... interface {}) template.HTML {
681
- size , class := parseOthers (avatars .DefaultAvatarPixelSize , "ui avatar" , others ... )
642
+ size , class := gitea_html . ParseSizeAndClass (avatars .DefaultAvatarPixelSize , "ui avatar" , others ... )
682
643
683
644
src := repo .RelAvatarLink ()
684
645
if src != "" {
@@ -689,7 +650,7 @@ func RepoAvatar(repo *repo_model.Repository, others ...interface{}) template.HTM
689
650
690
651
// AvatarByEmail renders avatars by email address. args: email, name, size (int), class (string)
691
652
func AvatarByEmail (email , name string , others ... interface {}) template.HTML {
692
- size , class := parseOthers (avatars .DefaultAvatarPixelSize , "ui avatar" , others ... )
653
+ size , class := gitea_html . ParseSizeAndClass (avatars .DefaultAvatarPixelSize , "ui avatar" , others ... )
693
654
src := avatars .GenerateEmailAvatarFastLink (email , size * setting .Avatar .RenderedSizeFactor )
694
655
695
656
if src != "" {
0 commit comments