mirror of
https://github.com/gohugoio/hugo.git
synced 2025-08-31 22:41:53 +02:00
@@ -21,7 +21,6 @@ import (
|
||||
|
||||
bp "github.com/spf13/hugo/bufferpool"
|
||||
"github.com/spf13/hugo/deps"
|
||||
"github.com/spf13/hugo/tpl/urls"
|
||||
)
|
||||
|
||||
// Some of the template funcs are'nt entirely stateless.
|
||||
@@ -29,9 +28,6 @@ type templateFuncster struct {
|
||||
funcMap template.FuncMap
|
||||
cachedPartials partialCache
|
||||
|
||||
// Namespaces
|
||||
urls *urls.Namespace
|
||||
|
||||
*deps.Deps
|
||||
}
|
||||
|
||||
@@ -39,9 +35,6 @@ func newTemplateFuncster(deps *deps.Deps) *templateFuncster {
|
||||
return &templateFuncster{
|
||||
Deps: deps,
|
||||
cachedPartials: partialCache{p: make(map[string]interface{})},
|
||||
|
||||
// Namespaces
|
||||
urls: urls.New(deps),
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -38,6 +38,7 @@ import (
|
||||
_ "github.com/spf13/hugo/tpl/strings"
|
||||
_ "github.com/spf13/hugo/tpl/time"
|
||||
_ "github.com/spf13/hugo/tpl/transform"
|
||||
_ "github.com/spf13/hugo/tpl/urls"
|
||||
)
|
||||
|
||||
// Get retrieves partial output from the cache based upon the partial name.
|
||||
@@ -92,20 +93,12 @@ func (t *templateFuncster) initFuncMap() {
|
||||
funcMap := template.FuncMap{
|
||||
// Namespaces
|
||||
//"time": t.time.Namespace,
|
||||
"urls": t.urls.Namespace,
|
||||
|
||||
"absURL": t.urls.AbsURL,
|
||||
"absLangURL": t.urls.AbsLangURL,
|
||||
"int": func(v interface{}) (int, error) { return cast.ToIntE(v) },
|
||||
"partial": t.partial,
|
||||
"partialCached": t.partialCached,
|
||||
"print": fmt.Sprint,
|
||||
"printf": fmt.Sprintf,
|
||||
"println": fmt.Sprintln,
|
||||
"ref": t.urls.Ref,
|
||||
"relURL": t.urls.RelURL,
|
||||
"relLangURL": t.urls.RelLangURL,
|
||||
"relref": t.urls.RelRef,
|
||||
"string": func(v interface{}) (string, error) { return cast.ToStringE(v) },
|
||||
"urlize": t.PathSpec.URLize,
|
||||
}
|
||||
|
@@ -64,6 +64,8 @@ func TestTemplateFuncsExamples(t *testing.T) {
|
||||
|
||||
v.Set("workingDir", workingDir)
|
||||
v.Set("multilingual", true)
|
||||
v.Set("baseURL", "http://mysite.com/hugo/")
|
||||
v.Set("CurrentContentLanguage", helpers.NewLanguage("en", v))
|
||||
|
||||
fs := hugofs.NewMem(v)
|
||||
|
||||
@@ -122,10 +124,7 @@ func TestFuncsInTemplate(t *testing.T) {
|
||||
// TODO(bep): docs: fix title example
|
||||
// TODO(bep) namespace remove when done
|
||||
in :=
|
||||
`absLangURL: {{ "index.html" | absLangURL }}
|
||||
absURL: {{ "http://gohugo.io/" | absURL }}
|
||||
absURL: {{ "mystyle.css" | absURL }}
|
||||
absURL: {{ 42 | absURL }}
|
||||
`
|
||||
crypto.MD5: {{ crypto.MD5 "Hello world, gophers!" }}
|
||||
dateFormat: {{ dateFormat "Monday, Jan 2, 2006" "2015-01-21" }}
|
||||
htmlEscape 1: {{ htmlEscape "Cathal Garvey & The Sunshine Band <cathal@foo.bar>" | safeHTML}}
|
||||
@@ -138,18 +137,11 @@ htmlUnescape 5: {{ htmlUnescape "Cathal Garvey & The Sunshine Band <catha
|
||||
print: {{ print "works!" }}
|
||||
printf: {{ printf "%s!" "works" }}
|
||||
println: {{ println "works!" -}}
|
||||
relLangURL: {{ "index.html" | relLangURL }}
|
||||
relURL 1: {{ "http://gohugo.io/" | relURL }}
|
||||
relURL 2: {{ "mystyle.css" | relURL }}
|
||||
relURL 3: {{ mul 2 21 | relURL }}
|
||||
strings.TrimPrefix: {{ strings.TrimPrefix "Goodbye,, world!" "Goodbye," }}
|
||||
urlize: {{ "Bat Man" | urlize }}
|
||||
`
|
||||
|
||||
expected := `absLangURL: http://mysite.com/hugo/en/index.html
|
||||
absURL: http://gohugo.io/
|
||||
absURL: http://mysite.com/hugo/mystyle.css
|
||||
absURL: http://mysite.com/hugo/42
|
||||
expected := `
|
||||
crypto.MD5: b3029f756f98f79e7f1b7f1d1f0dd53b
|
||||
dateFormat: Wednesday, Jan 21, 2015
|
||||
htmlEscape 1: Cathal Garvey & The Sunshine Band <cathal@foo.bar>
|
||||
@@ -162,10 +154,6 @@ htmlUnescape 5: Cathal Garvey & The Sunshine Band <cathal@foo.bar>
|
||||
print: works!
|
||||
printf: works!
|
||||
println: works!
|
||||
relLangURL: /hugo/en/index.html
|
||||
relURL 1: http://gohugo.io/
|
||||
relURL 2: /hugo/mystyle.css
|
||||
relURL 3: /hugo/42
|
||||
strings.TrimPrefix: , world!
|
||||
urlize: bat-man
|
||||
`
|
||||
|
Reference in New Issue
Block a user