hugo

Fork of github.com/gohugoio/hugo with reverse pagination support

git clone git://git.shimmy1996.com/hugo.git

template_info.go (1790B)

    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 FileInfo interface {
   31 	Name() string
   32 	Filename() string
   33 }
   34 
   35 type InfoManager interface {
   36 	ParseInfo() ParseInfo
   37 
   38 	// Identifies and manages this template and its dependencies.
   39 	identity.Manager
   40 }
   41 
   42 type defaultInfo struct {
   43 	identity.Manager
   44 	parseInfo ParseInfo
   45 }
   46 
   47 func NewInfo(id identity.Manager, parseInfo ParseInfo) Info {
   48 	return &defaultInfo{
   49 		Manager:   id,
   50 		parseInfo: parseInfo,
   51 	}
   52 }
   53 
   54 func (info *defaultInfo) ParseInfo() ParseInfo {
   55 	return info.parseInfo
   56 }
   57 
   58 type ParseInfo struct {
   59 	// Set for shortcode templates with any {{ .Inner }}
   60 	IsInner bool
   61 
   62 	// Set for partials with a return statement.
   63 	HasReturn bool
   64 
   65 	// Config extracted from template.
   66 	Config ParseConfig
   67 }
   68 
   69 func (info ParseInfo) IsZero() bool {
   70 	return info.Config.Version == 0
   71 }
   72 
   73 type ParseConfig struct {
   74 	Version int
   75 }
   76 
   77 var DefaultParseConfig = ParseConfig{
   78 	Version: TemplateVersion,
   79 }
   80 
   81 var DefaultParseInfo = ParseInfo{
   82 	Config: DefaultParseConfig,
   83 }