internal

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Dec 20, 2022 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var TemplateFuncsNamespaceRegistry []func(d *deps.Deps) *TemplateFuncsNamespace

TemplateFuncsNamespaceRegistry describes a registry of functions that provide namespaces.

Functions

func AddTemplateFuncsNamespace

func AddTemplateFuncsNamespace(ns func(d *deps.Deps) *TemplateFuncsNamespace)

AddTemplateFuncsNamespace adds a given function to a registry.

Types

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(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 added in v1.0.0

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

ToMap returns a limited map representation of the namespaces.

Directories

Path Synopsis
go_templates
cfg
Package cfg holds configuration shared by the Go command and internal/testenv.
Package cfg holds configuration shared by the Go command and internal/testenv.
fmtsort
Package fmtsort provides a general stable ordering mechanism for maps, on behalf of the fmt and text/template packages.
Package fmtsort provides a general stable ordering mechanism for maps, on behalf of the fmt and text/template packages.
htmltemplate
Package template (html/template) implements data-driven templates for generating HTML output safe against code injection.
Package template (html/template) implements data-driven templates for generating HTML output safe against code injection.
testenv
Package testenv provides information about what functionality is available in different testing environments run by the Go team.
Package testenv provides information about what functionality is available in different testing environments run by the Go team.
texttemplate
Package template implements data-driven templates for generating textual output.
Package template implements data-driven templates for generating textual output.
texttemplate/parse
Package parse builds parse trees for templates as defined by text/template and html/template.
Package parse builds parse trees for templates as defined by text/template and html/template.

Jump to

Keyboard shortcuts

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