diff options
| author | Dave Henderson <dhenderson@gmail.com> | 2018-07-26 21:13:08 -0400 |
|---|---|---|
| committer | Dave Henderson <dhenderson@gmail.com> | 2018-07-26 21:51:29 -0400 |
| commit | 90365c708baada8ae1dd136dcca62118873e5c0f (patch) | |
| tree | 67998db621695c795b068906d94a959138b21518 /docs-src | |
| parent | b0de7eac46bd522ca4784548824b7e370058a987 (diff) | |
Doc generation
Signed-off-by: Dave Henderson <dhenderson@gmail.com>
Diffstat (limited to 'docs-src')
| -rw-r--r-- | docs-src/content/functions/conv.yml | 60 | ||||
| -rw-r--r-- | docs-src/content/functions/filepath.yml | 195 | ||||
| -rw-r--r-- | docs-src/content/functions/func_doc.md.tmpl | 46 | ||||
| -rw-r--r-- | docs-src/content/functions/math.yml | 273 | ||||
| -rw-r--r-- | docs-src/content/functions/path.yml | 127 | ||||
| -rw-r--r-- | docs-src/content/functions/strings.yml | 16 | ||||
| -rw-r--r-- | docs-src/content/functions/test.yml | 39 |
7 files changed, 756 insertions, 0 deletions
diff --git a/docs-src/content/functions/conv.yml b/docs-src/content/functions/conv.yml new file mode 100644 index 00000000..4f57f311 --- /dev/null +++ b/docs-src/content/functions/conv.yml @@ -0,0 +1,60 @@ +ns: conv +preamble: | + These are a collection of functions that mostly help converting from one type + to another - generally from a `string` to something else, and vice-versa. +funcs: + - name: conv.Bool + alias: bool + - name: conv.Default + alias: default + - name: conv.Slice + alias: slice + - name: conv.Has + alias: has + - name: conv.Join + alias: join + - name: conv.URL + - name: conv.ParseInt + - name: conv.ParseFloat + - name: conv.ParseUint + - name: conv.Atoi + - name: conv.ToBool + description: | + Converts the input to a boolean value. + Possible `true` values are: `1` or the strings `"t"`, `"true"`, or `"yes"` + (any capitalizations). All other values are considered `false`. + pipeline: true + arguments: + - name: input + required: true + description: The input to convert + examples: + - | + $ gomplate -i '{{ conv.ToBool "yes" }} {{ conv.ToBool true }} {{ conv.ToBool "0x01" }}' + true true true + $ gomplate -i '{{ conv.ToBool false }} {{ conv.ToBool "blah" }} {{ conv.ToBool 0 }}' + false false false + - name: conv.ToBools + description: | + Converts a list of inputs to an array of boolean values. + Possible `true` values are: `1` or the strings `"t"`, `"true"`, or `"yes"` + (any capitalizations). All other values are considered `false`. + pipeline: true + arguments: + - name: input + required: true + description: The input array to convert + examples: + - | + $ gomplate -i '{{ conv.ToBools "yes" true "0x01" }}' + [true true true] + $ gomplate -i '{{ conv.ToBools false "blah" 0 }}' + [false false false] + - name: conv.ToInt64 + - name: conv.ToInt + - name: conv.ToInt64s + - name: conv.ToInts + - name: conv.ToFloat64 + - name: conv.ToFloat64s + - name: conv.ToString + - name: conv.ToStrings diff --git a/docs-src/content/functions/filepath.yml b/docs-src/content/functions/filepath.yml new file mode 100644 index 00000000..84d550d5 --- /dev/null +++ b/docs-src/content/functions/filepath.yml @@ -0,0 +1,195 @@ +ns: filepath +preamble: | + gomplate's path functions are split into 2 namespaces: + - `path`, which is useful for manipulating slash-based (`/`) paths, such as in URLs + - `filepath`, which should be used for local filesystem paths, especially when Windows paths may be involved. + + This page documents the `filepath` namespace - see also the [`path`](../path) documentation. + + These functions are wrappers for Go's [`path/filepath`](https://golang.org/pkg/path/filepath/) package. +funcs: + - name: filepath.Base + description: | + Returns the last element of path. Trailing path separators are removed before extracting the last element. If the path is empty, Base returns `.`. If the path consists entirely of separators, Base returns a single separator. + + A wrapper for Go's [`filepath.Base`](https://golang.org/pkg/path/filepath/#Base) function. + pipeline: true + arguments: + - name: path + required: true + description: The input path + examples: + - | + $ gomplate -i '{{ filepath.Base "/tmp/foo" }}' + foo + - name: filepath.Clean + description: | + Clean returns the shortest path name equivalent to path by purely lexical processing. + + A wrapper for Go's [`filepath.Clean`](https://golang.org/pkg/path/filepath/#Clean) function. + pipeline: true + arguments: + - name: path + required: true + description: The input path + examples: + - | + $ gomplate -i '{{ filepath.Clean "/tmp//foo/../" }}' + /tmp + - name: filepath.Dir + description: | + Returns all but the last element of path, typically the path's directory. + + A wrapper for Go's [`filepath.Dir`](https://golang.org/pkg/path/filepath/#Dir) function. + pipeline: true + arguments: + - name: path + required: true + description: The input path + examples: + - | + $ gomplate -i '{{ filepath.Dir "/tmp/foo" }}' + /tmp + - name: filepath.Ext + description: | + Returns the file name extension used by path. + + A wrapper for Go's [`filepath.Ext`](https://golang.org/pkg/path/filepath/#Ext) function. + pipeline: true + arguments: + - name: path + required: true + description: The input path + examples: + - | + $ gomplate -i '{{ filepath.Ext "/tmp/foo.csv" }}' + .csv + - name: filepath.FromSlash + description: | + Returns the result of replacing each slash (`/`) character in the path with the platform's separator character. + + A wrapper for Go's [`filepath.FromSlash`](https://golang.org/pkg/path/filepath/#FromSlash) function. + pipeline: true + arguments: + - name: path + required: true + description: The input path + examples: + - | + $ gomplate -i '{{ filepath.FromSlash "/foo/bar" }}' + /foo/bar + C:\> gomplate.exe -i '{{ filepath.FromSlash "/foo/bar" }}' + C:\foo\bar + - name: filepath.IsAbs + description: | + Reports whether the path is absolute. + + A wrapper for Go's [`filepath.IsAbs`](https://golang.org/pkg/path/filepath/#IsAbs) function. + pipeline: true + arguments: + - name: path + required: true + description: The input path + examples: + - | + $ gomplate -i 'the path is {{ if (filepath.IsAbs "/tmp/foo.csv") }}absolute{{else}}relative{{end}}' + the path is absolute + $ gomplate -i 'the path is {{ if (filepath.IsAbs "../foo.csv") }}absolute{{else}}relative{{end}}' + the path is relative + - name: filepath.Join + description: | + Joins any number of path elements into a single path, adding a separator if necessary. + + A wrapper for Go's [`filepath.Join`](https://golang.org/pkg/path/filepath/#Join) function. + arguments: + - name: elem... + required: true + description: The path elements to join (0 or more) + examples: + - | + $ gomplate -i '{{ filepath.Join "/tmp" "foo" "bar" }}' + /tmp/foo/bar + C:\> gomplate.exe -i '{{ filepath.Join "C:\tmp" "foo" "bar" }}' + C:\tmp\foo\bar + - name: filepath.Match + description: | + Reports whether name matches the shell file name pattern. + + A wrapper for Go's [`filepath.Match`](https://golang.org/pkg/path/filepath/#Match) function. + arguments: + - name: pattern + required: true + description: The pattern to match on + - name: path + required: true + description: The path to match + examples: + - | + $ gomplate -i '{{ filepath.Match "*.csv" "foo.csv" }}' + true + - name: filepath.Rel + description: | + Returns a relative path that is lexically equivalent to targetpath when joined to basepath with an intervening separator. + + A wrapper for Go's [`filepath.Rel`](https://golang.org/pkg/path/filepath/#Rel) function. + arguments: + - name: basepath + required: true + description: The base path + - name: targetpath + required: true + description: The target path + examples: + - | + $ gomplate -i '{{ filepath.Rel "/a" "/a/b/c" }}' + b/c + - name: filepath.Split + description: | + Splits path immediately following the final path separator, separating it into a directory and file name component. + + The function returns an array with two values, the first being the diretory, and the second the file. + + A wrapper for Go's [`filepath.Split`](https://golang.org/pkg/path/filepath/#Split) function. + pipeline: true + arguments: + - name: path + required: true + description: The input path + examples: + - | + $ gomplate -i '{{ $p := filepath.Split "/tmp/foo" }}{{ $dir := index $p 0 }}{{ $file := index $p 1 }}dir is {{$dir}}, file is {{$file}}' + dir is /tmp/, file is foo + C:\> gomplate.exe -i '{{ $p := filepath.Split `C:\tmp\foo` }}{{ $dir := index $p 0 }}{{ $file := index $p 1 }}dir is {{$dir}}, file is {{$file}}' + dir is C:\tmp\, file is foo + - name: filepath.ToSlash + description: | + Returns the result of replacing each separator character in path with a slash (`/`) character. + + A wrapper for Go's [`filepath.ToSlash`](https://golang.org/pkg/path/filepath/#ToSlash) function. + pipeline: true + arguments: + - name: path + required: true + description: The input path + examples: + - | + $ gomplate -i '{{ filepath.ToSlash "/foo/bar" }}' + /foo/bar + C:\> gomplate.exe -i '{{ filepath.ToSlash `foo\bar\baz` }}' + foo/bar/baz + - name: filepath.VolumeName + description: | + Returns the leading volume name. Given `C:\foo\bar` it returns `C:` on Windows. Given a UNC like `\\host\share\foo` it returns `\\host\share`. On other platforms it returns an empty string. + + A wrapper for Go's [`filepath.VolumeName`](https://golang.org/pkg/path/filepath/#VolumeName) function. + pipeline: true + arguments: + - name: path + required: true + description: The input path + examples: + - | + C:\> gomplate.exe -i 'volume is {{ filepath.VolumeName "C:/foo/bar" }}' + volume is C: + $ gomplate -i 'volume is {{ filepath.VolumeName "/foo/bar" }}' + volume is diff --git a/docs-src/content/functions/func_doc.md.tmpl b/docs-src/content/functions/func_doc.md.tmpl new file mode 100644 index 00000000..742b5afb --- /dev/null +++ b/docs-src/content/functions/func_doc.md.tmpl @@ -0,0 +1,46 @@ +{{ $data := ds "data" -}} +--- +title: {{ $data.ns }} functions +menu: + main: + parent: functions +--- + +{{ $data.preamble -}} + +{{ range $_, $f := $data.funcs }} +## `{{ $f.name }}` +{{ if has $f "alias" }} +**Alias:** `{{$f.alias}}` +{{ end }} + +{{- if has $f "description" }} +{{ $f.description }} +{{ end -}} + +{{ if has $f "arguments" -}} +### Usage +```go +{{ $f.name }} {{ range $f.arguments -}} {{ if not .required }}[{{ .name }}]{{else}}{{ .name }}{{end}} {{end}} +``` +{{ if has $f "pipeline" }}{{ if $f.pipeline }} +```go +{{ $last := (sub (len $f.arguments) 1) -}} +{{ (index $f.arguments $last).name }} | {{ $f.name }} {{ range $i, $a := $f.arguments -}} {{if not (eq $i $last)}}{{ if not $a.required }}[{{ .name }}]{{else}}{{ .name }}{{end}}{{end}} {{end}} +``` +{{ end }}{{ end }} +### Arguments + +| name | description | +|------|-------------| +{{ range $f.arguments }}| `{{.name}}` | _({{if .required}}required{{else}}optional{{end}})_ {{.description}} | +{{ end }} +{{- end -}} +{{if has $f "examples" }} +### Examples + +{{ range $f.examples -}} +```console +{{ . | strings.TrimSpace }} +``` +{{ end }}{{ end }}{{ end -}} diff --git a/docs-src/content/functions/math.yml b/docs-src/content/functions/math.yml new file mode 100644 index 00000000..da9033a8 --- /dev/null +++ b/docs-src/content/functions/math.yml @@ -0,0 +1,273 @@ +ns: math +preamble: | + A set of basic math functions to be able to perform simple arithmetic operations with `gomplate`. + + ### Supported input + + In general, any input will be converted to the correct input type by the various functions in this package, and an appropriately-typed value will be returned type. Special cases are documented. + + In addition to regular base-10 numbers, integers can be + [specified](https://golang.org/ref/spec#Integer_literals) as octal (prefix with + `0`) or hexadecimal (prefix with `0x`). + + Decimal/floating-point numbers can be [specified](https://golang.org/ref/spec#Floating-point_literals) + with optional exponents. + + Some examples demonstrating this: + + ```console + $ NUM=50 gomplate -i '{{ div (getenv "NUM") 10 }}' + 5 + $ gomplate -i '{{ add "0x2" "02" "2.0" "2e0" }}' + 8 + $ gomplate -i '{{ add 2.5 2.5 }}' + 5.0 + ``` +funcs: + - name: math.Abs + description: | + Returns the absolute value of a given number. When the input is an integer, the result will be an `int64`, otherwise it will be a `float64`. + arguments: + - name: num + required: true + description: The input number + examples: + - | + $ gomplate -i '{{ math.Abs -3.5 }} {{ math.Abs 3.5 }} {{ math.Abs -42 }}' + 3.5 3.5 42 + - name: math.Add + alias: add + description: | + Adds all given operators. When one of the inputs is a floating-point number, the result will be a `float64`, otherwise it will be an `int64`. + arguments: + - name: n... + required: true + description: The numbers to add together + examples: + - | + $ gomplate -i '{{ math.Add 1 2 3 4 }} {{ math.Add 1.5 2 3 }}' + 10 6.5 + - name: math.Ceil + description: | + Returns the least integer value greater than or equal to a given floating-point number. This wraps Go's [`math.Ceil`](https://golang.org/pkg/math/#Ceil). + + **Note:** the return value of this function is a `float64` so that the special-cases `NaN` and `Inf` can be returned appropriately. + arguments: + - name: num + required: true + description: The input number. Will be converted to a `float64`, or `0` if not convertable + examples: + - | + $ gomplate -i '{{ range (slice 5.1 42 "3.14" "0xFF" "NaN" "Inf" "-0") }}ceil {{ printf "%#v" . }} = {{ math.Ceil . }}{{"\n"}}{{ end }}' + ceil 5.1 = 6 + ceil 42 = 42 + ceil "3.14" = 4 + ceil "0xFF" = 255 + ceil "NaN" = NaN + ceil "Inf" = +Inf + ceil "-0" = 0 + - name: math.Div + alias: div + description: | + Divide the first number by the second. Division by zero is disallowed. The result will be a `float64`. + pipeline: true + arguments: + - name: a + required: true + description: The divisor + - name: b + required: true + description: The dividend + examples: + - | + $ gomplate -i '{{ math.Div 8 2 }} {{ math.Div 3 2 }}' + 4 1.5 + - name: math.Floor + description: | + Returns the greatest integer value less than or equal to a given floating-point number. This wraps Go's [`math.Floor`](https://golang.org/pkg/math/#Floor). + + **Note:** the return value of this function is a `float64` so that the special-cases `NaN` and `Inf` can be returned appropriately. + arguments: + - name: num + required: true + description: The input number. Will be converted to a `float64`, or `0` if not convertable + examples: + - | + $ gomplate -i '{{ range (slice 5.1 42 "3.14" "0xFF" "NaN" "Inf" "-0") }}floor {{ printf "%#v" . }} = {{ math.Floor . }}{{"\n"}}{{ end }}' + floor 5.1 = 4 + floor 42 = 42 + floor "3.14" = 3 + floor "0xFF" = 255 + floor "NaN" = NaN + floor "Inf" = +Inf + floor "-0" = 0 + - name: math.IsFloat + description: | + Returns whether or not the given number can be interpreted as a floating-point literal, as defined by the [Go language reference](https://golang.org/ref/spec#Floating-point_literals). + + **Note:** If a decimal point is part of the input number, it will be considered a floating-point number, even if the decimal is `0`. + arguments: + - name: num + required: true + description: The value to test + examples: + - | + $ gomplate -i '{{ range (slice 1.0 "-1.0" 5.1 42 "3.14" "foo" "0xFF" "NaN" "Inf" "-0") }}{{ if (math.IsFloat .) }}{{.}} is a float{{"\n"}}{{ end }}{{end}}' + 1 is a float + -1.0 is a float + 5.1 is a float + 3.14 is a float + NaN is a float + Inf is a float + - name: math.IsInt + description: | + Returns whether or not the given number is an integer. + arguments: + - name: num + required: true + description: The value to test + examples: + - | + $ gomplate -i '{{ range (slice 1.0 "-1.0" 5.1 42 "3.14" "foo" "0xFF" "NaN" "Inf" "-0") }}{{ if (math.IsInt .) }}{{.}} is an integer{{"\n"}}{{ end }}{{end}}' + 42 is an integer + 0xFF is an integer + -0 is an integer + - name: math.IsNum + description: | + Returns whether the given input is a number. Useful for `if` conditions. + arguments: + - name: in + required: true + description: The value to test + examples: + - | + $ gomplate -i '{{ math.IsNum "foo" }} {{ math.IsNum 0xDeadBeef }}' + false true + - name: math.Max + description: | + Returns the largest number provided. If any values are floating-point numbers, a `float64` is returned, otherwise an `int64` is returned. The same special-cases as Go's [`math.Max`](https://golang.org/pkg/math/#Max) are followed. + arguments: + - name: nums... + required: true + description: One or more numbers to compare + examples: + - | + $ gomplate -i '{{ math.Max 0 8.0 4.5 "-1.5e-11" }}' + 8 + - name: math.Min + description: | + Returns the smallest number provided. If any values are floating-point numbers, a `float64` is returned, otherwise an `int64` is returned. The same special-cases as Go's [`math.Min`](https://golang.org/pkg/math/#Min) are followed. + arguments: + - name: nums... + required: true + description: One or more numbers to compare + examples: + - | + $ gomplate -i '{{ math.Min 0 8 4.5 "-1.5e-11" }}' + -1.5e-11 + - name: math.Mul + alias: mul + description: | + Multiply all given operators together. + arguments: + - name: n... + required: true + description: The numbers to multiply + examples: + - | + $ gomplate -i '{{ math.Mul 8 8 2 }}' + 128 + - name: math.Pow + alias: pow + description: | + Calculate an exponent - _b<sup>n</sup>_. This wraps Go's [`math.Pow`](https://golang.org/pkg/math/#Pow). If any values are floating-point numbers, a `float64` is returned, otherwise an `int64` is returned. + arguments: + - name: b + required: true + description: The base + - name: 'n' + required: true + description: The exponent + examples: + - | + $ gomplate -i '{{ math.Pow 10 2 }}' + 100 + $ gomplate -i '{{ math.Pow 2 32 }}' + 4294967296 + $ gomplate -i '{{ math.Pow 1.5 2 }}' + 2.2 + - name: math.Rem + alias: rem + description: | + Return the remainder from an integer division operation. + pipeline: true + arguments: + - name: a + required: true + description: The divisor + - name: b + required: true + description: The dividend + examples: + - | + $ gomplate -i '{{ math.Rem 5 3 }}' + 2 + $ gomplate -i '{{ math.Rem -5 3 }}' + -2 + - name: math.Round + description: | + Returns the nearest integer, rounding half away from zero. + + **Note:** the return value of this function is a `float64` so that the special-cases `NaN` and `Inf` can be returned appropriately. + arguments: + - name: num + required: true + description: The input number. Will be converted to a `float64`, or `0` if not convertable + examples: + - | + $ gomplate -i '{{ range (slice -6.5 5.1 42.9 "3.5" 6.5) }}round {{ printf "%#v" . }} = {{ math.Round . }}{{"\n"}}{{ end }}' + round -6.5 = -7 + round 5.1 = 5 + round 42.9 = 43 + round "3.5" = 4 + round 6.5 = 7 + - name: math.Seq + alias: seq + description: | + Return a sequence from `start` to `end`, in steps of `step`. Can handle counting + down as well as up, including with negative numbers. + + Note that the sequence _may_ not end at `end`, if `end` is not divisible by `step`. + arguments: + - name: start + required: false + description: The first number in the sequence (defaults to `1`) + - name: end + required: true + description: The last number in the sequence + - name: step + required: false + description: The amount to increment between each number (defaults to `1`) + examples: + - | + $ gomplate -i '{{ range (math.Seq 5) }}{{.}} {{end}}' + 1 2 3 4 5 + - | + $ gomplate -i '{{ conv.Join (math.Seq 10 -3 2) ", " }}' + 10, 8, 6, 4, 2, 0, -2 + - name: math.Sub + alias: sub + description: | + Subtract the second from the first of the given operators. When one of the inputs is a floating-point number, the result will be a `float64`, otherwise it will be an `int64`. + pipeline: true + arguments: + - name: a + required: true + description: The minuend (the number to subtract from) + - name: b + required: true + description: The subtrahend (the number being subtracted) + examples: + - | + $ gomplate -i '{{ math.Sub 3 1 }}' + 2 diff --git a/docs-src/content/functions/path.yml b/docs-src/content/functions/path.yml new file mode 100644 index 00000000..4be76854 --- /dev/null +++ b/docs-src/content/functions/path.yml @@ -0,0 +1,127 @@ +ns: path +preamble: | + gomplate's path functions are split into 2 namespaces: + - `path`, which is useful for manipulating slash-based (`/`) paths, such as in URLs + - `filepath`, which should be used for local filesystem paths, especially when Windows paths may be involved. + + This page documents the `path` namespace - see also the [`filepath`](../filepath) documentation. + + These functions are wrappers for Go's [`path`](https://golang.org/pkg/path/) and [`path/filepath`](https://golang.org/pkg/path/filepath/) packages. +funcs: + - name: path.Base + description: | + Returns the last element of path. Trailing slashes are removed before extracting the last element. If the path is empty, Base returns `.`. If the path consists entirely of slashes, Base returns `/`. + + A wrapper for Go's [`path.Base`](https://golang.org/pkg/path/#Base) function. + pipeline: true + arguments: + - name: path + required: true + description: The input path + examples: + - | + $ gomplate -i '{{ path.Base "/tmp/foo" }}' + foo + - name: path.Clean + description: | + Clean returns the shortest path name equivalent to path by purely lexical processing. + + A wrapper for Go's [`path.Clean`](https://golang.org/pkg/path/#Clean) function. + pipeline: true + arguments: + - name: path + required: true + description: The input path + examples: + - | + $ gomplate -i '{{ path.Clean "/tmp//foo/../" }}' + /tmp + - name: path.Dir + description: | + Returns all but the last element of path, typically the path's directory. + + A wrapper for Go's [`path.Dir`](https://golang.org/pkg/path/#Dir) function. + pipeline: true + arguments: + - name: path + required: true + description: The input path + examples: + - | + $ gomplate -i '{{ path.Dir "/tmp/foo" }}' + /tmp + - name: path.Ext + description: | + Returns the file name extension used by path. + + A wrapper for Go's [`path.Ext`](https://golang.org/pkg/path/#Ext) function. + pipeline: true + arguments: + - name: path + required: true + description: The input path + examples: + - | + $ gomplate -i '{{ path.Ext "/tmp/foo.csv" }}' + .csv + - name: path.IsAbs + description: | + Reports whether the path is absolute. + + A wrapper for Go's [`path.IsAbs`](https://golang.org/pkg/path/#IsAbs) function. + pipeline: true + arguments: + - name: path + required: true + description: The input path + examples: + - | + $ gomplate -i 'the path is {{ if (path.IsAbs "/tmp/foo.csv") }}absolute{{else}}relative{{end}}' + the path is absolute + $ gomplate -i 'the path is {{ if (path.IsAbs "../foo.csv") }}absolute{{else}}relative{{end}}' + the path is relative + - name: path.Join + description: | + Joins any number of path elements into a single path, adding a separating slash if necessary. + + A wrapper for Go's [`path.Join`](https://golang.org/pkg/path/#Join) function. + arguments: + - name: elem... + required: true + description: The path elements to join (0 or more) + examples: + - | + $ gomplate -i '{{ path.Join "/tmp" "foo" "bar" }}' + /tmp/foo/bar + - name: path.Match + description: | + Reports whether name matches the shell file name pattern. + + A wrapper for Go's [`path.Match`](https://golang.org/pkg/path/#Match) function. + arguments: + - name: pattern + required: true + description: The pattern to match on + - name: path + required: true + description: The path to match + examples: + - | + $ gomplate -i '{{ path.Match "*.csv" "foo.csv" }}' + true + - name: path.Split + description: | + Splits path immediately following the final slash, separating it into a directory and file name component. + + The function returns an array with two values, the first being the diretory, and the second the file. + + A wrapper for Go's [`path.Split`](https://golang.org/pkg/path/#Split) function. + pipeline: true + arguments: + - name: path + required: true + description: The input path + examples: + - | + $ gomplate -i '{{ $p := path.Split "/tmp/foo" }}{{ $dir := index $p 0 }}{{ $file := index $p 1 }}dir is {{$dir}}, file is {{$file}}' + dir is /tmp/, file is foo diff --git a/docs-src/content/functions/strings.yml b/docs-src/content/functions/strings.yml new file mode 100644 index 00000000..6e3807c3 --- /dev/null +++ b/docs-src/content/functions/strings.yml @@ -0,0 +1,16 @@ +ns: strings +preamble: '' +funcs: + - name: strings.Sort + alias: sort + description: | + Returns an alphanumerically-sorted copy of a given string list. + pipeline: true + arguments: + - name: list + required: true + description: The list to sort + examples: + - | + $ gomplate -i '{{ (slice "foo" "bar" "baz") | sort }}' + [bar baz foo] diff --git a/docs-src/content/functions/test.yml b/docs-src/content/functions/test.yml new file mode 100644 index 00000000..f2e21099 --- /dev/null +++ b/docs-src/content/functions/test.yml @@ -0,0 +1,39 @@ +ns: test +preamble: | + The `test` namespace contains some simple functions to help validate + assumptions and can cause template generation to fail in specific cases. +funcs: + - name: test.Assert + alias: assert + description: | + Asserts that the given expression or value is `true`. If it is not, causes + template generation to fail immediately with an optional message. + pipeline: true + arguments: + - name: message + required: false + description: The optional message to provide in the case of failure + - name: value + required: true + description: The value to test + examples: + - | + $ gomplate -i '{{ assert (eq "foo" "bar") }}' + template: <arg>:1:3: executing "<arg>" at <assert (eq "foo" "ba...>: error calling assert: assertion failed + $ gomplate -i '{{ assert "something horrible happened" false }}' + template: <arg>:1:3: executing "<arg>" at <assert "something ho...>: error calling assert: assertion failed: something horrible happened + - name: test.Fail + alias: fail + description: | + Cause template generation to fail immediately, with an optional message. + pipeline: true + arguments: + - name: message + required: false + description: The optional message to provide + examples: + - | + $ gomplate -i '{{ fail }}' + template: <arg>:1:3: executing "<arg>" at <fail>: error calling fail: template generation failed + $ gomplate -i '{{ test.Fail "something is wrong!" }}' + template: <arg>:1:7: executing "<arg>" at <test.Fail>: error calling Fail: template generation failed: something is wrong! |
