package tpl

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

Index

Package Files

template.go template_info.go

Constants

const TemplateVersion = 2

Increments on breaking changes.

Variables

var DefaultParseConfig = ParseConfig{
    Version: TemplateVersion,
}
var DefaultParseInfo = ParseInfo{
    Config: DefaultParseConfig,
}

func GetDataFromContext

func GetDataFromContext(ctx context.Context) any

GetDataFromContext returns the template data context (usually .Page) from ctx if set. NOte: This is not fully implemented yet.

func GetHasLockFromContext

func GetHasLockFromContext(ctx context.Context) bool

func SetHasLockInContext

func SetHasLockInContext(ctx context.Context, hasLock bool) context.Context

type FileInfo

type FileInfo interface {
    Name() string
    Filename() string
}

type Info

type Info interface {
    ParseInfo() ParseInfo

    // Identifies this template and its dependencies.
    identity.Provider
}

func NewInfo

func NewInfo(id identity.Manager, parseInfo ParseInfo) Info

type InfoManager

type InfoManager interface {
    ParseInfo() ParseInfo

    // Identifies and manages this template and its dependencies.
    identity.Manager
}

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

type Template

type Template interface {
    Name() string
    Prepare() (*texttemplate.Template, error)
}

Template is the common interface between text/template and html/template.

func WithInfo

func WithInfo(templ Template, info Info) Template

WithInfo wraps the info in a template.

type TemplateDebugger

type TemplateDebugger interface {
    Debug()
}

TemplateDebugger prints some debug info to stdout.

type TemplateFinder

type TemplateFinder interface {
    TemplateLookup
    TemplateLookupVariant
}

TemplateFinder finds templates.

type TemplateFuncGetter

type TemplateFuncGetter interface {
    GetFunc(name string) (reflect.Value, bool)
}

TemplateFuncGetter allows to find a template func by name.

type TemplateHandler

type TemplateHandler interface {
    TemplateFinder
    Execute(t Template, wr io.Writer, data any) error
    ExecuteWithContext(ctx context.Context, t Template, wr io.Writer, data any) error
    LookupLayout(d output.LayoutDescriptor, f output.Format) (Template, bool, error)
    HasTemplate(name string) bool
}

TemplateHandler finds and executes templates.

type TemplateLookup

type TemplateLookup interface {
    Lookup(name string) (Template, bool)
}

type TemplateLookupVariant

type TemplateLookupVariant interface {
    // TODO(bep) this currently only works for shortcodes.
    // We may unify and expand this variant pattern to the
    // other templates, but we need this now for the shortcodes to
    // quickly determine if a shortcode has a template for a given
    // output format.
    // It returns the template, if it was found or not and if there are
    // alternative representations (output format, language).
    // We are currently only interested in output formats, so we should improve
    // this for speed.
    LookupVariant(name string, variants TemplateVariants) (Template, bool, bool)
    LookupVariants(name string) []Template
}

type TemplateManager

type TemplateManager interface {
    TemplateHandler
    TemplateFuncGetter
    AddTemplate(name, tpl string) error
    MarkReady() error
}

TemplateManager manages the collection of templates.

type TemplateParseFinder

type TemplateParseFinder interface {
    TemplateParser
    TemplateFinder
}

TemplateParseFinder provides both parsing and finding.

type TemplateParser

type TemplateParser interface {
    Parse(name, tpl string) (Template, error)
}

TemplateParser is used to parse ad-hoc templates, e.g. in the Resource chain.

type TemplateVariants

type TemplateVariants struct {
    Language     string
    OutputFormat output.Format
}

TemplateVariants describes the possible variants of a template. All of these may be empty.

type TemplatesProvider

type TemplatesProvider interface {
    Tmpl() TemplateHandler
    TextTmpl() TemplateParseFinder
}

TemplatesProvider as implemented by deps.Deps.

type UnusedTemplatesProvider

type UnusedTemplatesProvider interface {
    UnusedTemplates() []FileInfo
}

UnusedTemplatesProvider lists unused templates if the build is configured to track those.

Directories

PathSynopsis
tpl/castPackage cast provides template functions for data type conversions.
tpl/collectionsPackage collections provides template functions for manipulating collections such as arrays, maps, and slices.
tpl/comparePackage compare provides template functions for comparing values.
tpl/cryptoPackage crypto provides template functions for cryptographic operations.
tpl/dataPackage data provides template functions for working with external data sources.
tpl/debugPackage debug provides template functions to help debugging templates.
tpl/diagrams
tpl/encodingPackage encoding provides template functions for encoding content.
tpl/fmtPackage fmt provides template functions for formatting strings.
tpl/hugoPackage hugo provides template functions for accessing the Site Hugo object.
tpl/imagesPackage images provides template functions for manipulating images.
tpl/inflectPackage inflect provides template functions for the inflection of words.
tpl/internal
tpl/jsPackage js provides functions for building JavaScript resources
tpl/langPackage lang provides template functions for content internationalization.
tpl/mathPackage math provides template functions for mathematical operations.
tpl/openapi
tpl/openapi/openapi3
tpl/osPackage os provides template functions for interacting with the operating system.
tpl/partialsPackage partials provides template functions for working with reusable templates.
tpl/pathPackage path provides template functions for manipulating paths.
tpl/reflectPackage reflect provides template functions for run-time object reflection.
tpl/resourcesPackage resources provides template functions for working with resources.
tpl/safePackage safe provides template functions for escaping untrusted content or encapsulating trusted content.
tpl/sitePackage site provides template functions for accessing the Site object.
tpl/stringsPackage strings provides template functions for manipulating strings.
tpl/templatesPackage templates provides template functions for working with templates.
tpl/timePackage time provides template functions for measuring and displaying time.
tpl/tplimpl
tpl/transformPackage transform provides template functions for transforming content.
tpl/urlsPackage urls provides template functions to deal with URLs.
Version
v0.99.1 (latest)
Published
May 18, 2022
Platform
linux/amd64
Imports
7 packages (graph)
Last checked
1 hour ago

Tools for package owners.