mirror of
https://github.com/go-gitea/gitea
synced 2025-07-22 18:28:37 +00:00
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:     --------- Co-authored-by: Giteabot <teabot@gitea.io>
This commit is contained in:
@@ -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>
|
||||
|
@@ -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>
|
||||
|
@@ -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>
|
||||
|
||||
|
@@ -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}}
|
||||
|
@@ -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">
|
||||
|
@@ -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}}
|
||||
|
@@ -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}}
|
||||
|
@@ -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">
|
||||
|
@@ -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}}
|
||||
|
@@ -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>
|
||||
|
||||
|
@@ -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"}}"
|
||||
|
Reference in New Issue
Block a user