docshelper.go (1742B)
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 cast 15 16 import ( 17 "github.com/gohugoio/hugo/common/loggers" 18 "github.com/gohugoio/hugo/config" 19 "github.com/gohugoio/hugo/deps" 20 "github.com/gohugoio/hugo/docshelper" 21 "github.com/gohugoio/hugo/langs" 22 "github.com/gohugoio/hugo/resources/page" 23 "github.com/gohugoio/hugo/tpl/internal" 24 ) 25 26 // This file provides documentation support and is randomly put into this package. 27 func init() { 28 docsProvider := func() docshelper.DocProvider { 29 cfg := config.New() 30 d := &deps.Deps{ 31 Cfg: cfg, 32 Log: loggers.NewErrorLogger(), 33 BuildStartListeners: &deps.Listeners{}, 34 Language: langs.NewDefaultLanguage(cfg), 35 Site: page.NewDummyHugoSite(newTestConfig()), 36 } 37 38 var namespaces internal.TemplateFuncsNamespaces 39 40 for _, nsf := range internal.TemplateFuncsNamespaceRegistry { 41 nf := nsf(d) 42 namespaces = append(namespaces, nf) 43 44 } 45 46 return docshelper.DocProvider{"tpl": map[string]any{"funcs": namespaces}} 47 } 48 49 docshelper.AddDocProviderFunc(docsProvider) 50 } 51 52 func newTestConfig() config.Provider { 53 v := config.New() 54 v.Set("contentDir", "content") 55 return v 56 }