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:
parent
377e0139b0
commit
56ae853ca0
6 changed files with 20 additions and 21 deletions
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue