github.com/neohugo/neohugo@v0.123.8/tpl/tplimpl/templateProvider.go (about) 1 // Copyright 2017-present The Hugo Authors. All rights reserved. 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // http://www.apache.org/licenses/LICENSE-2.0 7 // 8 // Unless required by applicable law or agreed to in writing, software 9 // distributed under the License is distributed on an "AS IS" BASIS, 10 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 // See the License for the specific language governing permissions and 12 // limitations under the License. 13 14 package tplimpl 15 16 import ( 17 "github.com/neohugo/neohugo/deps" 18 "github.com/neohugo/neohugo/tpl" 19 ) 20 21 // TemplateProvider manages templates. 22 type TemplateProvider struct{} 23 24 // DefaultTemplateProvider is a globally available TemplateProvider. 25 var DefaultTemplateProvider *TemplateProvider 26 27 // Update updates the Hugo Template System in the provided Deps 28 // with all the additional features, templates & functions. 29 func (*TemplateProvider) NewResource(dst *deps.Deps) error { 30 handlers, err := newTemplateHandlers(dst) 31 if err != nil { 32 return err 33 } 34 dst.SetTempl(handlers) 35 return nil 36 } 37 38 // Clone clones. 39 func (*TemplateProvider) CloneResource(dst, src *deps.Deps) error { 40 t := src.Tmpl().(*templateExec) 41 c := t.Clone(dst) 42 funcMap := make(map[string]any) 43 for k, v := range c.funcs { 44 funcMap[k] = v.Interface() 45 } 46 dst.SetTempl(&tpl.TemplateHandlers{ 47 Tmpl: c, 48 TxtTmpl: newStandaloneTextTemplate(funcMap), 49 }) 50 return nil 51 }