import (
"bytes"
"encoding/base64"
+ "encoding/json"
"errors"
"fmt"
"html"
return template.HTML(m)
}
+// jsonify encodes a given object to JSON.
+func jsonify(v interface{}) (template.HTML, error) {
+ b, err := json.Marshal(v)
+ if err != nil {
+ return "", err
+ }
+ return template.HTML(b), nil
+}
+
func refPage(page interface{}, ref, methodName string) template.HTML {
value := reflect.ValueOf(page)
"intersect": intersect,
"isSet": isSet,
"isset": isSet,
+ "jsonify": jsonify,
"last": last,
"le": le,
"lower": func(a string) string { return strings.ToLower(a) },
seq: {{ seq 3 }}
sort: {{ slice "B" "C" "A" | sort }}
delimit: {{ delimit (slice "A" "B" "C") ", " " and " }}
+jsonify: {{ (slice "A" "B" "C") | jsonify }}
`
expected := `chomp: <p>Blockhead</p>
dateFormat: Wednesday, Jan 21, 2015
seq: [1 2 3]
sort: [A B C]
delimit: A, B and C
+jsonify: ["A","B","C"]
`
var b bytes.Buffer