"html"
"html/template"
"math/rand"
+ "net/url"
"os"
"reflect"
"regexp"
return hex.EncodeToString(hash[:]), nil
}
+// querify converts the given parameters into a url.Values object
+func querify(params ...interface{}) (url.Values, error) {
+ qs := url.Values{}
+ vals, err := dictionary(params...)
+ if err != nil {
+ return url.Values{}, fmt.Errorf("querify keys must be strings")
+ }
+
+ for name, value := range vals {
+ qs.Add(name, url.QueryEscape(fmt.Sprintf("%v", value)))
+ }
+
+ return qs, nil
+}
+
func init() {
funcMap = template.FuncMap{
"absURL": func(a string) template.HTML { return template.HTML(helpers.AbsURL(a)) },
"partial": partial,
"plainify": plainify,
"pluralize": pluralize,
+ "querify": querify,
"readDir": readDirFromWorkingDir,
"readFile": readFileFromWorkingDir,
"ref": ref,
mul: {{mul 2 3}}
plainify: {{ plainify "Hello <strong>world</strong>, gophers!" }}
pluralize: {{ "cat" | pluralize }}
+querify: {{ (querify "foo" 1 "bar" 2 "baz" "with spaces").Encode | safeHTML }}
readDir: {{ range (readDir ".") }}{{ .Name }}{{ end }}
readFile: {{ readFile "README.txt" }}
relURL 1: {{ "http://gohugo.io/" | relURL }}
mul: 6
plainify: Hello world, gophers!
pluralize: cats
+querify: bar=2&baz=with%2Bspaces&foo=1
readDir: README.txt
readFile: Hugo Rocks!
relURL 1: http://gohugo.io/