mirror of
https://gitcode.com/gitea/gitea.git
synced 2025-10-24 09:13:40 +08:00
Simplify template helper functions (#24570)
To avoid bloating the template helper functions, some functions could be
provided by type methods.
And the new code `data-line-type="{{.GetHTMLDiffLineType}}"` reads
better than `data-line-type="{{DiffLineTypeToStr .GetType}}"`
After the fix, screenshots (the same as before):
<details>


</details>
This commit is contained in:
@ -104,6 +104,19 @@ func (d *DiffLine) GetType() int {
|
||||
return int(d.Type)
|
||||
}
|
||||
|
||||
// GetHTMLDiffLineType returns the diff line type name for HTML
|
||||
func (d *DiffLine) GetHTMLDiffLineType() string {
|
||||
switch d.Type {
|
||||
case DiffLineAdd:
|
||||
return "add"
|
||||
case DiffLineDel:
|
||||
return "del"
|
||||
case DiffLineSection:
|
||||
return "tag"
|
||||
}
|
||||
return "same"
|
||||
}
|
||||
|
||||
// CanComment returns whether a line can get commented
|
||||
func (d *DiffLine) CanComment() bool {
|
||||
return len(d.Comments) == 0 && d.Type != DiffLineSection
|
||||
|
||||
Reference in New Issue
Block a user