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 14package tpl 15 16import ( 17 "github.com/gohugoio/hugo/identity" 18) 19 20// Increments on breaking changes. 21const TemplateVersion = 2 22 23type Info interface { 24 ParseInfo() ParseInfo 25 26 // Identifies this template and its dependencies. 27 identity.Provider 28} 29 30type InfoManager interface { 31 ParseInfo() ParseInfo 32 33 // Identifies and manages this template and its dependencies. 34 identity.Manager 35} 36 37type defaultInfo struct { 38 identity.Manager 39 parseInfo ParseInfo 40} 41 42func NewInfo(id identity.Manager, parseInfo ParseInfo) Info { 43 return &defaultInfo{ 44 Manager: id, 45 parseInfo: parseInfo, 46 } 47} 48 49func (info *defaultInfo) ParseInfo() ParseInfo { 50 return info.parseInfo 51} 52 53type 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 64func (info ParseInfo) IsZero() bool { 65 return info.Config.Version == 0 66} 67 68// Info holds some info extracted from a parsed template. 69type Info1 struct { 70} 71 72type ParseConfig struct { 73 Version int 74} 75 76var DefaultParseConfig = ParseConfig{ 77 Version: TemplateVersion, 78} 79 80var DefaultParseInfo = ParseInfo{ 81 Config: DefaultParseConfig, 82} 83