github.com/gohugoio/hugo@v0.88.1/config/configProvider.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 config
    15  
    16  import (
    17  	"github.com/gohugoio/hugo/common/maps"
    18  	"github.com/gohugoio/hugo/common/types"
    19  )
    20  
    21  // Provider provides the configuration settings for Hugo.
    22  type Provider interface {
    23  	GetString(key string) string
    24  	GetInt(key string) int
    25  	GetBool(key string) bool
    26  	GetParams(key string) maps.Params
    27  	GetStringMap(key string) map[string]interface{}
    28  	GetStringMapString(key string) map[string]string
    29  	GetStringSlice(key string) []string
    30  	Get(key string) interface{}
    31  	Set(key string, value interface{})
    32  	Merge(key string, value interface{})
    33  	SetDefaults(params maps.Params)
    34  	SetDefaultMergeStrategy()
    35  	WalkParams(walkFn func(params ...KeyParams) bool)
    36  	IsSet(key string) bool
    37  }
    38  
    39  // GetStringSlicePreserveString returns a string slice from the given config and key.
    40  // It differs from the GetStringSlice method in that if the config value is a string,
    41  // we do not attempt to split it into fields.
    42  func GetStringSlicePreserveString(cfg Provider, key string) []string {
    43  	sd := cfg.Get(key)
    44  	return types.ToStringSlicePreserveString(sd)
    45  }
    46  
    47  // SetBaseTestDefaults provides some common config defaults used in tests.
    48  func SetBaseTestDefaults(cfg Provider) {
    49  	cfg.Set("resourceDir", "resources")
    50  	cfg.Set("contentDir", "content")
    51  	cfg.Set("dataDir", "data")
    52  	cfg.Set("i18nDir", "i18n")
    53  	cfg.Set("layoutDir", "layouts")
    54  	cfg.Set("assetDir", "assets")
    55  	cfg.Set("archetypeDir", "archetypes")
    56  	cfg.Set("publishDir", "public")
    57  }