templates

package
v0.19.4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 24, 2023 License: MIT Imports: 50 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrTemplateNotInitialized = errors.New("template system is not initialized, check your log for errors")

Functions

func ActionContent2Commits

func ActionContent2Commits(act Actioner) *repository.PushCommits

ActionContent2Commits converts action content to push commits

func ActionIcon

func ActionIcon(opType activities_model.ActionType) string

ActionIcon accepts an action operation type and returns an icon class name.

func AssetFS

func AssetFS() *assetfs.LayeredFS

func Avatar

func Avatar(ctx context.Context, item interface{}, others ...interface{}) template.HTML

Avatar renders user avatars. args: user, size (int), class (string)

func AvatarByAction

func AvatarByAction(ctx context.Context, action *activities_model.Action, others ...interface{}) template.HTML

AvatarByAction renders user avatars from action. args: action, size (int), class (string)

func AvatarByEmail

func AvatarByEmail(ctx context.Context, email, name string, others ...interface{}) template.HTML

AvatarByEmail renders avatars by email address. args: email, name, size (int), class (string)

func AvatarHTML

func AvatarHTML(src string, size int, class, name string) template.HTML

AvatarHTML creates the HTML for an avatar

func BuiltinAssets

func BuiltinAssets() *assetfs.Layer

func CustomAssets

func CustomAssets() *assetfs.Layer

func DotEscape

func DotEscape(raw string) string

DotEscape wraps a dots in names with ZWJ [U+200D] in order to prevent autolinkers from detecting these as urls

func Eval

func Eval(tokens ...any) (any, error)

Eval the expression and return the result, see the comment of eval.Expr for details. To use this helper function in templates, pass each token as a separate parameter.

{{ $int64 := Eval $var "+" 1 }}
{{ $float64 := Eval $var "+" 1.0 }}

Golang's template supports comparable int types, so the int64 result can be used in later statements like {{if lt $int64 10}}

func FilenameIsImage

func FilenameIsImage(filename string) bool

func HandleTemplateRenderingError

func HandleTemplateRenderingError(err error) string

func IsMultilineCommitMessage

func IsMultilineCommitMessage(msg string) bool

IsMultilineCommitMessage checks to see if a commit message contains multiple lines.

func ListMailTemplateAssetNames

func ListMailTemplateAssetNames(assets *assetfs.LayeredFS) ([]string, error)

func ListWebTemplateAssetNames

func ListWebTemplateAssetNames(assets *assetfs.LayeredFS) ([]string, error)

func Mailer

Mailer provides the templates required for sending notification mails.

func MigrationIcon

func MigrationIcon(hostname string) string

MigrationIcon returns a SVG name matching the service an issue/comment was migrated from

func NewFuncMap

func NewFuncMap() template.FuncMap

NewFuncMap returns functions for injecting to templates

func ReactionToEmoji

func ReactionToEmoji(reaction string) template.HTML

ReactionToEmoji renders emoji for use in reactions

func ReloadHTMLTemplates

func ReloadHTMLTemplates() error

func RenderCodeBlock

func RenderCodeBlock(htmlEscapedTextToRender template.HTML) template.HTML

RenderCodeBlock renders "`…`" as highlighted "<code>" block. Intended for issue and PR titles, these containers should have styles for "<code>" elements

func RenderCommitBody

func RenderCommitBody(ctx context.Context, msg, urlPrefix string, metas map[string]string) template.HTML

RenderCommitBody extracts the body of a commit message without its title.

func RenderCommitMessage

func RenderCommitMessage(ctx context.Context, msg, urlPrefix string, metas map[string]string) template.HTML

RenderCommitMessage renders commit message with XSS-safe and special links.

func RenderCommitMessageLink(ctx context.Context, msg, urlPrefix, urlDefault string, metas map[string]string) template.HTML

RenderCommitMessageLink renders commit message as a XXS-safe link to the provided default url, handling for special links.

func RenderCommitMessageLinkSubject

func RenderCommitMessageLinkSubject(ctx context.Context, msg, urlPrefix, urlDefault string, metas map[string]string) template.HTML

RenderCommitMessageLinkSubject renders commit message as a XXS-safe link to the provided default url, handling for special links without email to links.

func RenderEmoji

func RenderEmoji(ctx context.Context, text string) template.HTML

RenderEmoji renders html text with emoji post processors

func RenderIssueTitle

func RenderIssueTitle(ctx context.Context, text, urlPrefix string, metas map[string]string) template.HTML

RenderIssueTitle renders issue/pull title with defined post processors

func RenderLabel

func RenderLabel(ctx context.Context, label *issues_model.Label) template.HTML

RenderLabel renders a label

func RenderLabels

func RenderLabels(ctx context.Context, labels []*issues_model.Label, repoLink string) template.HTML

func RenderMarkdownToHtml

func RenderMarkdownToHtml(ctx context.Context, input string) template.HTML

func RenderNote

func RenderNote(ctx context.Context, msg, urlPrefix string, metas map[string]string) template.HTML

RenderNote renders the contents of a git-notes file as a commit message.

func RepoAvatar

func RepoAvatar(repo *repo_model.Repository, others ...interface{}) template.HTML

RepoAvatar renders repo avatars. args: repo, size(int), class (string)

func Safe

func Safe(raw string) template.HTML

Safe render raw as HTML

func SortArrow

func SortArrow(normSort, revSort, urlSort string, isDefault bool) template.HTML

func Str2html

func Str2html(raw string) template.HTML

Str2html render Markdown text to HTML

func TabSizeClass

func TabSizeClass(ec interface{}, filename string) string

Types

type Actioner

type Actioner interface {
	GetOpType() activities_model.ActionType
	GetActUserName() string
	GetRepoUserName() string
	GetRepoName() string
	GetRepoPath() string
	GetRepoLink() string
	GetBranch() string
	GetContent() string
	GetCreate() time.Time
	GetIssueInfos() []string
}

Actioner describes an action

type HTMLRender

type HTMLRender struct {
	// contains filtered or unexported fields
}

func HTMLRenderer

func HTMLRenderer() *HTMLRender

HTMLRenderer init once and returns the globally shared html renderer

func (*HTMLRender) CompileTemplates

func (h *HTMLRender) CompileTemplates() error

func (*HTMLRender) HTML

func (h *HTMLRender) HTML(w io.Writer, status int, name string, data interface{}) error

func (*HTMLRender) TemplateLookup

func (h *HTMLRender) TemplateLookup(name string) (TemplateExecutor, error)

type JsonUtils

type JsonUtils struct{} //nolint:revive

func NewJsonUtils

func NewJsonUtils() *JsonUtils

func (*JsonUtils) EncodeToString

func (su *JsonUtils) EncodeToString(v any) string

func (*JsonUtils) PrettyIndent

func (su *JsonUtils) PrettyIndent(s string) string

type SliceUtils

type SliceUtils struct{}

func NewSliceUtils

func NewSliceUtils() *SliceUtils

func (*SliceUtils) Contains

func (su *SliceUtils) Contains(s, v any) bool

type StringUtils

type StringUtils struct{}

func NewStringUtils

func NewStringUtils() *StringUtils

func (*StringUtils) Contains

func (su *StringUtils) Contains(s, substr string) bool

func (*StringUtils) EllipsisString

func (su *StringUtils) EllipsisString(s string, max int) string

func (*StringUtils) HasPrefix

func (su *StringUtils) HasPrefix(s, prefix string) bool

func (*StringUtils) Join

func (su *StringUtils) Join(a []string, sep string) string

func (*StringUtils) Split

func (su *StringUtils) Split(s, sep string) []string

type TemplateExecutor

type TemplateExecutor scopedtmpl.TemplateExecutor

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL