mirror of
https://github.com/go-gitea/gitea.git
synced 2025-05-13 01:12:36 -04:00
fix
This commit is contained in:
parent
9b8609e017
commit
f119993612
@ -162,22 +162,6 @@ func NewFuncMap() template.FuncMap {
|
||||
|
||||
"FilenameIsImage": filenameIsImage,
|
||||
"TabSizeClass": tabSizeClass,
|
||||
|
||||
// for backward compatibility only, do not use them anymore
|
||||
"TimeSince": timeSinceLegacy,
|
||||
"TimeSinceUnix": timeSinceLegacy,
|
||||
"DateTime": dateTimeLegacy,
|
||||
|
||||
"RenderEmoji": renderEmojiLegacy,
|
||||
"RenderLabel": renderLabelLegacy,
|
||||
"RenderLabels": renderLabelsLegacy,
|
||||
"RenderIssueTitle": renderIssueTitleLegacy,
|
||||
|
||||
"RenderMarkdownToHtml": renderMarkdownToHtmlLegacy,
|
||||
|
||||
"RenderCommitMessage": renderCommitMessageLegacy,
|
||||
"RenderCommitMessageLinkSubject": renderCommitMessageLinkSubjectLegacy,
|
||||
"RenderCommitBody": renderCommitBodyLegacy,
|
||||
}
|
||||
}
|
||||
|
||||
@ -367,7 +351,3 @@ func QueryBuild(a ...any) template.URL {
|
||||
}
|
||||
return template.URL(s)
|
||||
}
|
||||
|
||||
func panicIfDevOrTesting() {
|
||||
setting.PanicInDevOrTesting("legacy template functions are for backward compatibility only, do not use them in new code")
|
||||
}
|
||||
|
@ -1,23 +0,0 @@
|
||||
// Copyright 2024 The Gitea Authors. All rights reserved.
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
package templates
|
||||
|
||||
import (
|
||||
"html/template"
|
||||
|
||||
"code.gitea.io/gitea/modules/translation"
|
||||
)
|
||||
|
||||
func dateTimeLegacy(format string, datetime any, _ ...string) template.HTML {
|
||||
panicIfDevOrTesting()
|
||||
if s, ok := datetime.(string); ok {
|
||||
datetime = parseLegacy(s)
|
||||
}
|
||||
return dateTimeFormat(format, datetime)
|
||||
}
|
||||
|
||||
func timeSinceLegacy(time any, _ translation.Locale) template.HTML {
|
||||
panicIfDevOrTesting()
|
||||
return TimeSince(time)
|
||||
}
|
@ -23,7 +23,6 @@ func TestDateTime(t *testing.T) {
|
||||
du := NewDateUtils()
|
||||
|
||||
refTimeStr := "2018-01-01T00:00:00Z"
|
||||
refDateStr := "2018-01-01"
|
||||
refTime, _ := time.Parse(time.RFC3339, refTimeStr)
|
||||
refTimeStamp := timeutil.TimeStamp(refTime.Unix())
|
||||
|
||||
@ -32,18 +31,9 @@ func TestDateTime(t *testing.T) {
|
||||
assert.EqualValues(t, "-", du.AbsoluteShort(time.Time{}))
|
||||
assert.EqualValues(t, "-", du.AbsoluteShort(timeutil.TimeStamp(0)))
|
||||
|
||||
actual := dateTimeLegacy("short", "invalid")
|
||||
assert.EqualValues(t, `-`, actual)
|
||||
|
||||
actual = dateTimeLegacy("short", refTimeStr)
|
||||
actual := du.AbsoluteShort(refTime)
|
||||
assert.EqualValues(t, `<absolute-date weekday="" year="numeric" month="short" day="numeric" date="2018-01-01T00:00:00Z">2018-01-01</absolute-date>`, actual)
|
||||
|
||||
actual = du.AbsoluteShort(refTime)
|
||||
assert.EqualValues(t, `<absolute-date weekday="" year="numeric" month="short" day="numeric" date="2018-01-01T00:00:00Z">2018-01-01</absolute-date>`, actual)
|
||||
|
||||
actual = dateTimeLegacy("short", refDateStr)
|
||||
assert.EqualValues(t, `<absolute-date weekday="" year="numeric" month="short" day="numeric" date="2018-01-01T00:00:00-05:00">2018-01-01</absolute-date>`, actual)
|
||||
|
||||
actual = du.AbsoluteShort(refTimeStamp)
|
||||
assert.EqualValues(t, `<absolute-date weekday="" year="numeric" month="short" day="numeric" date="2017-12-31T19:00:00-05:00">2017-12-31</absolute-date>`, actual)
|
||||
|
||||
@ -69,6 +59,6 @@ func TestTimeSince(t *testing.T) {
|
||||
actual = timeSinceTo(&refTime, time.Time{})
|
||||
assert.EqualValues(t, `<relative-time prefix="" tense="future" datetime="2018-01-01T00:00:00Z" data-tooltip-content data-tooltip-interactive="true">2018-01-01 00:00:00 +00:00</relative-time>`, actual)
|
||||
|
||||
actual = timeSinceLegacy(timeutil.TimeStampNano(refTime.UnixNano()), nil)
|
||||
actual = du.TimeSince(timeutil.TimeStampNano(refTime.UnixNano()))
|
||||
assert.EqualValues(t, `<relative-time prefix="" tense="past" datetime="2017-12-31T19:00:00-05:00" data-tooltip-content data-tooltip-interactive="true">2017-12-31 19:00:00 -05:00</relative-time>`, actual)
|
||||
}
|
||||
|
@ -1,53 +0,0 @@
|
||||
// Copyright 2024 The Gitea Authors. All rights reserved.
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
package templates
|
||||
|
||||
import (
|
||||
"context"
|
||||
"html/template"
|
||||
|
||||
issues_model "code.gitea.io/gitea/models/issues"
|
||||
"code.gitea.io/gitea/modules/reqctx"
|
||||
"code.gitea.io/gitea/modules/translation"
|
||||
)
|
||||
|
||||
func renderEmojiLegacy(ctx context.Context, text string) template.HTML {
|
||||
panicIfDevOrTesting()
|
||||
return NewRenderUtils(reqctx.FromContext(ctx)).RenderEmoji(text)
|
||||
}
|
||||
|
||||
func renderLabelLegacy(ctx context.Context, locale translation.Locale, label *issues_model.Label) template.HTML {
|
||||
panicIfDevOrTesting()
|
||||
return NewRenderUtils(reqctx.FromContext(ctx)).RenderLabel(label)
|
||||
}
|
||||
|
||||
func renderLabelsLegacy(ctx context.Context, locale translation.Locale, labels []*issues_model.Label, repoLink string, issue *issues_model.Issue) template.HTML {
|
||||
panicIfDevOrTesting()
|
||||
return NewRenderUtils(reqctx.FromContext(ctx)).RenderLabels(labels, repoLink, issue)
|
||||
}
|
||||
|
||||
func renderMarkdownToHtmlLegacy(ctx context.Context, input string) template.HTML { //nolint:revive
|
||||
panicIfDevOrTesting()
|
||||
return NewRenderUtils(reqctx.FromContext(ctx)).MarkdownToHtml(input)
|
||||
}
|
||||
|
||||
func renderCommitMessageLegacy(ctx context.Context, msg string, _ map[string]string) template.HTML {
|
||||
panicIfDevOrTesting()
|
||||
return NewRenderUtils(reqctx.FromContext(ctx)).RenderCommitMessage(msg, nil)
|
||||
}
|
||||
|
||||
func renderCommitMessageLinkSubjectLegacy(ctx context.Context, msg, urlDefault string, _ map[string]string) template.HTML {
|
||||
panicIfDevOrTesting()
|
||||
return NewRenderUtils(reqctx.FromContext(ctx)).RenderCommitMessageLinkSubject(msg, urlDefault, nil)
|
||||
}
|
||||
|
||||
func renderIssueTitleLegacy(ctx context.Context, text string, _ map[string]string) template.HTML {
|
||||
panicIfDevOrTesting()
|
||||
return NewRenderUtils(reqctx.FromContext(ctx)).RenderIssueTitle(text, nil)
|
||||
}
|
||||
|
||||
func renderCommitBodyLegacy(ctx context.Context, msg string, _ map[string]string) template.HTML {
|
||||
panicIfDevOrTesting()
|
||||
return NewRenderUtils(reqctx.FromContext(ctx)).RenderCommitBody(msg, nil)
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user