tmpl

package
v0.12.4 Latest Latest
Warning

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

Go to latest
Published: Oct 28, 2024 License: MIT Imports: 23 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(q *repo.Queries) 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   repo.User
	User      repo.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(repo *repo.Queries, fileSystems ...fs.FS) (*Engine, error)

type InviteMailCtx

type InviteMailCtx struct {
	BaseContext
	RegisterURL string
	Name        string
	Inviter     repo.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      repo.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, repo *repo.Queries) (TemplateEngine, error)

func NewTextEngine

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

type VerifyMailCtx

type VerifyMailCtx struct {
	BaseContext
	User       repo.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