github.com/neohugo/neohugo@v0.123.8/tpl/tplimpl/template_errors.go (about) 1 // Copyright 2018 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 "fmt" 18 19 "github.com/neohugo/neohugo/common/herrors" 20 "github.com/neohugo/neohugo/hugofs" 21 "github.com/neohugo/neohugo/identity" 22 ) 23 24 var _ identity.Identity = (*templateInfo)(nil) 25 26 type templateInfo struct { 27 name string 28 template string 29 isText bool // HTML or plain text template. 30 isEmbedded bool 31 32 meta *hugofs.FileMeta 33 } 34 35 func (t templateInfo) IdentifierBase() string { 36 return t.name 37 } 38 39 func (t templateInfo) Name() string { 40 return t.name 41 } 42 43 func (t templateInfo) Filename() string { 44 return t.meta.Filename 45 } 46 47 func (t templateInfo) IsZero() bool { 48 return t.name == "" 49 } 50 51 func (t templateInfo) resolveType() templateType { 52 return resolveTemplateType(t.name) 53 } 54 55 func (info templateInfo) errWithFileContext(what string, err error) error { 56 err = fmt.Errorf(what+": %w", err) 57 fe := herrors.NewFileErrorFromName(err, info.meta.Filename) 58 f, err := info.meta.Open() 59 if err != nil { 60 return err 61 } 62 defer f.Close() 63 return fe.UpdateContent(f, nil) 64 }