github.com/fighterlyt/hugo@v0.47.1/tpl/fmt/fmt.go (about) 1 // Copyright 2017 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 fmt 15 16 import ( 17 _fmt "fmt" 18 "github.com/gohugoio/hugo/helpers" 19 ) 20 21 // New returns a new instance of the fmt-namespaced template functions. 22 func New() *Namespace { 23 return &Namespace{helpers.NewDistinctErrorLogger()} 24 } 25 26 // Namespace provides template functions for the "fmt" namespace. 27 type Namespace struct { 28 errorLogger *helpers.DistinctLogger 29 } 30 31 // Print returns string representation of the passed arguments. 32 func (ns *Namespace) Print(a ...interface{}) string { 33 return _fmt.Sprint(a...) 34 } 35 36 // Printf returns a formatted string representation of the passed arguments. 37 func (ns *Namespace) Printf(format string, a ...interface{}) string { 38 return _fmt.Sprintf(format, a...) 39 40 } 41 42 // Println returns string representation of the passed arguments ending with a newline. 43 func (ns *Namespace) Println(a ...interface{}) string { 44 return _fmt.Sprintln(a...) 45 } 46 47 func (ns *Namespace) Errorf(format string, a ...interface{}) string { 48 ns.errorLogger.Printf(format, a...) 49 return _fmt.Sprintf(format, a...) 50 }