tpl

package
v0.58.0 Latest Latest
Warning

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

Go to latest
Published: Sep 4, 2019 License: Apache-2.0 Imports: 16 Imported by: 216

Documentation

Index

Constants

View Source
const TemplateVersion = 2

Increments on breaking changes.

Variables

View Source
var DefaultConfig = Config{
	Version: TemplateVersion,
}

Functions

This section is empty.

Types

type Config added in v0.55.0

type Config struct {
	Version int
}

type Info added in v0.55.0

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 added in v0.55.0

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 added in v0.20.1

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 added in v0.27.1

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 added in v0.20.1

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

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

func (*TemplateAdapter) TemplateInfo added in v0.55.0

func (t *TemplateAdapter) TemplateInfo() Info

func (*TemplateAdapter) Tree added in v0.20.1

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 added in v0.22.1

type TemplateDebugger interface {
	Debug()
}

TemplateDebugger prints some debug info to stdoud.

type TemplateExecutor added in v0.20.1

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

TemplateExecutor adds some extras to Template.

type TemplateFinder added in v0.20.1

type TemplateFinder interface {
	TemplateLookup
	TemplateLookupVariant
}

TemplateFinder finds templates.

type TemplateFuncsGetter added in v0.22.1

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

TemplateFuncsGetter allows to get a map of functions.

type TemplateHandler added in v0.20.1

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

	NewTextTemplate() TemplateParseFinder

	MarkReady() error
	RebuildClone()
}

TemplateHandler manages the collection of templates.

type TemplateInfoProvider added in v0.55.0

type TemplateInfoProvider interface {
	TemplateInfo() Info
}

TemplateInfoProvider provides some contextual information about a template.

type TemplateLookup added in v0.55.0

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

type TemplateLookupVariant added in v0.55.0

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 added in v0.45.1

type TemplateParseFinder interface {
	TemplateParser
	TemplateFinder
}

TemplateParseFinder provides both parsing and finding.

type TemplateParser added in v0.45.1

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 added in v0.20.1

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 added in v0.55.0

type TemplateVariants struct {
	Language     string
	OutputFormat output.Format
}

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

Directories

Path Synopsis
Package cast provides template functions for data type conversions.
Package cast provides template functions for data type conversions.
Package collections provides template functions for manipulating collections such as arrays, maps, and slices.
Package collections provides template functions for manipulating collections such as arrays, maps, and slices.
Package compare provides template functions for comparing values.
Package compare provides template functions for comparing values.
Package crypto provides template functions for cryptographic operations.
Package crypto provides template functions for cryptographic operations.
Package data provides template functions for working with external data sources.
Package data provides template functions for working with external data sources.
Package encoding provides template functions for encoding content.
Package encoding provides template functions for encoding content.
Package fmt provides template functions for formatting strings.
Package fmt provides template functions for formatting strings.
Package hugo provides template functions for accessing the Site Hugo object.
Package hugo provides template functions for accessing the Site Hugo object.
Package images provides template functions for manipulating images.
Package images provides template functions for manipulating images.
Package inflect provides template functions for the inflection of words.
Package inflect provides template functions for the inflection of words.
Package lang provides template functions for content internationalization.
Package lang provides template functions for content internationalization.
Package math provides template functions for mathmatical operations.
Package math provides template functions for mathmatical operations.
Package os provides template functions for interacting with the operating system.
Package os provides template functions for interacting with the operating system.
Package partials provides template functions for working with reusable templates.
Package partials provides template functions for working with reusable templates.
Package path provides template functions for manipulating paths.
Package path provides template functions for manipulating paths.
Package reflect provides template functions for run-time object reflection.
Package reflect provides template functions for run-time object reflection.
Package resources provides template functions for working with resources.
Package resources provides template functions for working with resources.
Package safe provides template functions for escaping untrusted content or encapsulating trusted content.
Package safe provides template functions for escaping untrusted content or encapsulating trusted content.
Package site provides template functions for accessing the Site object.
Package site provides template functions for accessing the Site object.
Package strings provides template functions for manipulating strings.
Package strings provides template functions for manipulating strings.
Package templates provides template functions for working with templates.
Package templates provides template functions for working with templates.
Package time provides template functions for measuring and displaying time.
Package time provides template functions for measuring and displaying time.
embedded
Package embedded defines the internal templates that Hugo provides.
Package embedded defines the internal templates that Hugo provides.
Package transform provides template functions for transforming content.
Package transform provides template functions for transforming content.
Package urls provides template functions to deal with URLs.
Package urls provides template functions to deal with URLs.

Jump to

Keyboard shortcuts

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