github.com/gohugoio/hugo@v0.88.1/tpl/template_info.go (about) 1 // Copyright 2019 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 tpl 15 16 import ( 17 "github.com/gohugoio/hugo/identity" 18 ) 19 20 // Increments on breaking changes. 21 const TemplateVersion = 2 22 23 type Info interface { 24 ParseInfo() ParseInfo 25 26 // Identifies this template and its dependencies. 27 identity.Provider 28 } 29 30 type InfoManager interface { 31 ParseInfo() ParseInfo 32 33 // Identifies and manages this template and its dependencies. 34 identity.Manager 35 } 36 37 type defaultInfo struct { 38 identity.Manager 39 parseInfo ParseInfo 40 } 41 42 func NewInfo(id identity.Manager, parseInfo ParseInfo) Info { 43 return &defaultInfo{ 44 Manager: id, 45 parseInfo: parseInfo, 46 } 47 } 48 49 func (info *defaultInfo) ParseInfo() ParseInfo { 50 return info.parseInfo 51 } 52 53 type ParseInfo struct { 54 // Set for shortcode templates with any {{ .Inner }} 55 IsInner bool 56 57 // Set for partials with a return statement. 58 HasReturn bool 59 60 // Config extracted from template. 61 Config ParseConfig 62 } 63 64 func (info ParseInfo) IsZero() bool { 65 return info.Config.Version == 0 66 } 67 68 // Info holds some info extracted from a parsed template. 69 type Info1 struct { 70 } 71 72 type ParseConfig struct { 73 Version int 74 } 75 76 var DefaultParseConfig = ParseConfig{ 77 Version: TemplateVersion, 78 } 79 80 var DefaultParseInfo = ParseInfo{ 81 Config: DefaultParseConfig, 82 }