Skip to content

Commit

Permalink
Reverse order of "jsonptr" function arguments
Browse files Browse the repository at this point in the history
... for better integration with template pipelines.
  • Loading branch information
dolmen committed Dec 6, 2018
1 parent 85f0175 commit 9446341
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 6 deletions.
11 changes: 8 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,11 @@ Apply [Go templates](https://golang.org/pkg/text/template/#hdr-Text_and_spaces)

goproc <Go-template-file> <JSON-or-YAML-file>

## 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.

Expand All @@ -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:

Expand Down
4 changes: 3 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion testdata/02.gotmpl
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
Hello, {{ jsonptr . "" }}!
Hello, {{ jsonptr "" . }}!
{{/* vim: syntax=gotexttmpl: */ -}}
2 changes: 1 addition & 1 deletion testdata/03.gotmpl
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
Hello, {{ jsonptr . "/name" }}!
Hello, {{ . | jsonptr "/name" }}!
{{/* vim: syntax=gotexttmpl: */ -}}

0 comments on commit 9446341

Please sign in to comment.