diff options
author | Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com> | 2019-11-27 15:42:36 +0300 |
---|---|---|
committer | Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com> | 2019-12-18 13:44:40 +0300 |
commit | e625088ef5a970388ad50e464e87db56b358dac4 (patch) | |
tree | f7b26dec1f3695411558d05ca7d0995817a42250 /tpl/template.go | |
parent | 67f3aa72cf9aaf3d6e447fa6bc12de704d46adf7 (diff) |
Add render template hooks for links and images
This commit also
* revises the change detection for templates used by content files in server mode.
* Adds a Page.RenderString method
Fixes #6545
Fixes #4663
Closes #6043
Diffstat (limited to 'tpl/template.go')
-rw-r--r-- | tpl/template.go | 39 |
1 files changed, 24 insertions, 15 deletions
diff --git a/tpl/template.go b/tpl/template.go index db715c306..0841236de 100644 --- a/tpl/template.go +++ b/tpl/template.go @@ -24,8 +24,6 @@ import ( texttemplate "github.com/gohugoio/hugo/tpl/internal/go_templates/texttemplate" ) -var _ TemplateInfoProvider = (*TemplateInfo)(nil) - // TemplateManager manages the collection of templates. type TemplateManager interface { TemplateHandler @@ -34,7 +32,6 @@ type TemplateManager interface { AddLateTemplate(name, tpl string) error LoadTemplates(prefix string) error - MarkReady() error RebuildClone() } @@ -80,11 +77,6 @@ type Template interface { Prepare() (*texttemplate.Template, error) } -// TemplateInfoProvider provides some contextual information about a template. -type TemplateInfoProvider interface { - TemplateInfo() Info -} - // TemplateParser is used to parse ad-hoc templates, e.g. in the Resource chain. type TemplateParser interface { Parse(name, tpl string) (Template, error) @@ -101,10 +93,31 @@ type TemplateDebugger interface { Debug() } -// TemplateInfo wraps a Template with some additional information. -type TemplateInfo struct { +// templateInfo wraps a Template with some additional information. +type templateInfo struct { Template - Info Info + Info +} + +// templateInfo wraps a Template with some additional information. +type templateInfoManager struct { + Template + InfoManager +} + +// WithInfo wraps the info in a template. +func WithInfo(templ Template, info Info) Template { + if manager, ok := info.(InfoManager); ok { + return &templateInfoManager{ + Template: templ, + InfoManager: manager, + } + } + + return &templateInfo{ + Template: templ, + Info: info, + } } var baseOfRe = regexp.MustCompile("template: (.*?):") @@ -117,10 +130,6 @@ func extractBaseOf(err string) string { return "" } -func (t *TemplateInfo) TemplateInfo() Info { - return t.Info -} - // TemplateFuncGetter allows to find a template func by name. type TemplateFuncGetter interface { GetFunc(name string) (reflect.Value, bool) |