Documentation
¶
Index ¶
- Variables
- func ActionContent2Commits(act Actioner) *repository.PushCommits
- func AssetFS() *assetfs.LayeredFS
- func AvatarHTML(src string, size int, class, name string) template.HTML
- func BuiltinAssets() *assetfs.Layer
- func CustomAssets() *assetfs.Layer
- func HandleTemplateRenderingError(err error) string
- func MailRendererReload() error
- func PageRendererReload() error
- func QueryBuild(a ...any) template.URL
- func ReloadAllTemplates() error
- func TimeSince(then any) template.HTML
- type Actioner
- type ActionsUtils
- type AvatarUtils
- type DateUtils
- type JsonUtils
- type MailRender
- type MarkdownEditorContext
- type MiscUtils
- type RenderUtils
- func (ut *RenderUtils) AvatarStack(data *user_model.AvatarStackData) template.HTML
- func (ut *RenderUtils) AvatarStackPushCommit(pushCommit *repository.PushCommit) template.HTML
- func (ut *RenderUtils) AvatarStackWithNames(data *user_model.AvatarStackData) template.HTML
- func (ut *RenderUtils) MarkdownToHtml(input string) template.HTML
- func (ut *RenderUtils) RenderCommitBody(msg string, repo *repo.Repository) template.HTML
- func (ut *RenderUtils) RenderCommitMessage(msg string, repo *repo.Repository) template.HTML
- func (ut *RenderUtils) RenderCommitMessageLinkSubject(msg, urlDefault string, repo *repo.Repository) template.HTML
- func (ut *RenderUtils) RenderEmoji(text string) template.HTML
- func (ut *RenderUtils) RenderFlashMessage(typ, msg string) template.HTML
- func (ut *RenderUtils) RenderIssueSimpleTitle(text string) template.HTML
- func (ut *RenderUtils) RenderIssueTitle(text string, repo *repo.Repository) template.HTML
- func (ut *RenderUtils) RenderLabel(label *issues_model.Label) template.HTML
- func (ut *RenderUtils) RenderLabels(labels []*issues_model.Label, repoLink string, issue *issues_model.Issue) template.HTML
- func (ut *RenderUtils) RenderPackageMarkdown(input string, linkedRepo *repo.Repository, pkgTreePath ...string) template.HTML
- func (ut *RenderUtils) RenderThemeItem(info *webtheme.ThemeMetaInfo, iconSize int) template.HTML
- func (ut *RenderUtils) RenderTimelineEventBadge(c *issues_model.Comment) template.HTML
- func (ut *RenderUtils) RenderTimelineEventComment(c *issues_model.Comment, createdStr template.HTML) template.HTML
- func (ut *RenderUtils) RenderUnicodeEscapeToggleButton(escapeStatus *charset.EscapeStatus) template.HTML
- func (ut *RenderUtils) RenderUnicodeEscapeToggleTd(combined, escapeStatus *charset.EscapeStatus) template.HTML
- type SliceUtils
- type StringUtils
- func (su *StringUtils) Contains(s, substr string) bool
- func (su *StringUtils) Cut(s, sep string) []any
- func (su *StringUtils) EllipsisString(s string, maxLength int) string
- func (su *StringUtils) HasPrefix(s, prefix string) bool
- func (su *StringUtils) Join(a []string, sep string) string
- func (su *StringUtils) Split(s, sep string) []string
- func (su *StringUtils) ToString(v any) string
- func (su *StringUtils) ToUpper(s string) string
- func (su *StringUtils) TrimPrefix(s, prefix string) string
- type TemplateExecutor
- type TplName
Constants ¶
This section is empty.
Variables ¶
var PageRenderer = sync.OnceValue(func() *pageRenderer { rendererType := util.Iif(setting.IsProd, "static", "auto-reloading") log.Debug("Creating %s HTML Renderer", rendererType) assetFS := AssetFS() tr := &tmplRender{ collectTemplateNames: func() ([]string, error) { names, err := assetFS.ListAllFiles(".", true) if err != nil { return nil, err } names = slices.DeleteFunc(names, func(file string) bool { return strings.HasPrefix(file, "mail/") || !strings.HasSuffix(file, ".tmpl") }) for i, file := range names { names[i] = strings.TrimSuffix(file, ".tmpl") } return names, nil }, readTemplateContent: func(name string) ([]byte, error) { return assetFS.ReadFile(name + ".tmpl") }, } pr := &pageRenderer{tmplRenderer: tr} if err := tr.recompileTemplates(pr.funcMapDummy()); err != nil { processStartupTemplateError(err) } if !setting.IsProd { go AssetFS().WatchLocalChanges(graceful.GetManager().ShutdownContext(), func() { if err := tr.recompileTemplates(pr.funcMapDummy()); err != nil { log.Error("Template error: %v\n%s", err, log.Stack(2)) } }) } return pr })
Functions ¶
func ActionContent2Commits ¶
func ActionContent2Commits(act Actioner) *repository.PushCommits
ActionContent2Commits converts action content to push commits
func AvatarHTML ¶
AvatarHTML creates the HTML for an avatar
func BuiltinAssets ¶
func CustomAssets ¶
func MailRendererReload ¶
func MailRendererReload() error
func PageRendererReload ¶
func PageRendererReload() error
func QueryBuild ¶
QueryBuild builds a query string from a list of key-value pairs. It omits the nil, false, zero int/int64 and empty string values, because they are default empty values for "ctx.FormXxx" calls. If 0 or false need to be included, use string values: "0" and "false". Build rules: * Even parameters: always build as query string: a=b&c=d * Odd parameters: * * {"/anything", param-pairs...} => "/?param-paris" * * {"anything?old-params", new-param-pairs...} => "anything?old-params&new-param-paris" * * Otherwise: {"old¶ms", new-param-pairs...} => "old¶ms&new-param-paris" * * Other behaviors are undefined yet.
func ReloadAllTemplates ¶
func ReloadAllTemplates() error
Types ¶
type Actioner ¶
type Actioner interface {
GetOpType() activities_model.ActionType
GetActUserName(ctx context.Context) string
GetRepoUserName(ctx context.Context) string
GetRepoName(ctx context.Context) string
GetRepoPath(ctx context.Context) string
GetRepoLink(ctx context.Context) string
GetBranch() string
GetContent() string
GetCreate() time.Time
GetIssueInfos() []string
}
Actioner describes an action
type ActionsUtils ¶
type ActionsUtils struct {
// contains filtered or unexported fields
}
func NewActionsUtils ¶
func NewActionsUtils(ctx context.Context) *ActionsUtils
func (*ActionsUtils) CommitStatusesToActionsStatuses ¶
func (a *ActionsUtils) CommitStatusesToActionsStatuses(statuses []*git_model.CommitStatus) actions_module.CommitActionsStatusMap
type AvatarUtils ¶
type AvatarUtils struct {
// contains filtered or unexported fields
}
func NewAvatarUtils ¶
func NewAvatarUtils(ctx context.Context) *AvatarUtils
func (*AvatarUtils) Avatar ¶
func (au *AvatarUtils) Avatar(item any, others ...any) template.HTML
Avatar renders user avatars. args: user, size (int), class (string)
func (*AvatarUtils) AvatarByAction ¶
func (au *AvatarUtils) AvatarByAction(action *activities_model.Action, others ...any) template.HTML
AvatarByAction renders user avatars from action. args: action, size (int), class (string)
func (*AvatarUtils) AvatarByEmail ¶
func (au *AvatarUtils) AvatarByEmail(email, name string, others ...any) template.HTML
AvatarByEmail renders avatars by email address. args: email, name, size (int), class (string)
type DateUtils ¶
type DateUtils struct{}
func NewDateUtils ¶
func NewDateUtils() *DateUtils
func (*DateUtils) AbsoluteLong ¶
AbsoluteLong renders in "January 01, 2006" format
func (*DateUtils) AbsoluteShort ¶
AbsoluteShort renders in "Jan 01, 2006" format
func (*DateUtils) ParseLegacy ¶
ParseLegacy parses the datetime in legacy format, eg: "2016-01-02" in server's timezone. It shouldn't be used in new code. New code should use Time or TimeStamp as much as possible.
type JsonUtils ¶
type JsonUtils struct{} //nolint:revive // variable naming triggers on Json, wants JSON
func NewJsonUtils ¶
func NewJsonUtils() *JsonUtils
func (*JsonUtils) EncodeToString ¶
func (*JsonUtils) PrettyIndent ¶
type MailRender ¶
type MailRender struct {
TemplateNames []string
BodyTemplates struct {
HasTemplate func(name string) bool
ExecuteTemplate func(w io.Writer, name string, data any) error
}
// FIXME: MAIL-TEMPLATE-SUBJECT: only "issue" related messages support using subject from templates
// It is an incomplete implementation from "Use templates for issue e-mail subject and body" https://github.com/go-gitea/gitea/pull/8329
SubjectTemplates *texttmpl.Template
// contains filtered or unexported fields
}
func MailRenderer ¶
func MailRenderer() *MailRender
func (*MailRender) MockTemplate ¶
func (r *MailRender) MockTemplate(name, subject, body string) func()
type MarkdownEditorContext ¶
type MiscUtils ¶
type MiscUtils struct {
// contains filtered or unexported fields
}
func NewMiscUtils ¶
func (*MiscUtils) MarkdownEditorComment ¶
func (m *MiscUtils) MarkdownEditorComment(repo *repo_model.Repository) *MarkdownEditorContext
func (*MiscUtils) MarkdownEditorGeneral ¶
func (m *MiscUtils) MarkdownEditorGeneral(owner *user_model.User) *MarkdownEditorContext
func (*MiscUtils) MarkdownEditorWiki ¶
func (m *MiscUtils) MarkdownEditorWiki(repo *repo_model.Repository) *MarkdownEditorContext
type RenderUtils ¶
type RenderUtils struct {
// contains filtered or unexported fields
}
func NewRenderUtils ¶
func NewRenderUtils(ctx reqctx.RequestContext) *RenderUtils
func (*RenderUtils) AvatarStack ¶
func (ut *RenderUtils) AvatarStack(data *user_model.AvatarStackData) template.HTML
AvatarStack renders overlapping avatars for the stack participants. It emits children in reverse so CSS `flex-direction: row-reverse` places the primary (Participants[0]) leftmost and last-painted (on top).
func (*RenderUtils) AvatarStackPushCommit ¶
func (ut *RenderUtils) AvatarStackPushCommit(pushCommit *repository.PushCommit) template.HTML
func (*RenderUtils) AvatarStackWithNames ¶
func (ut *RenderUtils) AvatarStackWithNames(data *user_model.AvatarStackData) template.HTML
AvatarStackWithNames renders the avatar stack plus a label: `name` / `a and b` / `N people` (opens popup).
func (*RenderUtils) MarkdownToHtml ¶
func (ut *RenderUtils) MarkdownToHtml(input string) template.HTML
func (*RenderUtils) RenderCommitBody ¶
func (ut *RenderUtils) RenderCommitBody(msg string, repo *repo.Repository) template.HTML
RenderCommitBody extracts the body of a commit message without its title.
func (*RenderUtils) RenderCommitMessage ¶
func (ut *RenderUtils) RenderCommitMessage(msg string, repo *repo.Repository) template.HTML
RenderCommitMessage renders commit message title (only title)
func (*RenderUtils) RenderCommitMessageLinkSubject ¶
func (ut *RenderUtils) RenderCommitMessageLinkSubject(msg, urlDefault string, repo *repo.Repository) template.HTML
RenderCommitMessageLinkSubject renders commit message as a XSS-safe link to the provided default url, handling for special links without email to links.
func (*RenderUtils) RenderEmoji ¶
func (ut *RenderUtils) RenderEmoji(text string) template.HTML
RenderEmoji renders html text with emoji post processors
func (*RenderUtils) RenderFlashMessage ¶
func (ut *RenderUtils) RenderFlashMessage(typ, msg string) template.HTML
func (*RenderUtils) RenderIssueSimpleTitle ¶
func (ut *RenderUtils) RenderIssueSimpleTitle(text string) template.HTML
RenderIssueSimpleTitle only renders with emoji and inline code block
func (*RenderUtils) RenderIssueTitle ¶
func (ut *RenderUtils) RenderIssueTitle(text string, repo *repo.Repository) template.HTML
RenderIssueTitle renders issue/pull title with defined post processors
func (*RenderUtils) RenderLabel ¶
func (ut *RenderUtils) RenderLabel(label *issues_model.Label) template.HTML
func (*RenderUtils) RenderLabels ¶
func (ut *RenderUtils) RenderLabels(labels []*issues_model.Label, repoLink string, issue *issues_model.Issue) template.HTML
func (*RenderUtils) RenderPackageMarkdown ¶
func (ut *RenderUtils) RenderPackageMarkdown(input string, linkedRepo *repo.Repository, pkgTreePath ...string) template.HTML
RenderPackageMarkdown renders package page Markdown so relative links resolve against the linked repository's default branch instead of the site root, falling back to plain rendering when there is no linked repository. pkgTreePath optionally roots links in a subdirectory (e.g. npm's repository.directory for monorepo packages).
func (*RenderUtils) RenderThemeItem ¶
func (ut *RenderUtils) RenderThemeItem(info *webtheme.ThemeMetaInfo, iconSize int) template.HTML
func (*RenderUtils) RenderTimelineEventBadge ¶
func (ut *RenderUtils) RenderTimelineEventBadge(c *issues_model.Comment) template.HTML
func (*RenderUtils) RenderTimelineEventComment ¶
func (ut *RenderUtils) RenderTimelineEventComment(c *issues_model.Comment, createdStr template.HTML) template.HTML
func (*RenderUtils) RenderUnicodeEscapeToggleButton ¶
func (ut *RenderUtils) RenderUnicodeEscapeToggleButton(escapeStatus *charset.EscapeStatus) template.HTML
func (*RenderUtils) RenderUnicodeEscapeToggleTd ¶
func (ut *RenderUtils) RenderUnicodeEscapeToggleTd(combined, escapeStatus *charset.EscapeStatus) template.HTML
type SliceUtils ¶
type SliceUtils struct{}
func NewSliceUtils ¶
func NewSliceUtils() *SliceUtils
func (*SliceUtils) Contains ¶
func (su *SliceUtils) Contains(s, v any) bool
func (*SliceUtils) JoinInt64 ¶
func (su *SliceUtils) JoinInt64(values []int64) string
JoinInt64 joins a slice of int64 values into a comma-separated string.
func (*SliceUtils) JoinToggleIDs ¶
func (su *SliceUtils) JoinToggleIDs(values []int64, target int64) (ret struct { IsIncluded bool ToggledIDs string }, )
type StringUtils ¶
type StringUtils struct{}
func NewStringUtils ¶
func NewStringUtils() *StringUtils
func (*StringUtils) Contains ¶
func (su *StringUtils) Contains(s, substr string) bool
func (*StringUtils) Cut ¶
func (su *StringUtils) Cut(s, sep string) []any
func (*StringUtils) EllipsisString ¶
func (su *StringUtils) EllipsisString(s string, maxLength int) string
func (*StringUtils) HasPrefix ¶
func (su *StringUtils) HasPrefix(s, prefix string) bool
func (*StringUtils) Split ¶
func (su *StringUtils) Split(s, sep string) []string
func (*StringUtils) ToString ¶
func (su *StringUtils) ToString(v any) string
func (*StringUtils) ToUpper ¶
func (su *StringUtils) ToUpper(s string) string
func (*StringUtils) TrimPrefix ¶
func (su *StringUtils) TrimPrefix(s, prefix string) string
type TemplateExecutor ¶
type TemplateExecutor scopedtmpl.TemplateExecutor