diff --git a/README.md b/README.md index 244345c..20fc37a 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,11 @@ Apply [Go templates](https://golang.org/pkg/text/template/#hdr-Text_and_spaces) goproc -## Go template functions extensions +## Template syntax + +See the [Go templates](https://golang.org/pkg/text/template/#hdr-Text_and_spaces) documentation. + +## Functions extensions The following functions are added in addition to the standard functions. @@ -19,9 +23,10 @@ The following functions are added in addition to the standard functions. To ease the extraction of data, `jsonptr` allows to express data location using JSON Pointer ([RFC 6901](https://tools.ietf.org/html/rfc6901)). -Usage: +Usages: - {{ jsonptr . "pointer" }} + {{ jsonptr "pointer" . }} + {{ . | jsonptr "pointer" }} Examples: diff --git a/main.go b/main.go index df1a11b..5bf64e9 100644 --- a/main.go +++ b/main.go @@ -56,7 +56,9 @@ func _main() error { tmpl := template.New("") tmpl.Funcs(template.FuncMap{ - "jsonptr": jsonptr.Get, + "jsonptr": func(ptr string, doc interface{}) (interface{}, error) { + return jsonptr.Get(doc, ptr) + }, }) var err error diff --git a/testdata/02.gotmpl b/testdata/02.gotmpl index 5fe8d2a..a3687d9 100644 --- a/testdata/02.gotmpl +++ b/testdata/02.gotmpl @@ -1,2 +1,2 @@ -Hello, {{ jsonptr . "" }}! +Hello, {{ jsonptr "" . }}! {{/* vim: syntax=gotexttmpl: */ -}} \ No newline at end of file diff --git a/testdata/03.gotmpl b/testdata/03.gotmpl index b394de3..1b327c4 100644 --- a/testdata/03.gotmpl +++ b/testdata/03.gotmpl @@ -1,2 +1,2 @@ -Hello, {{ jsonptr . "/name" }}! +Hello, {{ . | jsonptr "/name" }}! {{/* vim: syntax=gotexttmpl: */ -}} \ No newline at end of file