summaryrefslogtreecommitdiffstats
path: root/tpl/strings
diff options
context:
space:
mode:
authorBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2023-01-04 18:24:36 +0100
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2023-05-16 18:01:29 +0200
commit241b21b0fd34d91fccb2ce69874110dceae6f926 (patch)
treed4e0118eac7e9c42f065815447a70805f8d6ad3e /tpl/strings
parent6aededf6b42011c3039f5f66487a89a8dd65e0e7 (diff)
Create a struct with all of Hugo's config options
Primary motivation is documentation, but it will also hopefully simplify the code. Also, * Lower case the default output format names; this is in line with the custom ones (map keys) and how it's treated all the places. This avoids doing `stringds.EqualFold` everywhere. Closes #10896 Closes #10620
Diffstat (limited to 'tpl/strings')
-rw-r--r--tpl/strings/strings.go11
-rw-r--r--tpl/strings/strings_test.go6
2 files changed, 8 insertions, 9 deletions
diff --git a/tpl/strings/strings.go b/tpl/strings/strings.go
index 6c6e9b9d3..9f16f1581 100644
--- a/tpl/strings/strings.go
+++ b/tpl/strings/strings.go
@@ -33,17 +33,14 @@ import (
// New returns a new instance of the strings-namespaced template functions.
func New(d *deps.Deps) *Namespace {
- titleCaseStyle := d.Cfg.GetString("titleCaseStyle")
- titleFunc := helpers.GetTitleFunc(titleCaseStyle)
- return &Namespace{deps: d, titleFunc: titleFunc}
+ return &Namespace{deps: d}
}
// Namespace provides template functions for the "strings" namespace.
// Most functions mimic the Go stdlib, but the order of the parameters may be
// different to ease their use in the Go template system.
type Namespace struct {
- titleFunc func(s string) string
- deps *deps.Deps
+ deps *deps.Deps
}
// CountRunes returns the number of runes in s, excluding whitespace.
@@ -163,6 +160,7 @@ func (ns *Namespace) ContainsAny(s, chars any) (bool, error) {
// ContainsNonSpace reports whether s contains any non-space characters as defined
// by Unicode's White Space property,
+// <docsmeta>{"newIn": "0.111.0" }</docsmeta>
func (ns *Namespace) ContainsNonSpace(s any) bool {
ss := cast.ToString(s)
@@ -383,8 +381,7 @@ func (ns *Namespace) Title(s any) (string, error) {
if err != nil {
return "", err
}
-
- return ns.titleFunc(ss), nil
+ return ns.deps.Conf.CreateTitle(ss), nil
}
// FirstUpper converts s making the first character upper case.
diff --git a/tpl/strings/strings_test.go b/tpl/strings/strings_test.go
index a230d4a48..43334a8e8 100644
--- a/tpl/strings/strings_test.go
+++ b/tpl/strings/strings_test.go
@@ -17,14 +17,16 @@ import (
"html/template"
"testing"
- "github.com/gohugoio/hugo/config"
+ "github.com/gohugoio/hugo/config/testconfig"
"github.com/gohugoio/hugo/deps"
qt "github.com/frankban/quicktest"
"github.com/spf13/cast"
)
-var ns = New(&deps.Deps{Cfg: config.New()})
+var ns = New(&deps.Deps{
+ Conf: testconfig.GetTestConfig(nil, nil),
+})
type tstNoStringer struct{}