mirror of
https://github.com/gohugoio/hugo.git
synced 2025-08-27 22:09:53 +02:00
Make the title case style guide configurable
This works for the `title` func and the other places where Hugo makes title case. * AP style (new default) * Chicago style * Go style (what we have today) Fixes #989
This commit is contained in:
@@ -116,6 +116,7 @@ func init() {
|
||||
[]string{"title"},
|
||||
[][2]string{
|
||||
{`{{title "Bat man"}}`, `Bat Man`},
|
||||
{`{{title "somewhere over the rainbow"}}`, `Somewhere Over the Rainbow`},
|
||||
},
|
||||
)
|
||||
|
||||
|
@@ -18,6 +18,7 @@ import (
|
||||
|
||||
"github.com/gohugoio/hugo/deps"
|
||||
"github.com/gohugoio/hugo/tpl/internal"
|
||||
"github.com/spf13/viper"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
@@ -26,7 +27,7 @@ func TestInit(t *testing.T) {
|
||||
var ns *internal.TemplateFuncsNamespace
|
||||
|
||||
for _, nsf := range internal.TemplateFuncsNamespaceRegistry {
|
||||
ns = nsf(&deps.Deps{})
|
||||
ns = nsf(&deps.Deps{Cfg: viper.New()})
|
||||
if ns.Name == name {
|
||||
found = true
|
||||
break
|
||||
|
@@ -27,14 +27,17 @@ import (
|
||||
|
||||
// New returns a new instance of the strings-namespaced template functions.
|
||||
func New(d *deps.Deps) *Namespace {
|
||||
return &Namespace{deps: d}
|
||||
titleCaseStyle := d.Cfg.GetString("titleCaseStyle")
|
||||
titleFunc := helpers.GetTitleFunc(titleCaseStyle)
|
||||
return &Namespace{deps: d, titleFunc: titleFunc}
|
||||
}
|
||||
|
||||
// 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 {
|
||||
deps *deps.Deps
|
||||
titleFunc func(s string) string
|
||||
deps *deps.Deps
|
||||
}
|
||||
|
||||
// CountRunes returns the number of runes in s, excluding whitepace.
|
||||
@@ -303,7 +306,7 @@ func (ns *Namespace) Title(s interface{}) (string, error) {
|
||||
return "", err
|
||||
}
|
||||
|
||||
return _strings.Title(ss), nil
|
||||
return ns.titleFunc(ss), nil
|
||||
}
|
||||
|
||||
// ToLower returns a copy of the input s with all Unicode letters mapped to their
|
||||
|
@@ -19,11 +19,12 @@ import (
|
||||
"testing"
|
||||
|
||||
"github.com/gohugoio/hugo/deps"
|
||||
"github.com/spf13/viper"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
var ns = New(&deps.Deps{})
|
||||
var ns = New(&deps.Deps{Cfg: viper.New()})
|
||||
|
||||
type tstNoStringer struct{}
|
||||
|
||||
|
Reference in New Issue
Block a user