diff --git a/cmd/dump.go b/cmd/dump.go index ececc80f72507..1dbe25e222b01 100644 --- a/cmd/dump.go +++ b/cmd/dump.go @@ -132,7 +132,7 @@ func runDump(ctx *cli.Context) error { defer outFile.Close() } - setupConsoleLogger(util.Iif(quite, log.WARN, log.INFO), log.CanColorStderr, os.Stderr) + setupConsoleLogger(util.Ternary(quite, log.WARN, log.INFO), log.CanColorStderr, os.Stderr) setting.DisableLoggerInit() setting.LoadSettings() // cannot access session settings otherwise diff --git a/cmd/web.go b/cmd/web.go index dc5c6de48a309..a1c17d81fe6c0 100644 --- a/cmd/web.go +++ b/cmd/web.go @@ -220,7 +220,7 @@ func serveInstalled(ctx *cli.Context) error { } } - gtprof.EnableBuiltinTracer(util.Iif(setting.IsProd, 2000*time.Millisecond, 100*time.Millisecond)) + gtprof.EnableBuiltinTracer(util.Ternary(setting.IsProd, 2000*time.Millisecond, 100*time.Millisecond)) // Set up Chi routes webRoutes := routers.NormalRoutes() diff --git a/models/asymkey/ssh_key_fingerprint.go b/models/asymkey/ssh_key_fingerprint.go index 1ed3b5df2a19e..f6ba9b84906a3 100644 --- a/models/asymkey/ssh_key_fingerprint.go +++ b/models/asymkey/ssh_key_fingerprint.go @@ -77,13 +77,13 @@ func calcFingerprintNative(publicKeyContent string) (string, error) { func CalcFingerprint(publicKeyContent string) (string, error) { // Call the method based on configuration useNative := setting.SSH.KeygenPath == "" - calcFn := util.Iif(useNative, calcFingerprintNative, calcFingerprintSSHKeygen) + calcFn := util.Ternary(useNative, calcFingerprintNative, calcFingerprintSSHKeygen) fp, err := calcFn(publicKeyContent) if err != nil { if IsErrKeyUnableVerify(err) { return "", err } - return "", fmt.Errorf("CalcFingerprint(%s): %w", util.Iif(useNative, "native", "ssh-keygen"), err) + return "", fmt.Errorf("CalcFingerprint(%s): %w", util.Ternary(useNative, "native", "ssh-keygen"), err) } return fp, nil } diff --git a/models/issues/issue_project.go b/models/issues/issue_project.go index 01852447834c7..ecb7db9376614 100644 --- a/models/issues/issue_project.go +++ b/models/issues/issue_project.go @@ -155,7 +155,7 @@ func IssueAssignOrRemoveProject(ctx context.Context, issue *Issue, doer *user_mo Get(&res); err != nil { return err } - newSorting := util.Iif(res.IssueCount > 0, res.MaxSorting+1, 0) + newSorting := util.Ternary(res.IssueCount > 0, res.MaxSorting+1, 0) return db.Insert(ctx, &project_model.ProjectIssue{ IssueID: issue.ID, ProjectID: newProjectID, diff --git a/models/issues/issue_update.go b/models/issues/issue_update.go index 7b3fe04aa5b10..3ba69af10ccdf 100644 --- a/models/issues/issue_update.go +++ b/models/issues/issue_update.go @@ -47,7 +47,7 @@ func IsErrIssueIsClosed(err error) bool { } func (err ErrIssueIsClosed) Error() string { - return fmt.Sprintf("%s [id: %d, repo_id: %d, index: %d] is already closed", util.Iif(err.IsPull, "Pull Request", "Issue"), err.ID, err.RepoID, err.Index) + return fmt.Sprintf("%s [id: %d, repo_id: %d, index: %d] is already closed", util.Ternary(err.IsPull, "Pull Request", "Issue"), err.ID, err.RepoID, err.Index) } func SetIssueAsClosed(ctx context.Context, issue *Issue, doer *user_model.User, isMergePull bool) (*Comment, error) { @@ -84,7 +84,7 @@ func SetIssueAsClosed(ctx context.Context, issue *Issue, doer *user_model.User, return nil, ErrIssueAlreadyChanged } - return updateIssueNumbers(ctx, issue, doer, util.Iif(isMergePull, CommentTypeMergePull, CommentTypeClose)) + return updateIssueNumbers(ctx, issue, doer, util.Ternary(isMergePull, CommentTypeMergePull, CommentTypeClose)) } // ErrIssueIsOpen is used when reopen an opened issue @@ -102,7 +102,7 @@ func IsErrIssueIsOpen(err error) bool { } func (err ErrIssueIsOpen) Error() string { - return fmt.Sprintf("%s [id: %d, repo_id: %d, index: %d] is already open", util.Iif(err.IsPull, "Pull Request", "Issue"), err.ID, err.RepoID, err.Index) + return fmt.Sprintf("%s [id: %d, repo_id: %d, index: %d] is already open", util.Ternary(err.IsPull, "Pull Request", "Issue"), err.ID, err.RepoID, err.Index) } func setIssueAsReopen(ctx context.Context, issue *Issue, doer *user_model.User) (*Comment, error) { diff --git a/models/perm/access/repo_permission.go b/models/perm/access/repo_permission.go index 5e7ecb31eabbd..728bd66ac90a7 100644 --- a/models/perm/access/repo_permission.go +++ b/models/perm/access/repo_permission.go @@ -77,12 +77,12 @@ func (p *Permission) GetFirstUnitRepoID() int64 { func (p *Permission) UnitAccessMode(unitType unit.Type) perm_model.AccessMode { // if the units map contains the access mode, use it, but admin/owner mode could override it if m, ok := p.unitsMode[unitType]; ok { - return util.Iif(p.AccessMode >= perm_model.AccessModeAdmin, p.AccessMode, m) + return util.Ternary(p.AccessMode >= perm_model.AccessModeAdmin, p.AccessMode, m) } // if the units map does not contain the access mode, return the default access mode if the unit exists unitDefaultAccessMode := max(p.AccessMode, p.everyoneAccessMode[unitType]) hasUnit := slices.ContainsFunc(p.units, func(u *repo_model.RepoUnit) bool { return u.Type == unitType }) - return util.Iif(hasUnit, unitDefaultAccessMode, perm_model.AccessModeNone) + return util.Ternary(hasUnit, unitDefaultAccessMode, perm_model.AccessModeNone) } func (p *Permission) SetUnitsWithDefaultAccessMode(units []*repo_model.RepoUnit, mode perm_model.AccessMode) { diff --git a/models/perm/access_mode.go b/models/perm/access_mode.go index 6baeb5531a51a..c418ab3e820dd 100644 --- a/models/perm/access_mode.go +++ b/models/perm/access_mode.go @@ -58,7 +58,7 @@ func ParseAccessMode(permission string, allowed ...AccessMode) AccessMode { if len(allowed) == 0 { return m } - return util.Iif(slices.Contains(allowed, m), m, AccessModeNone) + return util.Ternary(slices.Contains(allowed, m), m, AccessModeNone) } // ErrInvalidAccessMode is returned when an invalid access mode is used diff --git a/models/project/column.go b/models/project/column.go index 77ff5ef83e025..e78b85ebcc7ee 100644 --- a/models/project/column.go +++ b/models/project/column.go @@ -149,7 +149,7 @@ func NewColumn(ctx context.Context, column *Column) error { if res.ColumnCount >= maxProjectColumns { return fmt.Errorf("NewBoard: maximum number of columns reached") } - column.Sorting = int8(util.Iif(res.ColumnCount > 0, res.MaxSorting+1, 0)) + column.Sorting = int8(util.Ternary(res.ColumnCount > 0, res.MaxSorting+1, 0)) _, err := db.GetEngine(ctx).Insert(column) return err } diff --git a/models/project/issue.go b/models/project/issue.go index 98eed2a2137b5..40a2da03b3b8a 100644 --- a/models/project/issue.go +++ b/models/project/issue.go @@ -62,7 +62,7 @@ func (c *Column) moveIssuesToAnotherColumn(ctx context.Context, newColumn *Colum return nil } - nextSorting := util.Iif(res.IssueCount > 0, res.MaxSorting+1, 0) + nextSorting := util.Ternary(res.IssueCount > 0, res.MaxSorting+1, 0) return db.WithTx(ctx, func(ctx context.Context) error { for i, issue := range issues { issue.ProjectColumnID = newColumn.ID diff --git a/modules/httpcache/httpcache.go b/modules/httpcache/httpcache.go index 045b00d944cc6..3ada69d4b16d7 100644 --- a/modules/httpcache/httpcache.go +++ b/modules/httpcache/httpcache.go @@ -26,7 +26,7 @@ func SetCacheControlInHeader(h http.Header, opts *CacheControlOptions) { // "max-age=0 + must-revalidate" (aka "no-cache") is preferred instead of "no-store" // because browsers may restore some input fields after navigate-back / reload a page. - publicPrivate := util.Iif(opts.IsPublic, "public", "private") + publicPrivate := util.Ternary(opts.IsPublic, "public", "private") if setting.IsProd { if opts.MaxAge == 0 { directives = append(directives, "max-age=0", "private", "must-revalidate") diff --git a/modules/httplib/url.go b/modules/httplib/url.go index 5d5b64dc0cfbf..fc31163e4a719 100644 --- a/modules/httplib/url.go +++ b/modules/httplib/url.go @@ -45,10 +45,10 @@ func getRequestScheme(req *http.Request) string { return s } if s := req.Header.Get("Front-End-Https"); s != "" { - return util.Iif(s == "on", "https", "http") + return util.Ternary(s == "on", "https", "http") } if s := req.Header.Get("X-Forwarded-Ssl"); s != "" { - return util.Iif(s == "on", "https", "http") + return util.Ternary(s == "on", "https", "http") } return "" } @@ -119,7 +119,7 @@ func detectURLRoutePath(ctx context.Context, s string) (routePath string, ut url cleanedPath := "" if u.Path != "" { cleanedPath = util.PathJoinRelX(u.Path) - cleanedPath = util.Iif(cleanedPath == ".", "", "/"+cleanedPath) + cleanedPath = util.Ternary(cleanedPath == ".", "", "/"+cleanedPath) } if urlIsRelative(s, u) { if u.Path == "" { diff --git a/modules/markup/html_internal_test.go b/modules/markup/html_internal_test.go index 159d712955797..65d9e0e07048b 100644 --- a/modules/markup/html_internal_test.go +++ b/modules/markup/html_internal_test.go @@ -33,7 +33,7 @@ func numericIssueLink(baseURL, class string, index int, marker string) string { // link an HTML link func link(href, class, contents string) string { - extra := util.Iif(class != "", ` class="`+class+`"`, "") + extra := util.Ternary(class != "", ` class="`+class+`"`, "") return fmt.Sprintf(`%s`, href, extra, contents) } diff --git a/modules/markup/html_issue.go b/modules/markup/html_issue.go index 7a6f33011a7c0..600c7130cb6fd 100644 --- a/modules/markup/html_issue.go +++ b/modules/markup/html_issue.go @@ -159,9 +159,9 @@ func issueIndexPatternProcessor(ctx *RenderContext, node *html.Node) { // Path determines the type of link that will be rendered. It's unknown at this point whether // the linked item is actually a PR or an issue. Luckily it's of no real consequence because // Gitea will redirect on click as appropriate. - issueOwner := util.Iif(ref.Owner == "", ctx.RenderOptions.Metas["user"], ref.Owner) - issueRepo := util.Iif(ref.Owner == "", ctx.RenderOptions.Metas["repo"], ref.Name) - issuePath := util.Iif(ref.IsPull, "pulls", "issues") + issueOwner := util.Ternary(ref.Owner == "", ctx.RenderOptions.Metas["user"], ref.Owner) + issueRepo := util.Ternary(ref.Owner == "", ctx.RenderOptions.Metas["repo"], ref.Name) + issuePath := util.Ternary(ref.IsPull, "pulls", "issues") linkHref := ctx.RenderHelper.ResolveLink(util.URLJoin(issueOwner, issueRepo, issuePath, ref.Issue), LinkTypeApp) // at the moment, only render the issue index in a full line (or simple line) as icon+title diff --git a/modules/markup/markdown/math/block_parser.go b/modules/markup/markdown/math/block_parser.go index 2c5553550a71a..2680e892c0576 100644 --- a/modules/markup/markdown/math/block_parser.go +++ b/modules/markup/markdown/math/block_parser.go @@ -55,7 +55,7 @@ func (b *blockParser) Open(parent ast.Node, reader text.Reader, pc parser.Contex node := NewBlock(dollars, pos) // Now we need to check if the ending block is on the segment... - endBytes := giteaUtil.Iif(dollars, b.endBytesDollars, b.endBytesSquare) + endBytes := giteaUtil.Ternary(dollars, b.endBytesDollars, b.endBytesSquare) idx := bytes.Index(line[pos+2:], endBytes) if idx >= 0 { // for case: "$$ ... $$ any other text" (this case will be handled by the inline parser) @@ -94,16 +94,16 @@ func (b *blockParser) Continue(node ast.Node, reader text.Reader, pc parser.Cont line, segment := reader.PeekLine() w, pos := util.IndentWidth(line, reader.LineOffset()) if w < 4 { - endBytes := giteaUtil.Iif(block.Dollars, b.endBytesDollars, b.endBytesSquare) + endBytes := giteaUtil.Ternary(block.Dollars, b.endBytesDollars, b.endBytesSquare) if bytes.HasPrefix(line[pos:], endBytes) && util.IsBlank(line[pos+len(endBytes):]) { if util.IsBlank(line[pos+len(endBytes):]) { - newline := giteaUtil.Iif(line[len(line)-1] != '\n', 0, 1) + newline := giteaUtil.Ternary(line[len(line)-1] != '\n', 0, 1) reader.Advance(segment.Stop - segment.Start - newline + segment.Padding) return parser.Close } } } - start := segment.Start + giteaUtil.Iif(pos > block.Indent, block.Indent, pos) + start := segment.Start + giteaUtil.Ternary(pos > block.Indent, block.Indent, pos) seg := text.NewSegmentPadding(start, segment.Stop, segment.Padding) node.Lines().Append(seg) return parser.Continue | parser.NoChildren diff --git a/modules/markup/markdown/math/block_renderer.go b/modules/markup/markdown/math/block_renderer.go index 412e4d0dee6c2..7fa9f5f6d325b 100644 --- a/modules/markup/markdown/math/block_renderer.go +++ b/modules/markup/markdown/math/block_renderer.go @@ -51,11 +51,11 @@ func (r *BlockRenderer) writeLines(w util.BufWriter, source []byte, n gast.Node) func (r *BlockRenderer) renderBlock(w util.BufWriter, source []byte, node gast.Node, entering bool) (gast.WalkStatus, error) { n := node.(*Block) if entering { - code := giteaUtil.Iif(n.Inline, "", `
`) + ``
+ code := giteaUtil.Ternary(n.Inline, "", ``) + ``
_ = r.renderInternal.FormatWithSafeAttrs(w, template.HTML(code))
r.writeLines(w, source, n)
} else {
- _, _ = w.WriteString(`` + giteaUtil.Iif(n.Inline, "", `
`) + "\n")
+ _, _ = w.WriteString(`` + giteaUtil.Ternary(n.Inline, "", ``) + "\n")
}
return gast.WalkContinue, nil
}
diff --git a/modules/templates/helper.go b/modules/templates/helper.go
index 3237f8b2958a6..dabffa55b7ed5 100644
--- a/modules/templates/helper.go
+++ b/modules/templates/helper.go
@@ -35,7 +35,7 @@ func NewFuncMap() template.FuncMap {
// -----------------------------------------------------------------
// html/template related functions
"dict": dict, // it's lowercase because this name has been widely used. Our other functions should have uppercase names.
- "Iif": iif,
+ "Ternary": ternary,
"Eval": evalTokens,
"SafeHTML": safeHTML,
"HTMLFormat": htmlFormat,
@@ -233,9 +233,9 @@ func dotEscape(raw string) string {
return strings.ReplaceAll(raw, ".", "\u200d.\u200d")
}
-// iif is an "inline-if", similar util.Iif[T] but templates need the non-generic version,
-// and it could be simply used as "{{iif expr trueVal}}" (omit the falseVal).
-func iif(condition any, vals ...any) any {
+// ternary is an "inline-if", similar util.Ternary[T] but templates need the non-generic version,
+// and it can be simply used as "{{ternary expr trueVal}}" (omit the falseVal).
+func ternary(condition any, vals ...any) any {
if isTemplateTruthy(condition) {
return vals[0]
} else if len(vals) > 1 {
diff --git a/modules/templates/helper_test.go b/modules/templates/helper_test.go
index 5d7bc93622be2..faa843e5a24e5 100644
--- a/modules/templates/helper_test.go
+++ b/modules/templates/helper_test.go
@@ -67,7 +67,7 @@ func TestSanitizeHTML(t *testing.T) {
func TestTemplateIif(t *testing.T) {
tmpl := template.New("test")
- tmpl.Funcs(template.FuncMap{"Iif": iif})
+ tmpl.Funcs(template.FuncMap{"Iif": ternary})
template.Must(tmpl.Parse(`{{if .Value}}true{{else}}false{{end}}:{{Iif .Value "true" "false"}}`))
cases := []any{nil, false, true, "", "string", 0, 1}
@@ -77,7 +77,7 @@ func TestTemplateIif(t *testing.T) {
w.Reset()
assert.NoError(t, tmpl.Execute(w, struct{ Value any }{v}), "case %d (%T) %#v fails", i, v, v)
out := w.String()
- truthyCount += util.Iif(out == "true:true", 1, 0)
+ truthyCount += util.Ternary(out == "true:true", 1, 0)
truthyMatches := out == "true:true" || out == "false:false"
assert.True(t, truthyMatches, "case %d (%T) %#v fail: %s", i, v, v, out)
}
diff --git a/modules/templates/util_render.go b/modules/templates/util_render.go
index 27316bbfecf5d..cefd457353077 100644
--- a/modules/templates/util_render.go
+++ b/modules/templates/util_render.go
@@ -221,7 +221,7 @@ func (ut *RenderUtils) MarkdownToHtml(input string) template.HTML { //nolint:rev
func (ut *RenderUtils) RenderLabels(labels []*issues_model.Label, repoLink string, issue *issues_model.Issue) template.HTML {
isPullRequest := issue != nil && issue.IsPull
- baseLink := fmt.Sprintf("%s/%s", repoLink, util.Iif(isPullRequest, "pulls", "issues"))
+ baseLink := fmt.Sprintf("%s/%s", repoLink, util.Ternary(isPullRequest, "pulls", "issues"))
htmlCode := ``
for _, label := range labels {
// Protect against nil value in labels - shouldn't happen but would cause a panic if so
diff --git a/modules/util/util.go b/modules/util/util.go
index 1fb4cb21cb884..6624fc706e234 100644
--- a/modules/util/util.go
+++ b/modules/util/util.go
@@ -213,8 +213,8 @@ func ToPointer[T any](val T) *T {
return &val
}
-// Iif is an "inline-if", it returns "trueVal" if "condition" is true, otherwise "falseVal"
-func Iif[T any](condition bool, trueVal, falseVal T) T {
+// Ternary is an "inline-if", it returns "trueVal" if "condition" is true, otherwise "falseVal"
+func Ternary[T any](condition bool, trueVal, falseVal T) T {
if condition {
return trueVal
}
diff --git a/modules/web/router_test.go b/modules/web/router_test.go
index 582980a27ae87..94a6c4aece867 100644
--- a/modules/web/router_test.go
+++ b/modules/web/router_test.go
@@ -27,7 +27,7 @@ func chiURLParamsToMap(chiCtx *chi.Context) map[string]string {
}
m[key] = pathParams.Values[i]
}
- return util.Iif(len(m) == 0, nil, m)
+ return util.Ternary(len(m) == 0, nil, m)
}
func TestPathProcessor(t *testing.T) {
diff --git a/routers/api/packages/rubygems/rubygems.go b/routers/api/packages/rubygems/rubygems.go
index de8c7ef3ed009..128f260ab6376 100644
--- a/routers/api/packages/rubygems/rubygems.go
+++ b/routers/api/packages/rubygems/rubygems.go
@@ -347,7 +347,7 @@ func GetAllPackagesVersions(ctx *context.Context) {
// format: RUBYGEM [-]VERSION_PLATFORM[,VERSION_PLATFORM],...] MD5
_, _ = fmt.Fprintf(out, "%s ", pkg.Name)
for i, v := range versions {
- sep := util.Iif(i == len(versions)-1, "", ",")
+ sep := util.Ternary(i == len(versions)-1, "", ",")
_, _ = fmt.Fprintf(out, "%s%s", v.Version, sep)
}
_, _ = fmt.Fprintf(out, " %x\n", md5.Sum([]byte(info)))
@@ -362,7 +362,7 @@ func writePackageVersionRequirements(prefix string, reqs []rubygems_module.Versi
reqs = []rubygems_module.VersionRequirement{{Restriction: ">=", Version: "0"}}
}
for i, req := range reqs {
- sep := util.Iif(i == 0, "", "&")
+ sep := util.Ternary(i == 0, "", "&")
_, _ = fmt.Fprintf(out, "%s%s %s", sep, req.Restriction, req.Version)
}
}
@@ -391,7 +391,7 @@ func makePackageVersionDependency(ctx *context.Context, version *packages_model.
buf.WriteString(version.Version)
buf.WriteByte(' ')
for i, dep := range metadata.RuntimeDependencies {
- sep := util.Iif(i == 0, "", ",")
+ sep := util.Ternary(i == 0, "", ",")
writePackageVersionRequirements(fmt.Sprintf("%s%s:", sep, dep.Name), dep.Version, buf)
}
_, _ = fmt.Fprintf(buf, "|checksum:%s", blob.HashSHA256)
diff --git a/routers/api/v1/misc/markup.go b/routers/api/v1/misc/markup.go
index 0cd4b8c5c5aa7..665081ab51e79 100644
--- a/routers/api/v1/misc/markup.go
+++ b/routers/api/v1/misc/markup.go
@@ -42,7 +42,7 @@ func Markup(ctx *context.APIContext) {
return
}
- mode := util.Iif(form.Wiki, "wiki", form.Mode) //nolint:staticcheck
+ mode := util.Ternary(form.Wiki, "wiki", form.Mode) //nolint:staticcheck
common.RenderMarkup(ctx.Base, ctx.Repo, mode, form.Text, form.Context, form.FilePath)
}
@@ -73,7 +73,7 @@ func Markdown(ctx *context.APIContext) {
return
}
- mode := util.Iif(form.Wiki, "wiki", form.Mode) //nolint:staticcheck
+ mode := util.Ternary(form.Wiki, "wiki", form.Mode) //nolint:staticcheck
common.RenderMarkup(ctx.Base, ctx.Repo, mode, form.Text, form.Context, "")
}
diff --git a/routers/init.go b/routers/init.go
index 744feee2f0db0..e9adb4806eb62 100644
--- a/routers/init.go
+++ b/routers/init.go
@@ -116,7 +116,7 @@ func InitWebInstalled(ctx context.Context) {
mustInitCtx(ctx, git.InitFull)
log.Info("Git version: %s (home: %s)", git.DefaultFeatures().VersionInfo(), git.HomeDir())
if !git.DefaultFeatures().SupportHashSha256 {
- log.Warn("sha256 hash support is disabled - requires Git >= 2.42." + util.Iif(git.DefaultFeatures().UsingGogit, " Gogit is currently unsupported.", ""))
+ log.Warn("sha256 hash support is disabled - requires Git >= 2.42." + util.Ternary(git.DefaultFeatures().UsingGogit, " Gogit is currently unsupported.", ""))
}
// Setup i18n
diff --git a/routers/web/devtest/mock_actions.go b/routers/web/devtest/mock_actions.go
index 3ce75dfad2d76..36ecae974d242 100644
--- a/routers/web/devtest/mock_actions.go
+++ b/routers/web/devtest/mock_actions.go
@@ -31,7 +31,7 @@ func generateMockStepsLog(logCur actions.LogCursor) (stepsLog []*actions.ViewSte
"##[endgroup]",
}
cur := logCur.Cursor // usually the cursor is the "file offset", but here we abuse it as "line number" to make the mock easier, intentionally
- mockCount := util.Iif(logCur.Step == 0, 3, 1)
+ mockCount := util.Ternary(logCur.Step == 0, 3, 1)
if logCur.Step == 1 && logCur.Cursor == 0 {
mockCount = 30 // for the first batch, return as many as possible to test the auto-expand and auto-scroll
}
diff --git a/routers/web/explore/org.go b/routers/web/explore/org.go
index 7bb71acfd78e0..66e54759c5ea8 100644
--- a/routers/web/explore/org.go
+++ b/routers/web/explore/org.go
@@ -40,7 +40,7 @@ func Organizations(ctx *context.Context) {
)
sortOrder := ctx.FormString("sort")
if sortOrder == "" {
- sortOrder = util.Iif(supportedSortOrders.Contains(setting.UI.ExploreDefaultSort), setting.UI.ExploreDefaultSort, "newest")
+ sortOrder = util.Ternary(supportedSortOrders.Contains(setting.UI.ExploreDefaultSort), setting.UI.ExploreDefaultSort, "newest")
ctx.SetFormString("sort", sortOrder)
}
diff --git a/routers/web/explore/user.go b/routers/web/explore/user.go
index e1e1ec1cfdbc4..2afc3c8223c77 100644
--- a/routers/web/explore/user.go
+++ b/routers/web/explore/user.go
@@ -147,7 +147,7 @@ func Users(ctx *context.Context) {
)
sortOrder := ctx.FormString("sort")
if sortOrder == "" {
- sortOrder = util.Iif(supportedSortOrders.Contains(setting.UI.ExploreDefaultSort), setting.UI.ExploreDefaultSort, "newest")
+ sortOrder = util.Ternary(supportedSortOrders.Contains(setting.UI.ExploreDefaultSort), setting.UI.ExploreDefaultSort, "newest")
ctx.SetFormString("sort", sortOrder)
}
diff --git a/routers/web/misc/markup.go b/routers/web/misc/markup.go
index 0c7ec6c2eb64f..733b26baad307 100644
--- a/routers/web/misc/markup.go
+++ b/routers/web/misc/markup.go
@@ -15,6 +15,6 @@ import (
// Markup render markup document to HTML
func Markup(ctx *context.Context) {
form := web.GetForm(ctx).(*api.MarkupOption)
- mode := util.Iif(form.Wiki, "wiki", form.Mode) //nolint:staticcheck
+ mode := util.Ternary(form.Wiki, "wiki", form.Mode) //nolint:staticcheck
common.RenderMarkup(ctx.Base, ctx.Repo, mode, form.Text, form.Context, form.FilePath)
}
diff --git a/routers/web/org/home.go b/routers/web/org/home.go
index e3c2dcf0bdd24..ea4691fa71bc7 100644
--- a/routers/web/org/home.go
+++ b/routers/web/org/home.go
@@ -155,7 +155,7 @@ func home(ctx *context.Context, viewRepositories bool) {
}
func prepareOrgProfileReadme(ctx *context.Context, prepareResult *shared_user.PrepareOrgHeaderResult) bool {
- viewAs := ctx.FormString("view_as", util.Iif(ctx.Org.IsMember, "member", "public"))
+ viewAs := ctx.FormString("view_as", util.Ternary(ctx.Org.IsMember, "member", "public"))
viewAsMember := viewAs == "member"
var profileRepo *repo_model.Repository
diff --git a/routers/web/repo/actions/view.go b/routers/web/repo/actions/view.go
index 41f0d2d0ec249..926c5852201ca 100644
--- a/routers/web/repo/actions/view.go
+++ b/routers/web/repo/actions/view.go
@@ -169,7 +169,7 @@ func getActionsViewArtifacts(ctx context.Context, repoID, runIndex int64) (artif
artifactsViewItems = append(artifactsViewItems, &ArtifactsViewItem{
Name: art.ArtifactName,
Size: art.FileSize,
- Status: util.Iif(art.Status == actions_model.ArtifactStatusExpired, "expired", "completed"),
+ Status: util.Ternary(art.Status == actions_model.ArtifactStatusExpired, "expired", "completed"),
})
}
return artifactsViewItems, nil
diff --git a/routers/web/repo/editor.go b/routers/web/repo/editor.go
index 113622f87293c..4476008ec0d35 100644
--- a/routers/web/repo/editor.go
+++ b/routers/web/repo/editor.go
@@ -190,7 +190,7 @@ func editFile(ctx *context.Context, isNewFile bool) {
ctx.Data["TreePaths"] = treePaths
ctx.Data["commit_summary"] = ""
ctx.Data["commit_message"] = ""
- ctx.Data["commit_choice"] = util.Iif(canCommit, frmCommitChoiceDirect, frmCommitChoiceNewBranch)
+ ctx.Data["commit_choice"] = util.Ternary(canCommit, frmCommitChoiceDirect, frmCommitChoiceNewBranch)
ctx.Data["new_branch_name"] = GetUniquePatchBranchName(ctx)
ctx.Data["last_commit"] = ctx.Repo.CommitID
diff --git a/routers/web/repo/release.go b/routers/web/repo/release.go
index 553bdbf6e5c5b..c6f4769d17cd3 100644
--- a/routers/web/repo/release.go
+++ b/routers/web/repo/release.go
@@ -465,7 +465,7 @@ func NewReleasePost(ctx *context.Context) {
return
}
- attachmentUUIDs := util.Iif(setting.Attachment.Enabled, form.Files, nil)
+ attachmentUUIDs := util.Ternary(setting.Attachment.Enabled, form.Files, nil)
// no existing release, create a new release
if rel == nil {
diff --git a/services/convert/issue.go b/services/convert/issue.go
index 7f386e629337d..d9d4f0b5884dc 100644
--- a/services/convert/issue.go
+++ b/services/convert/issue.go
@@ -58,7 +58,7 @@ func toIssue(ctx context.Context, doer *user_model.User, issue *issues_model.Iss
Comments: issue.NumComments,
Created: issue.CreatedUnix.AsTime(),
Updated: issue.UpdatedUnix.AsTime(),
- PinOrder: util.Iif(issue.PinOrder == -1, 0, issue.PinOrder), // -1 means loaded with no pin order
+ PinOrder: util.Ternary(issue.PinOrder == -1, 0, issue.PinOrder), // -1 means loaded with no pin order
}
if issue.Repo != nil {
diff --git a/services/convert/pull.go b/services/convert/pull.go
index 928534ce5e6b8..3ebcac911879e 100644
--- a/services/convert/pull.go
+++ b/services/convert/pull.go
@@ -95,7 +95,7 @@ func ToAPIPullRequest(ctx context.Context, pr *issues_model.PullRequest, doer *u
Deadline: apiIssue.Deadline,
Created: pr.Issue.CreatedUnix.AsTimePtr(),
Updated: pr.Issue.UpdatedUnix.AsTimePtr(),
- PinOrder: util.Iif(apiIssue.PinOrder == -1, 0, apiIssue.PinOrder),
+ PinOrder: util.Ternary(apiIssue.PinOrder == -1, 0, apiIssue.PinOrder),
// output "[]" rather than null to align to github outputs
RequestedReviewers: []*api.User{},
@@ -377,7 +377,7 @@ func ToAPIPullRequests(ctx context.Context, baseRepo *repo_model.Repository, prs
Deadline: apiIssue.Deadline,
Created: pr.Issue.CreatedUnix.AsTimePtr(),
Updated: pr.Issue.UpdatedUnix.AsTimePtr(),
- PinOrder: util.Iif(apiIssue.PinOrder == -1, 0, apiIssue.PinOrder),
+ PinOrder: util.Ternary(apiIssue.PinOrder == -1, 0, apiIssue.PinOrder),
AllowMaintainerEdit: pr.AllowMaintainerEdit,
diff --git a/services/gitdiff/gitdiff.go b/services/gitdiff/gitdiff.go
index 7208e1fb9641e..881626d66577f 100644
--- a/services/gitdiff/gitdiff.go
+++ b/services/gitdiff/gitdiff.go
@@ -323,7 +323,7 @@ func (diffSection *DiffSection) getDiffLineForRender(diffLineType DiffLineType,
} else {
// if left is empty or right is empty (a line is fully deleted or added), then we do not need to diff anymore.
// the tmpl code already adds background colors for these cases.
- lineHTML = util.Iif(diffLineType == DiffLineDel, diff1, diff2)
+ lineHTML = util.Ternary(diffLineType == DiffLineDel, diff1, diff2)
}
}
return DiffInlineWithUnicodeEscape(lineHTML, locale)
diff --git a/services/repository/files/tree.go b/services/repository/files/tree.go
index 9142416347c0c..69f19c49c113b 100644
--- a/services/repository/files/tree.go
+++ b/services/repository/files/tree.go
@@ -148,7 +148,7 @@ type TreeViewNode struct {
}
func (node *TreeViewNode) sortLevel() int {
- return util.Iif(node.EntryMode == "tree" || node.EntryMode == "commit", 0, 1)
+ return util.Ternary(node.EntryMode == "tree" || node.EntryMode == "commit", 0, 1)
}
func newTreeViewNodeFromEntry(ctx context.Context, commit *git.Commit, parentDir string, entry *git.TreeEntry) *TreeViewNode {
diff --git a/templates/admin/auth/list.tmpl b/templates/admin/auth/list.tmpl
index a1e72b742f2ea..811588566036f 100644
--- a/templates/admin/auth/list.tmpl
+++ b/templates/admin/auth/list.tmpl
@@ -25,7 +25,7 @@