package internal

import "github.com/gohugoio/hugo/tpl/internal"

Index

Package Files

templatefuncsRegistry.go

Variables

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

TemplateFuncsNamespaceRegistry describes a registry of functions that provide namespaces.

func AddTemplateFuncsNamespace

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

AddTemplateFuncsNamespace adds a given function to a registry.

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.

Directories

PathSynopsis
tpl/internal/go_templates
tpl/internal/go_templates/cfgPackage cfg holds configuration shared by the Go command and internal/testenv.
tpl/internal/go_templates/fmtsortPackage fmtsort provides a general stable ordering mechanism for maps, on behalf of the fmt and text/template packages.
tpl/internal/go_templates/htmltemplatePackage template (html/template) implements data-driven templates for generating HTML output safe against code injection.
tpl/internal/go_templates/testenvPackage testenv provides information about what functionality is available in different testing environments run by the Go team.
tpl/internal/go_templates/texttemplatePackage template implements data-driven templates for generating textual output.
tpl/internal/go_templates/texttemplate/parsePackage parse builds parse trees for templates as defined by text/template and html/template.
tpl/internal/resourcehelpers
Version
v0.101.0 (latest)
Published
Jun 16, 2022
Platform
linux/amd64
Imports
15 packages (graph)
Last checked
4 hours ago

Tools for package owners.