diff options
author | Runxi Yu <me@runxiyu.org> | 2025-02-11 21:33:48 +0800 |
---|---|---|
committer | Runxi Yu <me@runxiyu.org> | 2025-02-11 21:33:48 +0800 |
commit | 2159ed2cc629ae30d6bb020f67e301dedf779dd4 (patch) | |
tree | 65f6ca9f18b265621746c7147132014362dee9c5 | |
parent | repo_commit: Show chunks (diff) | |
download | forge-2159ed2cc629ae30d6bb020f67e301dedf779dd4.tar.gz forge-2159ed2cc629ae30d6bb020f67e301dedf779dd4.tar.zst forge-2159ed2cc629ae30d6bb020f67e301dedf779dd4.zip |
repo_commit: Properly format patchsets
Diffstat (limited to '')
-rw-r--r-- | handle_repo_commit.go | 1 | ||||
-rw-r--r-- | static/style.css | 31 | ||||
-rw-r--r-- | templates/repo_commit.html.tmpl | 37 |
3 files changed, 55 insertions, 14 deletions
diff --git a/handle_repo_commit.go b/handle_repo_commit.go index 3a63201..4660ff3 100644 --- a/handle_repo_commit.go +++ b/handle_repo_commit.go @@ -45,6 +45,7 @@ func handle_repo_commit(w http.ResponseWriter, r *http.Request) { } data["patch"] = patch + // TODO: Remove unnecessary context usable_file_patches := make([]usable_file_patch, 0) for _, file_patch := range patch.FilePatches() { from, to := file_patch.Files() diff --git a/static/style.css b/static/style.css index e37ad0d..c5d79ec 100644 --- a/static/style.css +++ b/static/style.css @@ -100,7 +100,7 @@ td#readme > *:first-child { .toggle-table-off + table > thead > tr > th > label, .toggle-table-on + table > thead > tr > th > label { width: 100%; display: inline-block; - padding: 3px 1px; + padding: 3px 0; cursor: pointer; } .toggle-table-off:checked + table > tbody { @@ -124,3 +124,32 @@ td#readme > *:first-child { .chunk-unknown { color: yellow; } +pre.chunk { + margin-top: 0; + margin-bottom: 0; +} +.toggle-on-wrapper { + border: var(--lighter-border-color) solid 1px; +} +.toggle-on-toggle { + display: none; +} +.toggle-on-header { + cursor: pointer; + display: block; + width: 100%; + border-bottom: var(--lighter-border-color) solid 1px; + background-color: var(--lighter-box-background-color); +} +.toggle-on-content { + display: none; +} +.toggle-on-toggle:checked + .toggle-on-header + .toggle-on-content { + display: block; +} +.file-patch + .file-patch { + margin-top: 0.5rem; +} +.file-header { + font-family: monospace; +} diff --git a/templates/repo_commit.html.tmpl b/templates/repo_commit.html.tmpl index edc4bc3..5b6cb84 100644 --- a/templates/repo_commit.html.tmpl +++ b/templates/repo_commit.html.tmpl @@ -41,21 +41,32 @@ </tbody> </table> </div> - <div class="padding-wrapper scroll"> + <div class="padding-wrapper"> + {{ $parent_commit_object := .parent_commit_object }} + {{ $commit_object := .commit_object }} {{ range .file_patches }} - <div class="file-patch"> - {{ .From.Path }} {{ .From.Mode }} → {{ .To.Path }} {{ .To.Mode }} - {{ range .Chunks }} - {{ if eq .Type 0 }} - <pre class="chunk chunk-unchanged">{{ .Content }}</pre> - {{ else if eq .Type 1 }} - <pre class="chunk chunk-addition">{{ .Content }}</pre> - {{ else if eq .Type 2 }} - <pre class="chunk chunk-deletion">{{ .Content }}</pre> - {{ else }} - <pre class="chunk chunk-unknown">{{ .Content }}</pre> + <div class="file-patch toggle-on-wrapper"> + <input type="checkbox" id="toggle-{{ .From.Hash }}{{ .To.Hash }}" class="file-toggle toggle-on-toggle"> + <label for="toggle-{{ .From.Hash }}{{ .To.Hash }}" class="file-header toggle-on-header"> + <span> + --- a/<a href="../../tree/{{ .From.Path }}?commit={{ $parent_commit_object.Hash }}">{{ .From.Path }}</a> {{ .From.Mode }} + <br /> + +++ b/<a href="../../tree/{{ .To.Path }}?commit={{ $commit_object.Hash }}">{{ .To.Path }}</a> {{ .To.Mode }} + </span> + </label> + <div class="file-content toggle-on-content scroll"> + {{ range .Chunks }} + {{ if eq .Type 0 }} + <pre class="chunk chunk-unchanged">{{ .Content }}</pre> + {{ else if eq .Type 1 }} + <pre class="chunk chunk-addition">{{ .Content }}</pre> + {{ else if eq .Type 2 }} + <pre class="chunk chunk-deletion">{{ .Content }}</pre> + {{ else }} + <pre class="chunk chunk-unknown">{{ .Content }}</pre> + {{ end }} {{ end }} - {{ end }} + </div> </div> {{ end }} </div> |