Documentation ¶
Index ¶
- Constants
- Variables
- func AddTemplateFuncsNamespace(ns func() *TemplateFuncsNamespace)
- func IdentityOr(a, b template.Identity) template.Identity
- func RegisterCallbackNamespaces(...)
- func RegisterExtendedNamespaces(functions template.CustomizedFunctions)
- func RegisterLookerNamespaces(functions template.CustomizedFunctions, looker collections.FuncLooker)
- func RegisterNamespaces()
- func ResetTemplateFuncsNamespaceRegistry()
- type BaseOf
- func (bo *BaseOf) AddBaseOf(key string, info TemplateInfo)
- func (bo *BaseOf) AddNeedsBaseOf(key string, info TemplateInfo)
- func (bo *BaseOf) GetBaseOf(key string) (TemplateInfo, bool)
- func (bo *BaseOf) GetNeedsBaseOf(key string) (TemplateInfo, bool)
- func (bo *BaseOf) GetTemplateSearchOrder(templateName string) []string
- func (bo *BaseOf) IsBaseTemplatePath(path string) bool
- func (bo *BaseOf) NeedsBaseOf(name, rawContent string) bool
- type LayoutCacheEntry
- type LayoutCacheKey
- type ParseConfig
- type ParseInfo
- type State
- type StateMap
- type TemplateFuncMethodMapping
- type TemplateFuncsNamespace
- type TemplateFuncsNamespaces
- type TemplateInfo
Constants ¶
View Source
const ( ShortcodesPathPrefix = "shortcodes/" InternalPathPrefix = "_internal/" EmbeddedPathPrefix = "_embedded/" )
View Source
const ( TemplateVersion = 2 NumTemplateVariants = 3 )
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 RegisterExtendedNamespaces ¶
func RegisterExtendedNamespaces(functions template.CustomizedFunctions)
func RegisterLookerNamespaces ¶
func RegisterLookerNamespaces(functions template.CustomizedFunctions, looker collections.FuncLooker)
func RegisterNamespaces ¶
func RegisterNamespaces()
func ResetTemplateFuncsNamespaceRegistry ¶ added in v0.0.10
func ResetTemplateFuncsNamespaceRegistry()
Types ¶
type BaseOf ¶
type BaseOf struct {
// contains filtered or unexported fields
}
func (*BaseOf) AddBaseOf ¶
func (bo *BaseOf) AddBaseOf(key string, info TemplateInfo)
func (*BaseOf) AddNeedsBaseOf ¶
func (bo *BaseOf) AddNeedsBaseOf(key string, info TemplateInfo)
func (*BaseOf) GetNeedsBaseOf ¶
func (bo *BaseOf) GetNeedsBaseOf(key string) (TemplateInfo, bool)
func (*BaseOf) GetTemplateSearchOrder ¶
GetTemplateSearchOrder 获取模板搜索顺序
func (*BaseOf) IsBaseTemplatePath ¶
func (*BaseOf) NeedsBaseOf ¶
type LayoutCacheEntry ¶
func NewLayoutCacheEntry ¶
func NewLayoutCacheEntry(found bool, templ template.Preparer, err error) LayoutCacheEntry
type LayoutCacheKey ¶
type LayoutCacheKey struct {
Names []string
}
func (LayoutCacheKey) IsEmpty ¶
func (k LayoutCacheKey) IsEmpty() bool
func (LayoutCacheKey) String ¶
func (k LayoutCacheKey) String() string
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 }
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 (*State) GetIdentity ¶
func (*State) IsInternalTemplate ¶
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 Fi fs.FileMetaInfo }
func LoadTemplate ¶
func LoadTemplate(name string, fim fs.FileMetaInfo) (TemplateInfo, error)
func LoadTemplateContent ¶
func LoadTemplateContent(name string, content string) (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
Source Files ¶
- baseof.go
- const.go
- identity.go
- info.go
- layout.go
- ns.go
- nscast.go
- nscollection.go
- nscompare.go
- nscrypto.go
- nscss.go
- nsdiagram.go
- nsencoding.go
- nsfmt.go
- nshugo.go
- nsinflect.go
- nslang.go
- nsmath.go
- nsos.go
- nspartials.go
- nspath.go
- nsreflect.go
- nsreg.go
- nsresource.go
- nssafe.go
- nssite.go
- nsstrings.go
- nstime.go
- nstransform.go
- nsurl.go
- parseinfo.go
- state.go
Click to show internal directories.
Click to hide internal directories.