1
0
Fork 0
mirror of https://codeberg.org/forgejo/forgejo.git synced 2024-11-22 08:42:32 -05:00

Little refactoring of diff highlight.

Moving cache variable to template instead of in the struct.
This commit is contained in:
Andrey Nering 2016-02-21 18:45:24 -03:00
parent 8ac04a3f29
commit d160c7e565
2 changed files with 5 additions and 8 deletions

View file

@ -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 {

View file

@ -34,6 +34,7 @@
</div>
{{range $i, $file := .Diff.Files}}
{{$highlightClass := $file.GetHighlightClass}}
<div class="diff-file-box diff-box file-content" id="diff-{{.Index}}">
<h4 class="ui top attached normal header">
<div class="diff-counter count ui left">
@ -76,13 +77,13 @@
<span rel="{{if $line.LeftIdx}}diff-{{Sha1 $file.Name}}L{{$line.LeftIdx}}{{end}}">{{if $line.LeftIdx}}{{$line.LeftIdx}}{{end}}</span>
</td>
<td class="lines-code halfwidth">
<pre><code class="wrap {{if $file.GetHighlightClass}}language-{{$file.GetHighlightClass}}{{else}}nohighlight{{end}}">{{if $line.LeftIdx}}{{$section.GetComputedInlineDiffFor $line}}{{end}}</code></pre>
<pre><code class="wrap {{if $highlightClass}}language-{{$highlightClass}}{{else}}nohighlight{{end}}">{{if $line.LeftIdx}}{{$section.GetComputedInlineDiffFor $line}}{{end}}</code></pre>
</td>
<td class="lines-num lines-num-new">
<span rel="{{if $line.RightIdx}}diff-{{Sha1 $file.Name}}R{{$line.RightIdx}}{{end}}">{{if $line.RightIdx}}{{$line.RightIdx}}{{end}}</span>
</td>
<td class="lines-code halfwidth">
<pre><code class="wrap {{if $file.GetHighlightClass}}language-{{$file.GetHighlightClass}}{{else}}nohighlight{{end}}">{{if $line.RightIdx}}{{$section.GetComputedInlineDiffFor $line}}{{end}}</code></pre>
<pre><code class="wrap {{if $highlightClass}}language-{{$highlightClass}}{{else}}nohighlight{{end}}">{{if $line.RightIdx}}{{$section.GetComputedInlineDiffFor $line}}{{end}}</code></pre>
</td>
</tr>
{{end}}
@ -104,7 +105,7 @@
</td>
{{end}}
<td class="lines-code">
<pre><code class="{{if $file.GetHighlightClass}}language-{{$file.GetHighlightClass}}{{else}}nohighlight{{end}}">{{$section.GetComputedInlineDiffFor $line}}</code></pre>
<pre><code class="{{if $highlightClass}}language-{{$highlightClass}}{{else}}nohighlight{{end}}">{{$section.GetComputedInlineDiffFor $line}}</code></pre>
</td>
</tr>
{{end}}