Browse Source

avoid HTMLString and render placeholder in template

pull/30707/head
silverwind 1 week ago
parent
commit
73937a5204
No account linked to committer's email address
3 changed files with 9 additions and 12 deletions
  1. 3
    3
      routers/web/repo/editor.go
  2. 0
    9
      services/context/base.go
  3. 6
    0
      templates/repo/editor/diff_preview.tmpl

+ 3
- 3
routers/web/repo/editor.go View File

@@ -420,10 +420,10 @@ func DiffPreviewPost(ctx *context.Context) {
}

if diff.NumFiles == 0 {
ctx.HTMLString(http.StatusOK, `<div class="tw-p-6">`+ctx.Locale.TrString("repo.editor.no_changes_to_show")+`</div>`)
return
ctx.Data["File"] = nil
} else {
ctx.Data["File"] = diff.Files[0]
}
ctx.Data["File"] = diff.Files[0]

ctx.HTML(http.StatusOK, tplEditDiffPreview)
}

+ 0
- 9
services/context/base.go View File

@@ -137,15 +137,6 @@ func (b *Base) JSON(status int, content any) {
}
}

// HTMLString renders string as HTML
func (b *Base) HTMLString(status int, html string) {
b.Resp.Header().Set("Content-Type", "text/html;charset=utf-8")
b.Resp.WriteHeader(status)
if _, err := b.Resp.Write([]byte(html)); err != nil {
log.Error("Render HTMLString failed: %v", err)
}
}

// RemoteAddr returns the client machine ip address
func (b *Base) RemoteAddr() string {
return b.Req.RemoteAddr

+ 6
- 0
templates/repo/editor/diff_preview.tmpl View File

@@ -1,3 +1,4 @@
{{if .File}}
<div class="diff-file-box">
<div class="ui attached table segment">
<div class="file-body file-code code-diff code-diff-unified unicode-escaped">
@@ -9,3 +10,8 @@
</div>
</div>
</div>
{{else}}
<div class="tw-p-6">
{{ctx.Locale.Tr "repo.editor.no_changes_to_show"}}
</div>
{{end}}

Loading…
Cancel
Save