valueobject

package
v0.0.0-...-f0d32e8 Latest Latest
Warning

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

Go to latest
Published: May 12, 2024 License: Apache-2.0 Imports: 37 Imported by: 0

Documentation

Index

Constants

View Source
const (
	TemplateVersion = 2
)

Variables

View Source
var DefaultParseConfig = ParseConfig{
	Version: TemplateVersion,
}
View Source
var DefaultParseInfo = ParseInfo{
	Config: DefaultParseConfig,
}
View Source
var TemplateFuncsNamespaceRegistry []func() *TemplateFuncsNamespace

Functions

func AddTemplateFuncsNamespace

func AddTemplateFuncsNamespace(ns func() *TemplateFuncsNamespace)

func IdentityOr

func IdentityOr(a, b template.Identity) template.Identity

func RegisterCallbackNamespaces

func RegisterCallbackNamespaces(cb func(ctx context.Context, name string, data any) (tmpl, res string, err error))

func RegisterExtendedNamespaces

func RegisterExtendedNamespaces(functions template.CustomizedFunctions)

func RegisterLookerNamespaces

func RegisterLookerNamespaces(functions template.CustomizedFunctions, looker collections.FuncLooker)

func RegisterNamespaces

func RegisterNamespaces()

Types

type BaseOf

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

func NewBaseOf

func NewBaseOf() *BaseOf

func (*BaseOf) AddBaseOf

func (bo *BaseOf) AddBaseOf(key string, info TemplateInfo)

func (*BaseOf) AddNeedsBaseOf

func (bo *BaseOf) AddNeedsBaseOf(key string, info TemplateInfo)

func (*BaseOf) GetBaseOf

func (bo *BaseOf) GetBaseOf(key string) (TemplateInfo, bool)

func (*BaseOf) GetNeedsBaseOf

func (bo *BaseOf) GetNeedsBaseOf(key string) (TemplateInfo, bool)

func (*BaseOf) IsBaseTemplatePath

func (bo *BaseOf) IsBaseTemplatePath(path string) bool

func (*BaseOf) NeedsBaseOf

func (bo *BaseOf) NeedsBaseOf(name, rawContent string) bool

type ParseConfig

type ParseConfig struct {
	Version int
}

type ParseInfo

type ParseInfo struct {
	// Set for shortcode templates with any {{ .Inner }}
	IsInner bool

	// Set for partials with a return statement.
	HasReturn bool

	// Config extracted from template.
	Config ParseConfig
}

func (ParseInfo) IsZero

func (info ParseInfo) IsZero() bool

func (ParseInfo) Return

func (info ParseInfo) Return() bool

type State

type State struct {
	template.Preparer

	Typ   template.Type
	PInfo ParseInfo
	Id    template.Identity

	Info     TemplateInfo
	BaseInfo TemplateInfo // Set when a base template is used.
}

func NewTemplateState

func NewTemplateState(templ template.Preparer, info TemplateInfo, id template.Identity) *State

func (*State) GetIdentity

func (t *State) GetIdentity() template.Identity

func (*State) IsInternalTemplate

func (t *State) IsInternalTemplate() bool

func (*State) IsText

func (t *State) IsText() bool

func (*State) ParseInfo

func (t *State) ParseInfo() ParseInfo

func (*State) String

func (t *State) String() string

type StateMap

type StateMap struct {
	Mu        sync.RWMutex
	Templates map[string]*State
}

type TemplateFuncMethodMapping

type TemplateFuncMethodMapping struct {
	Method any

	// Any template funcs aliases. This is mainly motivated by keeping
	// backwards compatibility, but some new template funcs may also make
	// sense to give short and snappy aliases.
	// Note that these aliases are global and will be merged, so the last
	// key will win.
	Aliases []string

	// A slice of input/expected examples.
	// We keep it a the namespace level for now, but may find a way to keep track
	// of the single template func, for documentation purposes.
	// Some of these, hopefully just a few, may depend on some test data to run.
	Examples [][2]string
}

TemplateFuncMethodMapping represents a mapping of functions to methods for a given namespace.

type TemplateFuncsNamespace

type TemplateFuncsNamespace struct {
	// The namespace name, "strings", "lang", etc.
	Name string

	// This is the method receiver.
	Context func(ctx context.Context, v ...any) (any, error)

	// Additional info, aliases and examples, per method name.
	MethodMappings map[string]TemplateFuncMethodMapping
}

TemplateFuncsNamespace represents a template function namespace.

func (*TemplateFuncsNamespace) AddMethodMapping

func (t *TemplateFuncsNamespace) AddMethodMapping(m any, aliases []string, examples [][2]string)

AddMethodMapping adds a method to a template function namespace.

type TemplateFuncsNamespaces

type TemplateFuncsNamespaces []*TemplateFuncsNamespace

TemplateFuncsNamespaces is a slice of TemplateFuncsNamespace.

func (TemplateFuncsNamespaces) MarshalJSON

func (namespaces TemplateFuncsNamespaces) MarshalJSON() ([]byte, error)

MarshalJSON returns the JSON encoding of namespaces.

func (TemplateFuncsNamespaces) ToMap

func (namespaces TemplateFuncsNamespaces) ToMap() map[string]any

ToMap returns a limited map representation of the namespaces.

type TemplateInfo

type TemplateInfo struct {
	Name       string
	Template   string
	IsText     bool // HTML or plain text template.
	IsEmbedded bool

	Meta *valueobject.FileMeta
}

func LoadTemplate

func LoadTemplate(name string, fim valueobject.FileMetaInfo) (TemplateInfo, error)

func (TemplateInfo) ErrWithFileContext

func (info TemplateInfo) ErrWithFileContext(what string, err error) error

func (TemplateInfo) IdentifierBase

func (info TemplateInfo) IdentifierBase() string

func (TemplateInfo) IsZero

func (info TemplateInfo) IsZero() bool

func (TemplateInfo) ResolveType

func (info TemplateInfo) ResolveType() template.Type

Jump to

Keyboard shortcuts

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