package tpl
import "github.com/gohugoio/hugo/tpl"
Index ¶
- Constants
- Variables
- type Config
- type Info
- type Template
- type TemplateAdapter
- func (t *TemplateAdapter) Execute(w io.Writer, data interface{}) (execErr error)
- func (t *TemplateAdapter) ExecuteToString(data interface{}) (string, error)
- func (t *TemplateAdapter) TemplateInfo() Info
- func (t *TemplateAdapter) Tree() string
- type TemplateDebugger
- type TemplateExecutor
- type TemplateFinder
- type TemplateFuncsGetter
- type TemplateHandler
- type TemplateInfoProvider
- type TemplateLookup
- type TemplateLookupVariant
- type TemplateParseFinder
- type TemplateParser
- type TemplateTestMocker
- type TemplateVariants
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 ¶
type Template ¶
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() error 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 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 ¶
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 ¶
TemplateVariants describes the possible variants of a template. All of these may be empty.
Source Files ¶
Directories ¶
Path | Synopsis |
---|---|
tpl/cast | Package cast provides template functions for data type conversions. |
tpl/collections | Package collections provides template functions for manipulating collections such as arrays, maps, and slices. |
tpl/compare | Package compare provides template functions for comparing values. |
tpl/crypto | Package crypto provides template functions for cryptographic operations. |
tpl/data | Package data provides template functions for working with external data sources. |
tpl/encoding | Package encoding provides template functions for encoding content. |
tpl/fmt | Package fmt provides template functions for formatting strings. |
tpl/hugo | Package hugo provides template functions for accessing the Site Hugo object. |
tpl/images | Package images provides template functions for manipulating images. |
tpl/inflect | Package inflect provides template functions for the inflection of words. |
tpl/internal | |
tpl/lang | Package lang provides template functions for content internationalization. |
tpl/math | Package math provides template functions for mathmatical operations. |
tpl/os | Package os provides template functions for interacting with the operating system. |
tpl/partials | Package partials provides template functions for working with reusable templates. |
tpl/path | Package path provides template functions for manipulating paths. |
tpl/reflect | Package reflect provides template functions for run-time object reflection. |
tpl/resources | Package resources provides template functions for working with resources. |
tpl/safe | Package safe provides template functions for escaping untrusted content or encapsulating trusted content. |
tpl/site | Package site provides template functions for accessing the Site object. |
tpl/strings | Package strings provides template functions for manipulating strings. |
tpl/templates | Package templates provides template functions for working with templates. |
tpl/time | Package time provides template functions for measuring and displaying time. |
tpl/tplimpl | |
tpl/tplimpl/embedded | Package embedded defines the internal templates that Hugo provides. |
tpl/tplimpl/embedded/generate | |
tpl/transform | Package transform provides template functions for transforming content. |
tpl/urls | Package urls provides template functions to deal with URLs. |
- Version
- v0.56.0
- Published
- Jul 25, 2019
- Platform
- windows/amd64
- Imports
- 16 packages
- Last checked
- 26 minutes ago –
Tools for package owners.