diff options
author | silverwind <me@silverwind.io> | 2020-09-08 19:17:56 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-09-08 13:17:56 -0400 |
commit | 3865ecbf13b5091be6a03913c1a83f361228d556 (patch) | |
tree | b4168776eeedb90adb8e0e00981ce161dd1f395b /modules/templates | |
parent | e2043987543d6b1e94afc22d145d70ddaf814898 (diff) | |
download | gitea-3865ecbf13b5091be6a03913c1a83f361228d556.tar.gz gitea-3865ecbf13b5091be6a03913c1a83f361228d556.zip |
File header tweaks, add CSS helpers (#12635)
- replace two instances of fontawesome with octicons
- add new "class" optional argument to "svg" helper
- add many new CSS helpers and move their import to the end for
increaseed precedence
Co-authored-by: zeripath <art27@cantab.net>
Co-authored-by: techknowlogick <techknowlogick@gitea.io>
Diffstat (limited to 'modules/templates')
-rw-r--r-- | modules/templates/helper.go | 14 |
1 files changed, 12 insertions, 2 deletions
diff --git a/modules/templates/helper.go b/modules/templates/helper.go index f86287f10b..c5526b3dea 100644 --- a/modules/templates/helper.go +++ b/modules/templates/helper.go @@ -468,13 +468,23 @@ func NewTextFuncMap() []texttmpl.FuncMap { var widthRe = regexp.MustCompile(`width="[0-9]+?"`) var heightRe = regexp.MustCompile(`height="[0-9]+?"`) -// SVG render icons -func SVG(icon string, size int) template.HTML { +// SVG render icons - arguments icon name (string), size (int), class (string) +func SVG(icon string, others ...interface{}) template.HTML { + var size = others[0].(int) + + class := "" + if len(others) > 1 && others[1].(string) != "" { + class = others[1].(string) + } + if svgStr, ok := svg.SVGs[icon]; ok { if size != 16 { svgStr = widthRe.ReplaceAllString(svgStr, fmt.Sprintf(`width="%d"`, size)) svgStr = heightRe.ReplaceAllString(svgStr, fmt.Sprintf(`height="%d"`, size)) } + if class != "" { + svgStr = strings.Replace(svgStr, `class="`, fmt.Sprintf(`class="%s `, class), 1) + } return template.HTML(svgStr) } return template.HTML("") |