package tpl

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

Index

Constants

const TemplateVersion = 2

Increments on breaking changes.

Variables

var DefaultConfig = Config{
	Version: TemplateVersion,
}

Types

type Config

type Config struct {
	Version int
}

type Info

type Info struct {

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

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

	// Config extracted from template.
	Config Config
}

Info holds some info extracted from a parsed template.

func (Info) IsZero

func (info Info) IsZero() bool

type Template

type Template interface {
	Execute(wr io.Writer, data interface{}) error
	Name() string
}

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

type TemplateAdapter

type TemplateAdapter struct {
	Template
	Metrics metrics.Provider

	Info Info

	// The filesystem where the templates are stored.
	Fs afero.Fs

	// Maps to base template if relevant.
	NameBaseTemplateName map[string]string
}

TemplateAdapter implements the TemplateExecutor interface.

func (*TemplateAdapter) Execute

func (t *TemplateAdapter) Execute(w io.Writer, data interface{}) (execErr error)

Execute executes the current template. The actual execution is performed by the embedded text or html template, but we add an implementation here so we can add a timer for some metrics.

func (*TemplateAdapter) ExecuteToString

func (t *TemplateAdapter) ExecuteToString(data interface{}) (string, error)

ExecuteToString executes the current template and returns the result as a string.

func (*TemplateAdapter) TemplateInfo

func (t *TemplateAdapter) TemplateInfo() Info

func (*TemplateAdapter) Tree

func (t *TemplateAdapter) Tree() string

Tree returns the template Parse tree as a string. Note: this isn't safe for parallel execution on the same template vs Lookup and Execute.

type TemplateDebugger

type TemplateDebugger interface {
	Debug()
}

TemplateDebugger prints some debug info to stdoud.

type TemplateExecutor

type TemplateExecutor interface {
	Template
	ExecuteToString(data interface{}) (string, error)
	Tree() string
}

TemplateExecutor adds some extras to Template.

type TemplateFinder

type TemplateFinder interface {
	TemplateLookup
	TemplateLookupVariant
}

TemplateFinder finds templates.

type TemplateFuncsGetter

type TemplateFuncsGetter interface {
	GetFuncs() map[string]interface{}
}

TemplateFuncsGetter allows to get a map of functions.

type TemplateHandler

type TemplateHandler interface {
	TemplateFinder
	AddTemplate(name, tpl string) error
	AddLateTemplate(name, tpl string) error
	LoadTemplates(prefix string) error

	NewTextTemplate() TemplateParseFinder

	MarkReady()
	RebuildClone()
}

TemplateHandler manages the collection of templates.

type TemplateInfoProvider

type TemplateInfoProvider interface {
	TemplateInfo() Info
}

TemplateInfoProvider provides some contextual information about a template.

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)
}

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 TemplateTestMocker

type TemplateTestMocker interface {
	SetFuncs(funcMap map[string]interface{})
}

TemplateTestMocker adds a way to override some template funcs during tests. The interface is named so it's not used in regular application code.

type TemplateVariants

type TemplateVariants struct {
	Language     string
	OutputFormat output.Format
}

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

Source Files

template.go template_info.go

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/encodingPackage encoding provides template functions for encoding content.
tpl/fmtPackage fmt provides template functions for formatting strings.
tpl/hugo
tpl/imagesPackage images provides template functions for manipulating images.
tpl/inflectPackage inflect provides template functions for the inflection of words.
tpl/internal
tpl/langPackage lang provides template functions for content internationalization.
tpl/mathPackage math provides template functions for mathmatical operations.
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/reflect
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/site
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/tplimpl/embeddedPackage embedded defines the internal templates that Hugo provides.
tpl/tplimpl/embedded/generate
tpl/transformPackage transform provides template functions for transforming content.
tpl/urlsPackage urls provides template functions to deal with URLs.
Version
v0.55.1
Published
Apr 12, 2019
Platform
windows/amd64
Imports
16 packages
Last checked
25 minutes ago

Tools for package owners.