Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/gohugoio/hugo.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/tpl
diff options
context:
space:
mode:
authorStephan Kulla <stephan.kulla@kulla>2016-08-13 01:31:50 +0300
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2016-08-13 01:31:50 +0300
commit88dcbc6efa419c97e95b7a05991d431d9c6b87a7 (patch)
treeae03bd4ecec1232f26d5921b516748f74674cdad /tpl
parent26725515c816506cdcaef7f35a934e492d9508e1 (diff)
tpl: Make absURL and relURL accept anything
Diffstat (limited to 'tpl')
-rw-r--r--tpl/template_funcs.go4
-rw-r--r--tpl/template_funcs_test.go4
2 files changed, 6 insertions, 2 deletions
diff --git a/tpl/template_funcs.go b/tpl/template_funcs.go
index 28ac1f885..efaf1a827 100644
--- a/tpl/template_funcs.go
+++ b/tpl/template_funcs.go
@@ -1803,7 +1803,7 @@ func htmlUnescape(in interface{}) (string, error) {
func init() {
funcMap = template.FuncMap{
- "absURL": func(a string) template.HTML { return template.HTML(helpers.AbsURL(a)) },
+ "absURL": func(a interface{}) template.HTML { return template.HTML(helpers.AbsURL(cast.ToString(a))) },
"add": func(a, b interface{}) (interface{}, error) { return helpers.DoArithmetic(a, b, '+') },
"after": after,
"apply": apply,
@@ -1856,7 +1856,7 @@ func init() {
"readDir": readDirFromWorkingDir,
"readFile": readFileFromWorkingDir,
"ref": ref,
- "relURL": func(a string) template.HTML { return template.HTML(helpers.RelURL(a)) },
+ "relURL": func(a interface{}) template.HTML { return template.HTML(helpers.RelURL(cast.ToString(a))) },
"relref": relRef,
"replace": replace,
"replaceRE": replaceRE,
diff --git a/tpl/template_funcs_test.go b/tpl/template_funcs_test.go
index 14046eb3d..38a94a113 100644
--- a/tpl/template_funcs_test.go
+++ b/tpl/template_funcs_test.go
@@ -82,6 +82,7 @@ func TestFuncsInTemplate(t *testing.T) {
in :=
`absURL: {{ "http://gohugo.io/" | absURL }}
absURL: {{ "mystyle.css" | absURL }}
+absURL: {{ 42 | absURL }}
add: {{add 1 2}}
base64Decode 1: {{ "SGVsbG8gd29ybGQ=" | base64Decode }}
base64Decode 2: {{ 42 | base64Encode | base64Decode }}
@@ -121,6 +122,7 @@ readDir: {{ range (readDir ".") }}{{ .Name }}{{ end }}
readFile: {{ readFile "README.txt" }}
relURL 1: {{ "http://gohugo.io/" | relURL }}
relURL 2: {{ "mystyle.css" | relURL }}
+relURL 2: {{ mul 2 21 | relURL }}
replace: {{ replace "Batman and Robin" "Robin" "Catwoman" }}
replaceRE: {{ "http://gohugo.io/docs" | replaceRE "^https?://([^/]+).*" "$1" }}
safeCSS: {{ "Bat&Man" | safeCSS | safeCSS }}
@@ -146,6 +148,7 @@ urlize: {{ "Bat Man" | urlize }}
expected := `absURL: http://gohugo.io/
absURL: http://mysite.com/hugo/mystyle.css
+absURL: http://mysite.com/hugo/42
add: 3
base64Decode 1: Hello world
base64Decode 2: 42
@@ -185,6 +188,7 @@ readDir: README.txt
readFile: Hugo Rocks!
relURL 1: http://gohugo.io/
relURL 2: /hugo/mystyle.css
+relURL 2: /hugo/42
replace: Batman and Catwoman
replaceRE: gohugo.io
safeCSS: Bat&amp;Man