mirror of https://github.com/mickael-menu/zk
You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
23 lines
560 B
Go
23 lines
560 B
Go
package helpers
|
|
|
|
import (
|
|
"encoding/json"
|
|
|
|
"github.com/aymerick/raymond"
|
|
"github.com/zk-org/zk/internal/util"
|
|
"github.com/zk-org/zk/internal/util/errors"
|
|
)
|
|
|
|
// RegisterJSON registers a {{json}} template helper which serializes its
|
|
// parameter to a JSON value.
|
|
func RegisterJSON(logger util.Logger) {
|
|
raymond.RegisterHelper("json", func(arg interface{}) string {
|
|
jsonBytes, err := json.Marshal(arg)
|
|
if err != nil {
|
|
logger.Err(errors.Wrapf(err, "%v: not a serializable argument for {{json}}", arg))
|
|
return ""
|
|
}
|
|
return string(jsonBytes)
|
|
})
|
|
}
|