tmpl

package
v1.1.2 Latest Latest
Warning

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

Go to latest
Published: Dec 20, 2023 License: MIT Imports: 20 Imported by: 0

Documentation

Index

Constants

View Source
const (
	KindSMS  = Kind("sms")
	KindMail = Kind("mail")
)

Variables

View Source
var (
	VerifyPhoneNumber = Known[*VerifyPhoneNumberCtx]{
		Name: "verify_phone_number",
		Kind: KindSMS,
	}

	SendPhoneSecurityCode = Known[*SendPhoneSecurityCodeCtx]{
		Name: "send_phone_security_code",
		Kind: KindSMS,
	}

	RequestPasswordReset = Known[*RequestPasswordResetCtx]{
		Name: "request_password_reset",
		Kind: KindMail,
	}

	AccountCreationNotice = Known[*AccountCreationNoticeCtx]{
		Name: "account_creation_notice",
		Kind: KindMail,
	}

	VerifyMail = Known[*VerifyMailCtx]{
		Name: "verify_mail",
		Kind: KindMail,
	}

	InviteMail = Known[*InviteMailCtx]{
		Name: "user_invitation",
		Kind: KindMail,
	}
)

Functions

func AddToMap

func AddToMap(dst, src map[string]any)

AddToMap - add src's entries to dst

func PrepareFunctionMap

func PrepareFunctionMap() map[string]any

func RenderKnown

func RenderKnown[T Context](cfg config.Config, engine TemplateEngine, known Known[T], args T) (string, error)

func RenderKnownTo

func RenderKnownTo[T Context](cfg config.Config, engine TemplateEngine, known Known[T], args T, target io.Writer) error

Types

type AccountCreationNoticeCtx

type AccountCreationNoticeCtx struct {
	BaseContext
	Creator   models.User
	User      models.User
	ResetLink string
}

Context types

type BaseContext

type BaseContext struct {
	SiteName  string
	SiteURL   string
	PublicURL string
}

func (*BaseContext) SetPublicURL

func (bc *BaseContext) SetPublicURL(url string)

func (*BaseContext) SetSiteName

func (bc *BaseContext) SetSiteName(name string)

func (*BaseContext) SetSiteURL

func (bc *BaseContext) SetSiteURL(url string)

type Context

type Context interface {
	SetSiteName(name string)
	SetSiteURL(name string)
	SetPublicURL(url string)
}

type Engine

type Engine struct {
	SMS  TemplateEngine
	Mail TemplateEngine
}

func New

func New(fileSystems ...fs.FS) (*Engine, error)

type InviteMailCtx

type InviteMailCtx struct {
	BaseContext
	RegisterURL string
	Name        string
	Inviter     models.User
}

Context types

type Kind

type Kind string

type Known

type Known[C Context] struct {
	Kind Kind
	Name string
}

Known is a known template that provides strong typing for the template variables and is bound by name.

type RenderContext

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

func NewRenderContext

func NewRenderContext() *RenderContext

func (*RenderContext) Get

func (rc *RenderContext) Get(key string) any

func (*RenderContext) Set

func (rc *RenderContext) Set(key string, value any)

type RequestPasswordResetCtx

type RequestPasswordResetCtx struct {
	BaseContext
	User      models.User
	ResetLink string
}

Context types

type SendPhoneSecurityCodeCtx

type SendPhoneSecurityCodeCtx struct {
	BaseContext
	Code string
}

Context types

type TemplateEngine

type TemplateEngine interface {
	ExecuteTemplate(wr io.Writer, name string, data any) error
}

func NewHTMLEngine

func NewHTMLEngine(fs fs.FS, kind Kind) (TemplateEngine, error)

func NewTextEngine

func NewTextEngine(fs fs.FS, kind Kind) (TemplateEngine, error)

type VerifyMailCtx

type VerifyMailCtx struct {
	BaseContext
	User       models.User
	VerifyLink string
}

Context types

type VerifyPhoneNumberCtx

type VerifyPhoneNumberCtx struct {
	BaseContext
	Code string
}

Context types

Jump to

Keyboard shortcuts

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