Browse Source

Merge pull request #2674 from andreynering/highlight-little-refactoring

Little refactoring of diff highlight.
pull/2676/head
Unknwon 9 years ago
parent
commit
6e74dd4388
  1. 6
      models/git_diff.go
  2. 7
      templates/repo/diff_box.tmpl

6
models/git_diff.go

@ -161,7 +161,6 @@ type DiffFile struct {
IsBin bool IsBin bool
IsRenamed bool IsRenamed bool
Sections []*DiffSection Sections []*DiffSection
HighlightClass string
} }
func (diffFile *DiffFile) GetType() int { func (diffFile *DiffFile) GetType() int {
@ -169,10 +168,7 @@ func (diffFile *DiffFile) GetType() int {
} }
func (diffFile *DiffFile) GetHighlightClass() string { func (diffFile *DiffFile) GetHighlightClass() string {
if diffFile.HighlightClass == "" { return highlight.FileNameToHighlightClass(diffFile.Name)
diffFile.HighlightClass = highlight.FileNameToHighlightClass(diffFile.Name)
}
return diffFile.HighlightClass
} }
type Diff struct { type Diff struct {

7
templates/repo/diff_box.tmpl

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

Loading…
Cancel
Save