avoid HTMLString and render placeholder in template

This commit is contained in:
silverwind 2024-04-26 13:14:09 +02:00
parent 839700b923
commit 73937a5204
No known key found for this signature in database
GPG Key ID: 2E62B41C93869443
3 changed files with 9 additions and 12 deletions

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)
}

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

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}}