summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2017-05-02 11:03:08 +0200
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2017-05-04 10:46:19 +0200
commitcff2f3133442a538f8e125717c5805d58484de88 (patch)
treed1b741ba7133ca879c46f1b69e76de26d4f6b230
parentf9e41f6497cac0c47e1446118690e698bb243719 (diff)
tpl: Add some GoDoc info to template func docs
Closes #3418
-rw-r--r--docs/data/docs.json2410
-rw-r--r--tpl/cast/cast.go2
-rw-r--r--tpl/cast/docshelper.go2
-rw-r--r--tpl/internal/templatefuncsRegistry.go178
4 files changed, 1459 insertions, 1133 deletions
diff --git a/docs/data/docs.json b/docs/data/docs.json
index 8c49b18bc..ece243255 100644
--- a/docs/data/docs.json
+++ b/docs/data/docs.json
@@ -260,1196 +260,1372 @@
]
},
"tpl": {
- "funcs": [
- {
- "Name": "cast",
- "Funcs": [
- {
- "Name": "ToInt",
- "Description": "",
- "Aliases": [
+ "funcs": {
+ "cast": {
+ "ToInt": {
+ "Description": "ToInt converts the given value to an int.",
+ "Args": [
+ "v"
+ ],
+ "Aliases": [
+ "int"
+ ],
+ "Examples": [
+ [
+ "{{ \"1234\" | int | printf \"%T\" }}",
"int"
- ],
- "Examples": [
- [
- "{{ \"1234\" | int | printf \"%T\" }}",
- "int"
- ]
]
- },
- {
- "Name": "ToString",
- "Description": "",
- "Aliases": [
+ ]
+ },
+ "ToString": {
+ "Description": "ToString converts the given value to a string.",
+ "Args": [
+ "v"
+ ],
+ "Aliases": [
+ "string"
+ ],
+ "Examples": [
+ [
+ "{{ 1234 | string | printf \"%T\" }}",
"string"
- ],
- "Examples": [
- [
- "{{ 1234 | string | printf \"%T\" }}",
- "string"
- ]
]
- }
- ]
+ ]
+ }
},
- {
- "Name": "compare",
- "Funcs": [
- {
- "Name": "Default",
- "Description": "",
- "Aliases": [
- "default"
- ],
- "Examples": [
- [
- "{{ \"Hugo Rocks!\" | default \"Hugo Rules!\" }}",
- "Hugo Rocks!"
- ],
- [
- "{{ \"\" | default \"Hugo Rules!\" }}",
- "Hugo Rules!"
- ]
+ "compare": {
+ "Default": {
+ "Description": "Default checks whether a given value is set and returns a default value if it\nis not. \"Set\" in this context means non-zero for numeric types and times;\nnon-zero length for strings, arrays, slices, and maps;\nany boolean or struct value; or non-nil for any other types.",
+ "Args": [
+ "dflt",
+ "given"
+ ],
+ "Aliases": [
+ "default"
+ ],
+ "Examples": [
+ [
+ "{{ \"Hugo Rocks!\" | default \"Hugo Rules!\" }}",
+ "Hugo Rocks!"
+ ],
+ [
+ "{{ \"\" | default \"Hugo Rules!\" }}",
+ "Hugo Rules!"
]
- },
- {
- "Name": "Eq",
- "Description": "",
- "Aliases": [
- "eq"
- ],
- "Examples": [
- [
- "{{ if eq .Section \"blog\" }}current{{ end }}",
- "current"
- ]
+ ]
+ },
+ "Eq": {
+ "Description": "Eq returns the boolean truth of arg1 == arg2.",
+ "Args": [
+ "x",
+ "y"
+ ],
+ "Aliases": [
+ "eq"
+ ],
+ "Examples": [
+ [
+ "{{ if eq .Section \"blog\" }}current{{ end }}",
+ "current"
]
- },
- {
- "Name": "Ge",
- "Description": "",
- "Aliases": [
- "ge"
- ],
- "Examples": []
- },
- {
- "Name": "Gt",
- "Description": "",
- "Aliases": [
- "gt"
- ],
- "Examples": []
- },
- {
- "Name": "Le",
- "Description": "",
- "Aliases": [
- "le"
- ],
- "Examples": []
- },
- {
- "Name": "Lt",
- "Description": "",
- "Aliases": [
- "lt"
- ],
- "Examples": []
- },
- {
- "Name": "Ne",
- "Description": "",
- "Aliases": [
- "ne"
- ],
- "Examples": []
- }
- ]
+ ]
+ },
+ "Ge": {
+ "Description": "Ge returns the boolean truth of arg1 \u003e= arg2.",
+ "Args": [
+ "a",
+ "b"
+ ],
+ "Aliases": [
+ "ge"
+ ],
+ "Examples": []
+ },
+ "Gt": {
+ "Description": "Gt returns the boolean truth of arg1 \u003e arg2.",
+ "Args": [
+ "a",
+ "b"
+ ],
+ "Aliases": [
+ "gt"
+ ],
+ "Examples": []
+ },
+ "Le": {
+ "Description": "Le returns the boolean truth of arg1 \u003c= arg2.",
+ "Args": [
+ "a",
+ "b"
+ ],
+ "Aliases": [
+ "le"
+ ],
+ "Examples": []
+ },
+ "Lt": {
+ "Description": "Lt returns the boolean truth of arg1 \u003c arg2.",
+ "Args": [
+ "a",
+ "b"
+ ],
+ "Aliases": [
+ "lt"
+ ],
+ "Examples": []
+ },
+ "Ne": {
+ "Description": "Ne returns the boolean truth of arg1 != arg2.",
+ "Args": [
+ "x",
+ "y"
+ ],
+ "Aliases": [
+ "ne"
+ ],
+ "Examples": []
+ }
},
- {
- "Name": "collections",
- "Funcs": [
- {
- "Name": "After",
- "Description": "",
- "Aliases": [
- "after"
- ],
- "Examples": []
- },
- {
- "Name": "Apply",
- "Description": "",
- "Aliases": [
- "apply"
- ],
- "Examples": []
- },
- {
- "Name": "Delimit",
- "Description": "",
- "Aliases": [
- "delimit"
- ],
- "Examples": [
- [
- "{{ delimit (slice \"A\" \"B\" \"C\") \", \" \" and \" }}",
- "A, B and C"
- ]
+ "collections": {
+ "After": {
+ "Description": "After returns all the items after the first N in a rangeable list.",
+ "Args": [
+ "index",
+ "seq"
+ ],
+ "Aliases": [
+ "after"
+ ],
+ "Examples": []
+ },
+ "Apply": {
+ "Description": "Apply takes a map, array, or slice and returns a new slice with the function fname applied over it.",
+ "Args": [
+ "seq",
+ "fname",
+ "args"
+ ],
+ "Aliases": [
+ "apply"
+ ],
+ "Examples": []
+ },
+ "Delimit": {
+ "Description": "Delimit takes a given sequence and returns a delimited HTML string.\nIf last is passed to the function, it will be used as the final delimiter.",
+ "Args": [
+ "seq",
+ "delimiter",
+ "last"
+ ],
+ "Aliases": [
+ "delimit"
+ ],
+ "Examples": [
+ [
+ "{{ delimit (slice \"A\" \"B\" \"C\") \", \" \" and \" }}",
+ "A, B and C"
]
- },
- {
- "Name": "Dictionary",
- "Description": "",
- "Aliases": [
- "dict"
- ],
- "Examples": []
- },
- {
- "Name": "EchoParam",
- "Description": "",
- "Aliases": [
- "echoParam"
- ],
- "Examples": [
- [
- "{{ echoParam .Params \"langCode\" }}",
- "en"
- ]
+ ]
+ },
+ "Dictionary": {
+ "Description": "Dictionary creates a map[string]interface{} from the given parameters by\nwalking the parameters and treating them as key-value pairs. The number\nof parameters must be even.",
+ "Args": [
+ "values"
+ ],
+ "Aliases": [
+ "dict"
+ ],
+ "Examples": []
+ },
+ "EchoParam": {
+ "Description": "EchoParam returns a given value if it is set; otherwise, it returns an\nempty string.",
+ "Args": [
+ "a",
+ "key"
+ ],
+ "Aliases": [
+ "echoParam"
+ ],
+ "Examples": [
+ [
+ "{{ echoParam .Params \"langCode\" }}",
+ "en"
]
- },
- {
- "Name": "First",
- "Description": "",
- "Aliases": [
- "first"
- ],
- "Examples": []
- },
- {
- "Name": "In",
- "Description": "",
- "Aliases": [
- "in"
- ],
- "Examples": [
- [
- "{{ if in \"this string contains a substring\" \"substring\" }}Substring found!{{ end }}",
- "Substring found!"
- ]
+ ]
+ },
+ "First": {
+ "Description": "First returns the first N items in a rangeable list.",
+ "Args": [
+ "limit",
+ "seq"
+ ],
+ "Aliases": [
+ "first"
+ ],
+ "Examples": []
+ },
+ "In": {
+ "Description": "In returns whether v is in the set l. l may be an array or slice.",
+ "Args": [
+ "l",
+ "v"
+ ],
+ "Aliases": [
+ "in"
+ ],
+ "Examples": [
+ [
+ "{{ if in \"this string contains a substring\" \"substring\" }}Substring found!{{ end }}",
+ "Substring found!"
]
- },
- {
- "Name": "Index",
- "Description": "",
- "Aliases": [
- "index"
- ],
- "Examples": []
- },
- {
- "Name": "Intersect",
- "Description": "",
- "Aliases": [
- "intersect"
- ],
- "Examples": []
- },
- {
- "Name": "IsSet",
- "Description": "",
- "Aliases": [
- "isSet",
- "isset"
- ],
- "Examples": []
- },
- {
- "Name": "Last",
- "Description": "",
- "Aliases": [
- "last"
- ],
- "Examples": []
- },
- {
- "Name": "Querify",
- "Description": "",
- "Aliases": [
- "querify"
- ],
- "Examples": [
- [
- "{{ (querify \"foo\" 1 \"bar\" 2 \"baz\" \"with spaces\" \"qux\" \"this\u0026that=those\") | safeHTML }}",
- "bar=2\u0026baz=with+spaces\u0026foo=1\u0026qux=this%26that%3Dthose"
- ],
- [
- "\u003ca href=\"https://www.google.com?{{ (querify \"q\" \"test\" \"page\" 3) | safeURL }}\"\u003eSearch\u003c/a\u003e",
- "\u003ca href=\"https://www.google.com?page=3\u0026amp;q=test\"\u003eSearch\u003c/a\u003e"
- ]
+ ]
+ },
+ "Index": {
+ "Description": "Index returns the result of indexing its first argument by the following\narguments. Thus \"index x 1 2 3\" is, in Go syntax, x[1][2][3]. Each\nindexed item must be a map, slice, or array.\n\nCopied from Go stdlib src/text/template/funcs.go.\n\nWe deviate from the stdlib due to https://github.com/golang/go/issues/14751.\n\nTODO(moorereason): merge upstream changes.",
+ "Args": [
+ "item",
+ "indices"
+ ],
+ "Aliases": [
+ "index"
+ ],
+ "Examples": []
+ },
+ "Intersect": {
+ "Description": "Intersect returns the common elements in the given sets, l1 and l2. l1 and\nl2 must be of the same type and may be either arrays or slices.",
+ "Args": [
+ "l1",
+ "l2"
+ ],
+ "Aliases": [
+ "intersect"
+ ],
+ "Examples": []
+ },
+ "IsSet": {
+ "Description": "IsSet returns whether a given array, channel, slice, or map has a key\ndefined.",
+ "Args": [
+ "a",
+ "key"
+ ],
+ "Aliases": [
+ "isSet",
+ "isset"
+ ],
+ "Examples": []
+ },
+ "Last": {
+ "Description": "Last returns the last N items in a rangeable list.",
+ "Args": [
+ "limit",
+ "seq"
+ ],
+ "Aliases": [
+ "last"
+ ],
+ "Examples": []
+ },
+ "Querify": {
+ "Description": "Querify encodes the given parameters in URL-encoded form (\"bar=baz\u0026foo=quux\") sorted by key.",
+ "Args": [
+ "params"
+ ],
+ "Aliases": [
+ "querify"
+ ],
+ "Examples": [
+ [
+ "{{ (querify \"foo\" 1 \"bar\" 2 \"baz\" \"with spaces\" \"qux\" \"this\u0026that=those\") | safeHTML }}",
+ "bar=2\u0026baz=with+spaces\u0026foo=1\u0026qux=this%26that%3Dthose"
+ ],
+ [
+ "\u003ca href=\"https://www.google.com?{{ (querify \"q\" \"test\" \"page\" 3) | safeURL }}\"\u003eSearch\u003c/a\u003e",
+ "\u003ca href=\"https://www.google.com?page=3\u0026amp;q=test\"\u003eSearch\u003c/a\u003e"
]
- },
- {
- "Name": "Seq",
- "Description": "",
- "Aliases": [
- "seq"
- ],
- "Examples": [
- [
- "{{ seq 3 }}",
- "[1 2 3]"
- ]
+ ]
+ },
+ "Seq": {
+ "Description": "Seq creates a sequence of integers. It's named and used as GNU's seq.\n\nExamples:\n 3 =\u003e 1, 2, 3\n 1 2 4 =\u003e 1, 3\n -3 =\u003e -1, -2, -3\n 1 4 =\u003e 1, 2, 3, 4\n 1 -2 =\u003e 1, 0, -1, -2",
+ "Args": [
+ "args"
+ ],
+ "Aliases": [
+ "seq"
+ ],
+ "Examples": [
+ [
+ "{{ seq 3 }}",
+ "[1 2 3]"
]
- },
- {
- "Name": "Shuffle",
- "Description": "",
- "Aliases": [
- "shuffle"
- ],
- "Examples": []
- },
- {
- "Name": "Slice",
- "Description": "",
- "Aliases": [
- "slice"
- ],
- "Examples": [
- [
- "{{ slice \"B\" \"C\" \"A\" | sort }}",
- "[A B C]"
- ]
+ ]
+ },
+ "Shuffle": {
+ "Description": "Shuffle returns the given rangeable list in a randomised order.",
+ "Args": [
+ "seq"
+ ],
+ "Aliases": [
+ "shuffle"
+ ],
+ "Examples": []
+ },
+ "Slice": {
+ "Description": "Slice returns a slice of all passed arguments.",
+ "Args": [
+ "args"
+ ],
+ "Aliases": [
+ "slice"
+ ],
+ "Examples": [
+ [
+ "{{ slice \"B\" \"C\" \"A\" | sort }}",
+ "[A B C]"
]
- },
- {
- "Name": "Sort",
- "Description": "",
- "Aliases": [
- "sort"
- ],
- "Examples": []
- },
- {
- "Name": "Union",
- "Description": "",
- "Aliases": [
- "union"
- ],
- "Examples": [
- [
- "{{ union (slice 1 2 3) (slice 3 4 5) }}",
- "[1 2 3 4 5]"
- ]
+ ]
+ },
+ "Sort": {
+ "Description": "Sort returns a sorted sequence.",
+ "Args": [
+ "seq",
+ "args"
+ ],
+ "Aliases": [
+ "sort"
+ ],
+ "Examples": []
+ },
+ "Union": {
+ "Description": "Union returns the union of the given sets, l1 and l2. l1 and\nl2 must be of the same type and may be either arrays or slices.\nIf l1 and l2 aren't of the same type then l1 will be returned.\nIf either l1 or l2 is nil then the non-nil list will be returned.",
+ "Args": [
+ "l1",
+ "l2"
+ ],
+ "Aliases": [
+ "union"
+ ],
+ "Examples": [
+ [
+ "{{ union (slice 1 2 3) (slice 3 4 5) }}",
+ "[1 2 3 4 5]"
]
- },
- {
- "Name": "Where",
- "Description": "",
- "Aliases": [
- "where"
- ],
- "Examples": []
- }
- ]
+ ]
+ },
+ "Where": {
+ "Description": "Where returns a filtered subset of a given data type.",
+ "Args": [
+ "seq",
+ "key",
+ "args"
+ ],
+ "Aliases": [
+ "where"
+ ],
+ "Examples": []
+ }
},
- {
- "Name": "crypto",
- "Funcs": [
- {
- "Name": "MD5",
- "Description": "",
- "Aliases": [
- "md5"
- ],
- "Examples": [
- [
- "{{ md5 \"Hello world, gophers!\" }}",
- "b3029f756f98f79e7f1b7f1d1f0dd53b"
- ],
- [
- "{{ crypto.MD5 \"Hello world, gophers!\" }}",
- "b3029f756f98f79e7f1b7f1d1f0dd53b"
- ]
+ "crypto": {
+ "MD5": {
+ "Description": "MD5 hashes the given input and returns its MD5 checksum.",
+ "Args": [
+ "in"
+ ],
+ "Aliases": [
+ "md5"
+ ],
+ "Examples": [
+ [
+ "{{ md5 \"Hello world, gophers!\" }}",
+ "b3029f756f98f79e7f1b7f1d1f0dd53b"
+ ],
+ [
+ "{{ crypto.MD5 \"Hello world, gophers!\" }}",
+ "b3029f756f98f79e7f1b7f1d1f0dd53b"
]
- },
- {
- "Name": "SHA1",
- "Description": "",
- "Aliases": [
- "sha1"
- ],
- "Examples": [
- [
- "{{ sha1 \"Hello world, gophers!\" }}",
- "c8b5b0e33d408246e30f53e32b8f7627a7a649d4"
- ]
+ ]
+ },
+ "SHA1": {
+ "Description": "SHA1 hashes the given input and returns its SHA1 checksum.",
+ "Args": [
+ "in"
+ ],
+ "Aliases": [
+ "sha1"
+ ],
+ "Examples": [
+ [
+ "{{ sha1 \"Hello world, gophers!\" }}",
+ "c8b5b0e33d408246e30f53e32b8f7627a7a649d4"
]
- },
- {
- "Name": "SHA256",
- "Description": "",
- "Aliases": [
- "sha256"
- ],
- "Examples": [
- [
- "{{ sha256 \"Hello world, gophers!\" }}",
- "6ec43b78da9669f50e4e422575c54bf87536954ccd58280219c393f2ce352b46"
- ]
+ ]
+ },
+ "SHA256": {
+ "Description": "SHA256 hashes the given input and returns its SHA256 checksum.",
+ "Args": [
+ "in"
+ ],
+ "Aliases": [
+ "sha256"
+ ],
+ "Examples": [
+ [
+ "{{ sha256 \"Hello world, gophers!\" }}",
+ "6ec43b78da9669f50e4e422575c54bf87536954ccd58280219c393f2ce352b46"
]
- }
- ]
+ ]
+ }
},
- {
- "Name": "data",
- "Funcs": [
- {
- "Name": "GetCSV",
- "Description": "",
- "Aliases": [
- "getCSV"
- ],
- "Examples": []
- },
- {
- "Name": "GetJSON",
- "Description": "",
- "Aliases": [
- "getJSON"
- ],
- "Examples": []
- }
- ]
+ "data": {
+ "GetCSV": {
+ "Description": "GetCSV expects a data separator and one or n-parts of a URL to a resource which\ncan either be a local or a remote one.\nThe data separator can be a comma, semi-colon, pipe, etc, but only one character.\nIf you provide multiple parts for the URL they will be joined together to the final URL.\nGetCSV returns nil or a slice slice to use in a short code.",
+ "Args": [
+ "sep",
+ "urlParts"
+ ],
+ "Aliases": [
+ "getCSV"
+ ],
+ "Examples": []
+ },
+ "GetJSON": {
+ "Description": "GetJSON expects one or n-parts of a URL to a resource which can either be a local or a remote one.\nIf you provide multiple parts they will be joined together to the final URL.\nGetJSON returns nil or parsed JSON to use in a short code.",
+ "Args": [
+ "urlParts"
+ ],
+ "Aliases": [
+ "getJSON"
+ ],
+ "Examples": []
+ }
},
- {
- "Name": "encoding",
- "Funcs": [
- {
- "Name": "Base64Decode",
- "Description": "",
- "Aliases": [
- "base64Decode"
- ],
- "Examples": [
- [
- "{{ \"SGVsbG8gd29ybGQ=\" | base64Decode }}",
- "Hello world"
- ],
- [
- "{{ 42 | base64Encode | base64Decode }}",
- "42"
- ]
+ "encoding": {
+ "Base64Decode": {
+ "Description": "Base64Decode returns the base64 decoding of the given content.",
+ "Args": [
+ "content"
+ ],
+ "Aliases": [
+ "base64Decode"
+ ],
+ "Examples": [
+ [
+ "{{ \"SGVsbG8gd29ybGQ=\" | base64Decode }}",
+ "Hello world"
+ ],
+ [
+ "{{ 42 | base64Encode | base64Decode }}",
+ "42"
]
- },
- {
- "Name": "Base64Encode",
- "Description": "",
- "Aliases": [
- "base64Encode"
- ],
- "Examples": [
- [
- "{{ \"Hello world\" | base64Encode }}",
- "SGVsbG8gd29ybGQ="
- ]
+ ]
+ },
+ "Base64Encode": {
+ "Description": "Base64Encode returns the base64 encoding of the given content.",
+ "Args": [
+ "content"
+ ],
+ "Aliases": [
+ "base64Encode"
+ ],
+ "Examples": [
+ [
+ "{{ \"Hello world\" | base64Encode }}",
+ "SGVsbG8gd29ybGQ="
]
- },
- {
- "Name": "Jsonify",
- "Description": "",
- "Aliases": [
- "jsonify"
- ],
- "Examples": [
- [
- "{{ (slice \"A\" \"B\" \"C\") | jsonify }}",
- "[\"A\",\"B\",\"C\"]"
- ]
+ ]
+ },
+ "Jsonify": {
+ "Description": "Jsonify encodes a given object to JSON.",
+ "Args": [
+ "v"
+ ],
+ "Aliases": [
+ "jsonify"
+ ],
+ "Examples": [
+ [
+ "{{ (slice \"A\" \"B\" \"C\") | jsonify }}",
+ "[\"A\",\"B\",\"C\"]"
]
- }
- ]
+ ]
+ }
},
- {
- "Name": "fmt",
- "Funcs": [
- {
- "Name": "Print",
- "Description": "",
- "Aliases": [
- "print"
- ],
- "Examples": [
- [
- "{{ print \"works!\" }}",
- "works!"
- ]
+ "fmt": {
+ "Print": {
+ "Description": "",
+ "Args": [
+ "a"
+ ],
+ "Aliases": [
+ "print"
+ ],
+ "Examples": [
+ [
+ "{{ print \"works!\" }}",
+ "works!"
]
- },
- {
- "Name": "Printf",
- "Description": "",
- "Aliases": [
- "printf"
- ],
- "Examples": [
- [
- "{{ printf \"%s!\" \"works\" }}",
- "works!"
- ]
+ ]
+ },
+ "Printf": {
+ "Description": "",
+ "Args": [
+ "format",
+ "a"
+ ],
+ "Aliases": [
+ "printf"
+ ],
+ "Examples": [
+ [
+ "{{ printf \"%s!\" \"works\" }}",
+ "works!"
]
- },
- {
- "Name": "Println",
- "Description": "",
- "Aliases": [
- "println"
- ],
- "Examples": [
- [
- "{{ println \"works!\" }}",
- "works!\n"
- ]
+ ]
+ },
+ "Println": {
+ "Description": "",
+ "Args": [
+ "a"
+ ],
+ "Aliases": [
+ "println"
+ ],
+ "Examples": [
+ [
+ "{{ println \"works!\" }}",
+ "works!\n"
]
- }
- ]
+ ]
+ }
},
- {
- "Name": "images",
- "Funcs": [
- {
- "Name": "Config",
- "Description": "",
- "Aliases": [
- "imageConfig"
- ],
- "Examples": []
- }
- ]