From d160c7e565ef3c3429ca601b5a10b13949579b36 Mon Sep 17 00:00:00 2001 From: Andrey Nering Date: Sun, 21 Feb 2016 18:45:24 -0300 Subject: [PATCH] Little refactoring of diff highlight. Moving cache variable to template instead of in the struct. --- models/git_diff.go | 6 +----- templates/repo/diff_box.tmpl | 7 ++++--- 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/models/git_diff.go b/models/git_diff.go index 9796ef59f8d..ab70139fb36 100644 --- a/models/git_diff.go +++ b/models/git_diff.go @@ -161,7 +161,6 @@ type DiffFile struct { IsBin bool IsRenamed bool Sections []*DiffSection - HighlightClass string } func (diffFile *DiffFile) GetType() int { @@ -169,10 +168,7 @@ func (diffFile *DiffFile) GetType() int { } func (diffFile *DiffFile) GetHighlightClass() string { - if diffFile.HighlightClass == "" { - diffFile.HighlightClass = highlight.FileNameToHighlightClass(diffFile.Name) - } - return diffFile.HighlightClass + return highlight.FileNameToHighlightClass(diffFile.Name) } type Diff struct { diff --git a/templates/repo/diff_box.tmpl b/templates/repo/diff_box.tmpl index f96ebda52d5..455f07002c4 100644 --- a/templates/repo/diff_box.tmpl +++ b/templates/repo/diff_box.tmpl @@ -34,6 +34,7 @@ {{range $i, $file := .Diff.Files}} + {{$highlightClass := $file.GetHighlightClass}}

@@ -76,13 +77,13 @@ {{if $line.LeftIdx}}{{$line.LeftIdx}}{{end}} -
{{if $line.LeftIdx}}{{$section.GetComputedInlineDiffFor $line}}{{end}}
+
{{if $line.LeftIdx}}{{$section.GetComputedInlineDiffFor $line}}{{end}}
{{if $line.RightIdx}}{{$line.RightIdx}}{{end}} -
{{if $line.RightIdx}}{{$section.GetComputedInlineDiffFor $line}}{{end}}
+
{{if $line.RightIdx}}{{$section.GetComputedInlineDiffFor $line}}{{end}}
{{end}} @@ -104,7 +105,7 @@ {{end}} -
{{$section.GetComputedInlineDiffFor $line}}
+
{{$section.GetComputedInlineDiffFor $line}}
{{end}}