From d78642e019dba865ebb10e8fd2b60e0e39994d1b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kim=20=22BKC=22=20Carlb=C3=A4cker?= Date: Sat, 26 Dec 2015 12:26:26 +0100 Subject: [PATCH] Implement Unified Diff-View --- public/css/gogs.css | 18 ++++++ templates/repo/diff_box.tmpl | 71 ++++---------------- templates/repo/diff_box_inline.tmpl | 74 +++++++++++++++++++++ templates/repo/diff_box_unified.tmpl | 97 ++++++++++++++++++++++++++++ 4 files changed, 200 insertions(+), 60 deletions(-) create mode 100644 templates/repo/diff_box_inline.tmpl create mode 100644 templates/repo/diff_box_unified.tmpl diff --git a/public/css/gogs.css b/public/css/gogs.css index ff1aaba7e..739ecad3a 100755 --- a/public/css/gogs.css +++ b/public/css/gogs.css @@ -724,6 +724,11 @@ img { } pre { font: 12px Consolas, "Liberation Mono", Menlo, Courier, monospace; + white-space: pre-wrap; /* CSS 3 */ + white-space: -moz-pre-wrap; /* Mozilla, since 1999 */ + white-space: -pre-wrap; /* Opera 4-6 */ + white-space: -o-pre-wrap; /* Opera 7 */ + word-wrap: break-word; /* Internet Explorer 5.5+ */ } pre.raw { padding: 7px 12px; @@ -2343,6 +2348,13 @@ footer .container .links > *:first-child { border-right: 1px solid #d4d4d5; padding: 0 5px; } +.repository .diff-file-box .code-diff tbody tr.tag-code td { + width: 50%; +} +.repository .diff-file-box .code-diff tbody tr.tag-code td.lines-num span.fold { + display: block; + text-align: center; +} .repository .diff-file-box .code-diff tbody tr.tag-code td, .repository .diff-file-box .code-diff tbody tr.tag-code pre { background-color: #F0F0F0 !important; @@ -2350,11 +2362,17 @@ footer .container .links > *:first-child { padding-top: 4px; padding-bottom: 4px; } +.repository .diff-file-box .code-diff tbody tr.del-code td { + width: 50%; +} .repository .diff-file-box .code-diff tbody tr.del-code td, .repository .diff-file-box .code-diff tbody tr.del-code pre { background-color: #ffecec !important; border-color: #f1c0c0 !important; } +.repository .diff-file-box .code-diff tbody tr.add-code td { + width: 50%; +} .repository .diff-file-box .code-diff tbody tr.add-code td, .repository .diff-file-box .code-diff tbody tr.add-code pre { background-color: #eaffea !important; diff --git a/templates/repo/diff_box.tmpl b/templates/repo/diff_box.tmpl index 036d4a649..bfcad4a1b 100644 --- a/templates/repo/diff_box.tmpl +++ b/templates/repo/diff_box.tmpl @@ -6,7 +6,11 @@ {{.i18n.Tr "repo.diff.stats_desc" .Diff.NumFiles .Diff.TotalAddition .Diff.TotalDeletion | Str2html}}
- {{.i18n.Tr "repo.diff.show_diff_stats"}} +
+ + +
+
    @@ -32,63 +36,10 @@
- {{range $i, $file := .Diff.Files}} -
-

-
- {{if $file.IsBin}} - {{$.i18n.Tr "repo.diff.bin"}} - {{else if not $file.IsRenamed}} - + {{.Addition}} - - - - - - {{.Deletion}} - {{end}} -
- {{if $file.IsRenamed}}{{$file.OldName}} → {{end}}{{$file.Name}} -
- {{if $file.IsDeleted}} - {{$.i18n.Tr "repo.diff.view_file"}} - {{else}} - {{$.i18n.Tr "repo.diff.view_file"}} - {{end}} -
-

-
- {{if not $file.IsRenamed}} - {{$isImage := (call $.IsImageFile $file.Name)}} - {{if and $isImage}} -
- -
- {{else}} -
- - - {{range .Sections}} - {{range $k, $line := .Lines}} - - - - - - {{end}} - {{end}} - -
- {{if $line.LeftIdx}}{{$line.LeftIdx}}{{end}} - - {{if $line.RightIdx}}{{$line.RightIdx}}{{end}} - -
{{$line.Content}}
-
-
- {{end}} - {{end}} -
-
-
- {{end}} +
+ {{ template "repo/diff_box_unified.tmpl" . }} +
+
+ {{ template "repo/diff_box_inline.tmpl" . }} +
{{end}} diff --git a/templates/repo/diff_box_inline.tmpl b/templates/repo/diff_box_inline.tmpl new file mode 100644 index 000000000..2dea01383 --- /dev/null +++ b/templates/repo/diff_box_inline.tmpl @@ -0,0 +1,74 @@ +{{range $i, $file := .Diff.Files}} +
+

+
+ {{if $file.IsBin}} + {{$.i18n.Tr "repo.diff.bin"}} + {{else if not $file.IsRenamed}} + + {{.Addition}} + + + + + - {{.Deletion}} + {{end}} +
+ {{if $file.IsRenamed}}{{$file.OldName}} → {{end}}{{$file.Name}} +
+ {{if $file.IsDeleted}} + {{$.i18n.Tr "repo.diff.view_file"}} + {{else}} + {{$.i18n.Tr "repo.diff.view_file"}} + {{end}} +
+

+
+ {{if not $file.IsRenamed}} + {{$isImage := (call $.IsImageFile $file.Name)}} + {{if and $isImage}} +
+ +
+ {{else}} +
+ + + {{range $j, $section := .Sections}} + {{range $k, $line := .Lines}} + + {{if eq .Type 4}} + + {{else}} + + + {{end}} + + + {{end}} + {{end}} + +
+ {{if gt $j 0}}{{end}} + + {{if $line.LeftIdx}}{{$line.LeftIdx}}{{end}} + + {{if $line.RightIdx}}{{$line.RightIdx}}{{end}} + +
{{$line.Content}}
+
+
+ + {{end}} + {{end}} +
+
+
+{{end}} diff --git a/templates/repo/diff_box_unified.tmpl b/templates/repo/diff_box_unified.tmpl new file mode 100644 index 000000000..386f530df --- /dev/null +++ b/templates/repo/diff_box_unified.tmpl @@ -0,0 +1,97 @@ +{{range $i, $file := .Diff.Files}} +
+

+
+ {{if $file.IsBin}} + {{$.i18n.Tr "repo.diff.bin"}} + {{else if not $file.IsRenamed}} + + {{.Addition}} + + + + + - {{.Deletion}} + {{end}} +
+ {{if $file.IsRenamed}}{{$file.OldName}} → {{end}}{{$file.Name}} +
+ {{if $file.IsDeleted}} + {{$.i18n.Tr "repo.diff.view_file"}} + {{else}} + {{$.i18n.Tr "repo.diff.view_file"}} + {{end}} +
+

+
+ {{if not $file.IsRenamed}} + {{$isImage := (call $.IsImageFile $file.Name)}} + {{if and $isImage}} +
+ +
+ {{else}} +
+ + + {{range $j, $section := .Sections}} + {{range $k, $line := .Lines}} + + {{if eq .Type 4}} + + + + + {{else}} + + + + + {{end}} + + {{end}} + {{end}} + +
+ + +
{{$line.Content}}
+
+ + +
{{$line.Content}}
+
+ {{if $line.LeftIdx}}{{$line.LeftIdx}}{{end}} + +
{{if $line.LeftIdx}}{{$line.Content}}{{end}}
+
+ {{if $line.RightIdx}}{{$line.RightIdx}}{{end}} + +
{{if $line.RightIdx}}{{$line.Content}}{{end}}
+
+
+ + {{end}} + {{end}} +
+
+
+{{end}}