diff options
author | wxiaoguang <wxiaoguang@gmail.com> | 2023-05-07 17:49:46 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-05-07 09:49:46 +0000 |
commit | 56ae853ca0f7255cc669d802b741922fd8670c3b (patch) | |
tree | 132ba83a8a238e1119738416083f17c668ee3442 /services/gitdiff | |
parent | 377e0139b0233f2b5419af42ad783f82cf9ce0ba (diff) | |
download | gitea-56ae853ca0f7255cc669d802b741922fd8670c3b.tar.gz gitea-56ae853ca0f7255cc669d802b741922fd8670c3b.zip |
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>
![image](https://user-images.githubusercontent.com/2114189/236657918-20ce01e0-1192-443e-aeb4-6b3fe1aa2102.png)
![image](https://user-images.githubusercontent.com/2114189/236657950-ee19727f-a1fc-4133-afc7-e5d1a8c1783f.png)
</details>
Diffstat (limited to 'services/gitdiff')
-rw-r--r-- | services/gitdiff/gitdiff.go | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/services/gitdiff/gitdiff.go b/services/gitdiff/gitdiff.go index c50e8137ab..73474cf248 100644 --- a/services/gitdiff/gitdiff.go +++ b/services/gitdiff/gitdiff.go @@ -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 |