From 56ae853ca0f7255cc669d802b741922fd8670c3b Mon Sep 17 00:00:00 2001 From: wxiaoguang Date: Sun, 7 May 2023 17:49:46 +0800 Subject: 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):
![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)
--- services/gitdiff/gitdiff.go | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'services/gitdiff') 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 -- cgit v1.2.3