aboutsummaryrefslogtreecommitdiffstats
path: root/templates
diff options
context:
space:
mode:
authorwxiaoguang <wxiaoguang@gmail.com>2023-04-29 20:02:29 +0800
committerGitHub <noreply@github.com>2023-04-29 08:02:29 -0400
commit241b74f6c536c1d7de3b4e79e552bf1a3264cc6d (patch)
treeb6e482d056eeb1d00ca48de9161dc1123f6bbaf4 /templates
parent5a5ab8ef5ac5fbdb893707933f06ff6bcd8e834a (diff)
downloadgitea-241b74f6c536c1d7de3b4e79e552bf1a3264cc6d.tar.gz
gitea-241b74f6c536c1d7de3b4e79e552bf1a3264cc6d.zip
Improve template helper (#24417)
It seems that we really need the "context function" soon. So we should clean up the helper functions first. Major changes: * Improve StringUtils and add JsonUtils * Remove one-time-use helper functions like CompareLink * Move other code (no change) to util_avatar/util_render/util_misc (no need to propose changes for them) I have tested the changed templates: ![image](https://user-images.githubusercontent.com/2114189/235283862-608dbf6b-2da3-4d06-8157-b523ca93edb4.png) ![image](https://user-images.githubusercontent.com/2114189/235283888-1dfc0471-e622-4d64-9d76-7859819580d3.png) ![image](https://user-images.githubusercontent.com/2114189/235283903-d559f14d-4abb-4a50-915f-2b9cbc381a7a.png) ![image](https://user-images.githubusercontent.com/2114189/235283955-b7b5adea-aca3-4758-b38a-3aae3f7c6048.png) --------- Co-authored-by: Giteabot <teabot@gitea.io>
Diffstat (limited to 'templates')
-rw-r--r--templates/admin/auth/edit.tmpl2
-rw-r--r--templates/admin/config.tmpl8
-rw-r--r--templates/admin/queue.tmpl2
-rw-r--r--templates/package/shared/cleanup_rules/list.tmpl4
-rw-r--r--templates/repo/home.tmpl20
-rw-r--r--templates/repo/issue/new_form.tmpl2
-rw-r--r--templates/repo/issue/view_content/comments.tmpl10
-rw-r--r--templates/repo/release/new.tmpl2
-rw-r--r--templates/repo/view_list.tmpl10
-rw-r--r--templates/shared/actions/runner_edit.tmpl2
-rw-r--r--templates/user/heatmap.tmpl2
11 files changed, 42 insertions, 22 deletions
diff --git a/templates/admin/auth/edit.tmpl b/templates/admin/auth/edit.tmpl
index 0aed59ffab..2c8fe724e2 100644
--- a/templates/admin/auth/edit.tmpl
+++ b/templates/admin/auth/edit.tmpl
@@ -334,7 +334,7 @@
<div class="field">
<label for="oauth2_scopes">{{.locale.Tr "admin.auths.oauth2_scopes"}}</label>
- <input id="oauth2_scopes" name="oauth2_scopes" value="{{if $cfg.Scopes}}{{Join $cfg.Scopes ","}}{{end}}">
+ <input id="oauth2_scopes" name="oauth2_scopes" value="{{if $cfg.Scopes}}{{StringUtils.Join $cfg.Scopes ","}}{{end}}">
</div>
<div class="field">
<label for="oauth2_required_claim_name">{{.locale.Tr "admin.auths.oauth2_required_claim_name"}}</label>
diff --git a/templates/admin/config.tmpl b/templates/admin/config.tmpl
index f0d0ad3643..c4f77ec1ae 100644
--- a/templates/admin/config.tmpl
+++ b/templates/admin/config.tmpl
@@ -365,7 +365,7 @@
<dt>{{$.locale.Tr "admin.config.log_mode"}}</dt>
<dd>{{.Name}} ({{.Provider}})</dd>
<dt>{{$.locale.Tr "admin.config.log_config"}}</dt>
- <dd><pre>{{.Config | JsonPrettyPrint}}</pre></dd>
+ <dd><pre>{{JsonUtils.PrettyIndent .Config}}</pre></dd>
{{end}}
<div class="ui divider"></div>
<dt>{{$.locale.Tr "admin.config.router_log_mode"}}</dt>
@@ -378,7 +378,7 @@
<dt>{{$.locale.Tr "admin.config.log_mode"}}</dt>
<dd>{{.Name}} ({{.Provider}})</dd>
<dt>{{$.locale.Tr "admin.config.log_config"}}</dt>
- <dd><pre>{{.Config | JsonPrettyPrint}}</pre></dd>
+ <dd><pre>{{JsonUtils.PrettyIndent .Config}}</pre></dd>
{{end}}
{{else}}
<dd>{{$.locale.Tr "admin.config.routes_to_default_logger"}}</dd>
@@ -393,7 +393,7 @@
<dt>{{$.locale.Tr "admin.config.log_mode"}}</dt>
<dd>{{.Name}} ({{.Provider}})</dd>
<dt>{{$.locale.Tr "admin.config.log_config"}}</dt>
- <dd><pre>{{.Config | JsonPrettyPrint}}</pre></dd>
+ <dd><pre>{{JsonUtils.PrettyIndent .Config}}</pre></dd>
{{end}}
{{else}}
<dd>{{$.locale.Tr "admin.config.routes_to_default_logger"}}</dd>
@@ -412,7 +412,7 @@
<dt>{{$.locale.Tr "admin.config.log_mode"}}</dt>
<dd>{{.Name}} ({{.Provider}})</dd>
<dt>{{$.locale.Tr "admin.config.log_config"}}</dt>
- <dd><pre>{{.Config | JsonPrettyPrint}}</pre></dd>
+ <dd><pre>{{JsonUtils.PrettyIndent .Config}}</pre></dd>
{{end}}
{{else}}
<dd>{{$.locale.Tr "admin.config.routes_to_default_logger"}}</dd>
diff --git a/templates/admin/queue.tmpl b/templates/admin/queue.tmpl
index 3de01a32ab..84eb8892ef 100644
--- a/templates/admin/queue.tmpl
+++ b/templates/admin/queue.tmpl
@@ -174,7 +174,7 @@
{{.locale.Tr "admin.monitor.queue.configuration"}}
</h4>
<div class="ui attached segment">
- <pre>{{.Queue.Configuration | JsonPrettyPrint}}</pre>
+ <pre>{{JsonUtils.PrettyIndent .Queue.Configuration}}</pre>
</div>
</div>
diff --git a/templates/package/shared/cleanup_rules/list.tmpl b/templates/package/shared/cleanup_rules/list.tmpl
index 09f95e4f4a..10a073eb55 100644
--- a/templates/package/shared/cleanup_rules/list.tmpl
+++ b/templates/package/shared/cleanup_rules/list.tmpl
@@ -22,9 +22,9 @@
<a class="item" href="{{$.Link}}/rules/{{.ID}}"><strong>{{.Type.Name}}</strong></a>
<div><i>{{if .Enabled}}{{$.locale.Tr "enabled"}}{{else}}{{$.locale.Tr "disabled"}}{{end}}</i></div>
{{if .KeepCount}}<div><i>{{$.locale.Tr "packages.owner.settings.cleanuprules.keep.count"}}:</i> {{if eq .KeepCount 1}}{{$.locale.Tr "packages.owner.settings.cleanuprules.keep.count.1"}}{{else}}{{$.locale.Tr "packages.owner.settings.cleanuprules.keep.count.n" .KeepCount}}{{end}}</div>{{end}}
- {{if .KeepPattern}}<div><i>{{$.locale.Tr "packages.owner.settings.cleanuprules.keep.pattern"}}:</i> {{EllipsisString .KeepPattern 100}}</div>{{end}}
+ {{if .KeepPattern}}<div><i>{{$.locale.Tr "packages.owner.settings.cleanuprules.keep.pattern"}}:</i> {{StringUtils.EllipsisString .KeepPattern 100}}</div>{{end}}
{{if .RemoveDays}}<div><i>{{$.locale.Tr "packages.owner.settings.cleanuprules.remove.days"}}:</i> {{$.locale.Tr "tool.days" .RemoveDays}}</div>{{end}}
- {{if .RemovePattern}}<div><i>{{$.locale.Tr "packages.owner.settings.cleanuprules.remove.pattern"}}:</i> {{EllipsisString .RemovePattern 100}}</div>{{end}}
+ {{if .RemovePattern}}<div><i>{{$.locale.Tr "packages.owner.settings.cleanuprules.remove.pattern"}}:</i> {{StringUtils.EllipsisString .RemovePattern 100}}</div>{{end}}
</div>
</div>
{{else}}
diff --git a/templates/repo/home.tmpl b/templates/repo/home.tmpl
index c47fa9d9ca..de7c3a1dd0 100644
--- a/templates/repo/home.tmpl
+++ b/templates/repo/home.tmpl
@@ -68,7 +68,13 @@
{{$l := Eval $n "-" 1}}
<!-- If home page, show new pr. If not, show breadcrumb -->
{{if and (eq $n 0) .CanCompareOrPull .IsViewBranch (not .Repository.IsArchived)}}
- <a id="new-pull-request" role="button" class="ui compact basic button" href="{{CompareLink .BaseRepo .Repository .BranchName}}"
+ {{$cmpBranch := ""}}
+ {{if ne .Repository.ID .BaseRepo.ID}}
+ {{$cmpBranch = printf "%s/%s:" (.Repository.OwnerName|PathEscape) (.Repository.Name|PathEscape)}}
+ {{end}}
+ {{$cmpBranch = printf "%s%s" $cmpBranch (.BranchName|PathEscapeSegments)}}
+ {{$compareLink := printf "%s/compare/%s...%s" .BaseRepo.Link (.BaseRepo.DefaultBranch|PathEscapeSegments) $cmpBranch}}
+ <a id="new-pull-request" role="button" class="ui compact basic button" href="{{$compareLink}}"
data-tooltip-content="{{if .PullRequestCtx.Allowed}}{{.locale.Tr "repo.pulls.compare_changes"}}{{else}}{{.locale.Tr "action.compare_branch"}}{{end}}">
{{svg "octicon-git-pull-request"}}
</a>
@@ -103,7 +109,17 @@
</a>
{{end}}
{{if ne $n 0}}
- <span class="ui breadcrumb repo-path gt-ml-2"><a class="section" href="{{.RepoLink}}/src/{{.BranchNameSubURL}}" title="{{.Repository.Name}}">{{EllipsisString .Repository.Name 30}}</a>{{range $i, $v := .TreeNames}}<span class="divider">/</span>{{if eq $i $l}}<span class="active section" title="{{$v}}">{{EllipsisString $v 30}}</span>{{else}}{{$p := index $.Paths $i}}<span class="section"><a href="{{$.BranchLink}}/{{PathEscapeSegments $p}}" title="{{$v}}">{{EllipsisString $v 30}}</a></span>{{end}}{{end}}</span>
+ <span class="ui breadcrumb repo-path gt-ml-2">
+ <a class="section" href="{{.RepoLink}}/src/{{.BranchNameSubURL}}" title="{{.Repository.Name}}">{{StringUtils.EllipsisString .Repository.Name 30}}</a>
+ {{- range $i, $v := .TreeNames -}}
+ <span class="divider">/</span>
+ {{- if eq $i $l -}}
+ <span class="active section" title="{{$v}}">{{StringUtils.EllipsisString $v 30}}</span>
+ {{- else -}}
+ {{$p := index $.Paths $i}}<span class="section"><a href="{{$.BranchLink}}/{{PathEscapeSegments $p}}" title="{{$v}}">{{StringUtils.EllipsisString $v 30}}</a></span>
+ {{- end -}}
+ {{- end -}}
+ </span>
{{end}}
</div>
<div class="gt-df gt-ac">
diff --git a/templates/repo/issue/new_form.tmpl b/templates/repo/issue/new_form.tmpl
index d00a4813d2..d673e89a39 100644
--- a/templates/repo/issue/new_form.tmpl
+++ b/templates/repo/issue/new_form.tmpl
@@ -13,7 +13,7 @@
<div class="field">
<input name="title" id="issue_title" placeholder="{{.locale.Tr "repo.milestones.title"}}" value="{{if .TitleQuery}}{{.TitleQuery}}{{else if .IssueTemplateTitle}}{{.IssueTemplateTitle}}{{else}}{{.title}}{{end}}" tabindex="3" autofocus required maxlength="255" autocomplete="off">
{{if .PageIsComparePull}}
- <div class="title_wip_desc" data-wip-prefixes="{{Json .PullRequestWorkInProgressPrefixes}}">{{.locale.Tr "repo.pulls.title_wip_desc" (index .PullRequestWorkInProgressPrefixes 0| Escape) | Safe}}</div>
+ <div class="title_wip_desc" data-wip-prefixes="{{JsonUtils.EncodeToString .PullRequestWorkInProgressPrefixes}}">{{.locale.Tr "repo.pulls.title_wip_desc" (index .PullRequestWorkInProgressPrefixes 0| Escape) | Safe}}</div>
{{end}}
</div>
{{if .Fields}}
diff --git a/templates/repo/issue/view_content/comments.tmpl b/templates/repo/issue/view_content/comments.tmpl
index b99e49a586..464f41be1a 100644
--- a/templates/repo/issue/view_content/comments.tmpl
+++ b/templates/repo/issue/view_content/comments.tmpl
@@ -304,10 +304,12 @@
{{template "shared/user/avatarlink" dict "Context" $.Context "user" .Poster}}
<span class="text grey muted-links">
{{template "shared/user/authorlink" .Poster}}
- {{$parsedDeadline := .Content | ParseDeadline}}
- {{$from := DateTime "long" (index $parsedDeadline 1)}}
- {{$to := DateTime "long" (index $parsedDeadline 0)}}
- {{$.locale.Tr "repo.issues.due_date_modified" $to $from $createdStr | Safe}}
+ {{$parsedDeadline := StringUtils.Split .Content "|"}}
+ {{if eq (len $parsedDeadline) 2}}
+ {{$from := DateTime "long" (index $parsedDeadline 1)}}
+ {{$to := DateTime "long" (index $parsedDeadline 0)}}
+ {{$.locale.Tr "repo.issues.due_date_modified" $to $from $createdStr | Safe}}
+ {{end}}
</span>
</div>
{{else if eq .Type 18}}
diff --git a/templates/repo/release/new.tmpl b/templates/repo/release/new.tmpl
index fe8a6cfc55..2d34613dde 100644
--- a/templates/repo/release/new.tmpl
+++ b/templates/repo/release/new.tmpl
@@ -20,7 +20,7 @@
<b>{{.tag_name}}</b><span class="at">@</span><strong>{{.tag_target}}</strong>
{{else}}
<input id="tag-name" name="tag_name" value="{{.tag_name}}" aria-label="{{.locale.Tr "repo.release.tag_name"}}" placeholder="{{.locale.Tr "repo.release.tag_name"}}" autofocus required maxlength="255">
- <input id="tag-name-editor" type="hidden" data-existing-tags={{Json .Tags}} data-tag-helper={{.locale.Tr "repo.release.tag_helper"}} data-tag-helper-new={{.locale.Tr "repo.release.tag_helper_new"}} data-tag-helper-existing={{.locale.Tr "repo.release.tag_helper_existing"}}>
+ <input id="tag-name-editor" type="hidden" data-existing-tags="{{JsonUtils.EncodeToString .Tags}}" data-tag-helper="{{.locale.Tr "repo.release.tag_helper"}}" data-tag-helper-new="{{.locale.Tr "repo.release.tag_helper_new"}}" data-tag-helper-existing="{{.locale.Tr "repo.release.tag_helper_existing"}}">
<div id="tag-target-selector" class="gt-dib">
<span class="at">@</span>
<div class="ui selection dropdown">
diff --git a/templates/repo/view_list.tmpl b/templates/repo/view_list.tmpl
index 9540c872c2..602cda3614 100644
--- a/templates/repo/view_list.tmpl
+++ b/templates/repo/view_list.tmpl
@@ -61,13 +61,15 @@
{{else}}
{{if $entry.IsDir}}
{{$subJumpablePathName := $entry.GetSubJumpablePathName}}
- {{$subJumpablePath := SubJumpablePath $subJumpablePathName}}
{{svg "octicon-file-directory-fill"}}
<a class="muted" href="{{$.TreeLink}}/{{PathEscapeSegments $subJumpablePathName}}" title="{{$subJumpablePathName}}">
- {{if eq (len $subJumpablePath) 2}}
- <span class="color-text-light-2">{{index $subJumpablePath 0}}</span>{{index $subJumpablePath 1}}
+ {{$subJumpablePathFields := StringUtils.Split $subJumpablePathName "/"}}
+ {{$subJumpablePathFieldLast := (Eval (len $subJumpablePathFields) "-" 1)}}
+ {{if eq $subJumpablePathFieldLast 0}}
+ {{$subJumpablePathName}}
{{else}}
- {{index $subJumpablePath 0}}
+ {{$subJumpablePathPrefixes := slice $subJumpablePathFields 0 $subJumpablePathFieldLast}}
+ <span class="color-text-light-2">{{StringUtils.Join $subJumpablePathPrefixes "/"}}</span>/{{index $subJumpablePathFields $subJumpablePathFieldLast}}
{{end}}
</a>
{{else}}
diff --git a/templates/shared/actions/runner_edit.tmpl b/templates/shared/actions/runner_edit.tmpl
index c9edc59b1d..94da2269b7 100644
--- a/templates/shared/actions/runner_edit.tmpl
+++ b/templates/shared/actions/runner_edit.tmpl
@@ -37,7 +37,7 @@
</div>
<div class="field" data-tooltip-content="Labels are comma-separated. Whitespace at the beginning, end, and around the commas are ignored.">
<label for="custom_labels">{{.locale.Tr "actions.runners.custom_labels"}}</label>
- <input id="custom_labels" name="custom_labels" value="{{Join .Runner.CustomLabels `,`}}">
+ <input id="custom_labels" name="custom_labels" value="{{StringUtils.Join .Runner.CustomLabels `,`}}">
<p class="help">{{.locale.Tr "actions.runners.custom_labels_helper"}}</p>
</div>
diff --git a/templates/user/heatmap.tmpl b/templates/user/heatmap.tmpl
index 5d42a5435b..b0ee0eeaac 100644
--- a/templates/user/heatmap.tmpl
+++ b/templates/user/heatmap.tmpl
@@ -1,6 +1,6 @@
{{if .HeatmapData}}
<div id="user-heatmap"
- data-heatmap-data="{{Json .HeatmapData}}"
+ data-heatmap-data="{{JsonUtils.EncodeToString .HeatmapData}}"
data-locale-total-contributions="{{$.locale.Tr "heatmap.number_of_contributions_in_the_last_12_months" ($.locale.PrettyNumber .HeatmapTotalContributions)}}"
data-locale-no-contributions="{{.locale.Tr "heatmap.no_contributions"}}"
data-locale-more="{{.locale.Tr "heatmap.more"}}"