glide up
This commit is contained in:
246
vendor/github.com/Masterminds/sprig/README.md
generated
vendored
246
vendor/github.com/Masterminds/sprig/README.md
generated
vendored
@@ -1,4 +1,6 @@
|
||||
# Sprig: Template functions for Go templates
|
||||
[](https://masterminds.github.io/stability/sustained.html)
|
||||
[](https://travis-ci.org/Masterminds/sprig)
|
||||
|
||||
The Go language comes with a [built-in template
|
||||
language](http://golang.org/pkg/text/template/), but not
|
||||
@@ -6,12 +8,15 @@ very many template functions. This library provides a group of commonly
|
||||
used template functions.
|
||||
|
||||
It is inspired by the template functions found in
|
||||
[Twig](http://twig.sensiolabs.org/documentation).
|
||||
|
||||
[](https://travis-ci.org/Masterminds/sprig)
|
||||
[Twig](http://twig.sensiolabs.org/documentation) and also in various
|
||||
JavaScript libraries, such as [underscore.js](http://underscorejs.org/).
|
||||
|
||||
## Usage
|
||||
|
||||
Template developers can read the [Sprig function documentation](http://masterminds.github.io/sprig/) to
|
||||
learn about the >100 template functions available.
|
||||
|
||||
For Go developers wishing to include Sprig as a library in their programs,
|
||||
API documentation is available [at GoDoc.org](http://godoc.org/github.com/Masterminds/sprig), but
|
||||
read on for standard usage.
|
||||
|
||||
@@ -54,241 +59,6 @@ Produces:
|
||||
HELLO!HELLO!HELLO!HELLO!HELLO!
|
||||
```
|
||||
|
||||
## Functions
|
||||
|
||||
### Date Functions
|
||||
|
||||
- date: Format a date, where a date is an integer type or a time.Time type, and
|
||||
format is a time.Format formatting string.
|
||||
- dateModify: Given a date, modify it with a duration: `date_modify "-1.5h" now`. If the duration doesn't
|
||||
parse, it returns the time unaltered. See `time.ParseDuration` for info on duration strings.
|
||||
- now: Current time.Time, for feeding into date-related functions.
|
||||
- htmlDate: Format a date for use in the value field of an HTML "date" form element.
|
||||
- dateInZone: Like date, but takes three arguments: format, timestamp,
|
||||
timezone.
|
||||
- htmlDateInZone: Like htmlDate, but takes two arguments: timestamp,
|
||||
timezone.
|
||||
|
||||
### String Functions
|
||||
|
||||
- trim: strings.TrimSpace
|
||||
- trimAll: strings.Trim, but with the argument order reversed `trimAll "$" "$5.00"` or `"$5.00 | trimAll "$"`
|
||||
- trimSuffix: strings.TrimSuffix, but with the argument order reversed `trimSuffix "-" "5-"`
|
||||
- trimPrefix: strings.TrimPrefix, but with the argument order reversed `trimPrefix "$" "$5"`
|
||||
- upper: strings.ToUpper
|
||||
- lower: strings.ToLower
|
||||
- title: strings.Title
|
||||
- repeat: strings.Repeat, but with the arguments switched: `repeat count str`. (This simplifies common pipelines)
|
||||
- substr: Given string, start, and length, return a substr.
|
||||
- nospace: Remove all spaces from a string. `h e l l o` becomes
|
||||
`hello`.
|
||||
- abbrev: Truncate a string with ellipses
|
||||
- trunc: Truncate a string (no suffix). `trunc 5 "Hello World"` yields "hello".
|
||||
- abbrevboth: Truncate both sides of a string with ellipses
|
||||
- untitle: Remove title case
|
||||
- intials: Given multiple words, return the first letter of each
|
||||
word
|
||||
- randAlphaNum: Generate a random alpha-numeric string
|
||||
- randAlpha: Generate a random alphabetic string
|
||||
- randAscii: Generate a random ASCII string, including symbols
|
||||
- randNumeric: Generate a random numeric string
|
||||
- wrap: Wrap text at the given column count
|
||||
- wrapWith: Wrap text at the given column count, and with the given
|
||||
string for a line terminator: `wrap 50 "\n\t" $string`
|
||||
- contains: strings.Contains, but with the arguments switched: `contains "cat" "uncatch"`. (This simplifies common pipelines)
|
||||
- hasPrefix: strings.hasPrefix, but with the arguments switched: `hasPrefix "cat" "catch"`.
|
||||
- hasSuffix: strings.hasSuffix, but with the arguments switched: `hasSuffix "cat" "ducat"`.
|
||||
- quote: Wrap strings in double quotes. `quote "a" "b"` returns `"a"
|
||||
"b"`
|
||||
- squote: Wrap strings in single quotes.
|
||||
- cat: Concatenate strings, separating them by spaces. `cat $a $b $c`.
|
||||
- indent: Indent a string using space characters. `indent 4 "foo\nbar"` produces " foo\n bar"
|
||||
- replace: Replace an old with a new in a string: `$name | replace " " "-"`
|
||||
- plural: Choose singular or plural based on length: `len $fish | plural
|
||||
"one anchovy" "many anchovies"`
|
||||
- uuidv4: Generate a UUID v4 string
|
||||
- sha256sum: Generate a hex encoded sha256 hash of the input
|
||||
- toString: Convert something to a string
|
||||
|
||||
### String Slice Functions:
|
||||
|
||||
- join: strings.Join, but as `join SEP SLICE`
|
||||
- split: strings.Split, but as `split SEP STRING`. The results are returned
|
||||
as a map with the indexes set to _N, where N is an integer starting from 0.
|
||||
Use it like this: `{{$v := "foo/bar/baz" | split "/"}}{{$v._0}}` (Prints `foo`)
|
||||
- splitList: strings.Split, but as `split SEP STRING`. The results are returned
|
||||
as an array.
|
||||
- toStrings: convert a list to a list of strings. 'list 1 2 3 | toStrings' produces '["1" "2" "3"]'
|
||||
- sortAlpha: sort a list lexicographically.
|
||||
|
||||
### Integer Slice Functions:
|
||||
|
||||
- until: Given an integer, returns a slice of counting integers from 0 to one
|
||||
less than the given integer: `range $i, $e := until 5`
|
||||
- untilStep: Given start, stop, and step, return an integer slice starting at
|
||||
'start', stopping at `stop`, and incrementing by 'step'. This is the same
|
||||
as Python's long-form of 'range'.
|
||||
|
||||
### Conversions:
|
||||
|
||||
- atoi: Convert a string to an integer. 0 if the integer could not be parsed.
|
||||
- int: Convert a string or numeric to an int
|
||||
- int64: Convert a string or numeric to an int64
|
||||
- float64: Convert a string or numeric to a float64
|
||||
|
||||
### Defaults:
|
||||
|
||||
- default: Give a default value. Used like this: {{trim " "| default "empty"}}.
|
||||
Since trim produces an empty string, the default value is returned. For
|
||||
things with a length (strings, slices, maps), len(0) will trigger the default.
|
||||
For numbers, the value 0 will trigger the default. For booleans, false will
|
||||
trigger the default. For structs, the default is never returned (there is
|
||||
no clear empty condition). For everything else, nil value triggers a default.
|
||||
- empty: Returns true if the given value is the zero value for that
|
||||
type. Structs are always non-empty.
|
||||
- coalesce: Given a list of items, return the first non-empty one.
|
||||
This follows the same rules as 'empty'. `{{ coalesce .someVal 0 "hello" }}`
|
||||
will return `.someVal` if set, or else return "hello". The 0 is skipped
|
||||
because it is an empty value.
|
||||
- compact: Return a copy of a list with all of the empty values removed.
|
||||
`list 0 1 2 "" | compact` will return `[1 2]`
|
||||
|
||||
### OS:
|
||||
|
||||
- env: Read an environment variable.
|
||||
- expandenv: Expand all environment variables in a string.
|
||||
|
||||
### File Paths:
|
||||
- base: Return the last element of a path. https://golang.org/pkg/path#Base
|
||||
- dir: Remove the last element of a path. https://golang.org/pkg/path#Dir
|
||||
- clean: Clean a path to the shortest equivalent name. (e.g. remove "foo/.."
|
||||
from "foo/../bar.html") https://golang.org/pkg/path#Clean
|
||||
- ext: Get the extension for a file path: https://golang.org/pkg/path#Ext
|
||||
- isAbs: Returns true if a path is absolute: https://golang.org/pkg/path#IsAbs
|
||||
|
||||
### Encoding:
|
||||
|
||||
- b32enc: Encode a string into a Base32 string
|
||||
- b32dec: Decode a string from a Base32 string
|
||||
- b64enc: Encode a string into a Base64 string
|
||||
- b64dec: Decode a string from a Base64 string
|
||||
|
||||
### Data Structures:
|
||||
|
||||
- tuple: Takes an arbitrary list of items and returns a slice of items. Its
|
||||
tuple-ish properties are mainly gained through the template idiom, and not
|
||||
through an API provided here. WARNING: The implementation of tuple will
|
||||
change in the future.
|
||||
- list: An arbitrary ordered list of items. (This is prefered over tuple.)
|
||||
- dict: Takes a list of name/values and returns a map[string]interface{}.
|
||||
The first parameter is converted to a string and stored as a key, the
|
||||
second parameter is treated as the value. And so on, with odds as keys and
|
||||
evens as values. If the function call ends with an odd, the last key will
|
||||
be assigned the empty string. Non-string keys are converted to strings as
|
||||
follows: []byte are converted, fmt.Stringers will have String() called.
|
||||
errors will have Error() called. All others will be passed through
|
||||
fmt.Sprtinf("%v"). _dicts are unordered_.
|
||||
|
||||
List:
|
||||
|
||||
```
|
||||
{{$t := list 1 "a" "foo"}}
|
||||
{{index $t 2}}{{index $t 0 }}{{index $t 1}}
|
||||
{{/* Prints foo1a *}}
|
||||
```
|
||||
|
||||
Dict:
|
||||
```
|
||||
{{ $t := map "key1" "value1" "key2" "value2" }}
|
||||
{{ $t.key2 }}
|
||||
{{ /* Prints value2 *}}
|
||||
```
|
||||
|
||||
|
||||
### Lists Functions:
|
||||
|
||||
These are used to manipulate lists: `{{ list 1 2 3 | reverse | first }}`
|
||||
|
||||
- first: Get the first item in a 'list'. 'list 1 2 3 | first' prints '1'
|
||||
- last: Get the last item in a 'list': 'list 1 2 3 | last ' prints '3'
|
||||
- rest: Get all but the first item in a list: 'list 1 2 3 | rest' returns '[2 3]'
|
||||
- initial: Get all but the last item in a list: 'list 1 2 3 | initial' returns '[1 2]'
|
||||
- append: Add an item to the end of a list: 'append $list 4' adds '4' to the end of '$list'
|
||||
- prepend: Add an item to the beginning of a list: 'prepend $list 4' puts 4 at the beginning of the list.
|
||||
- reverse: Reverse the items in a list.
|
||||
- uniq: Remove duplicates from a list.
|
||||
- without: Return a list with the given values removed: 'without (list 1 2 3) 1' would return '[2 3]'
|
||||
- has: Return 'tru' if the item is found in the list: 'has "foo" $list' will return 'true' if the list contains "foo"
|
||||
|
||||
### Dict Functions:
|
||||
|
||||
These are used to manipulate dicts.
|
||||
|
||||
- set: Takes a dict, a key, and a value, and sets that key/value pair in
|
||||
the dict. `set $dict $key $value`. For convenience, it returns the dict,
|
||||
even though the dict was modified in place.
|
||||
- unset: Takes a dict and a key, and deletes that key/value pair from the
|
||||
dict. `unset $dict $key`. This returns the dict for convenience.
|
||||
- hasKey: Takes a dict and a key, and returns boolean true if the key is in
|
||||
the dict.
|
||||
- pluck: Given a key and one or more maps, get all of the values for that key.
|
||||
- keys: Get an array of all of the keys in a dict. Order is not guaranteed.
|
||||
- pick: Select just the given keys out of the dict, and return a new dict.
|
||||
- omit: Return a dict without the given keys.
|
||||
|
||||
### Reflection:
|
||||
|
||||
- typeOf: Takes an interface and returns a string representation of the type.
|
||||
For pointers, this will return a type prefixed with an asterisk(`*`). So
|
||||
a pointer to type `Foo` will be `*Foo`.
|
||||
- typeIs: Compares an interface with a string name, and returns true if they match.
|
||||
Note that a pointer will not match a reference. For example `*Foo` will not
|
||||
match `Foo`.
|
||||
- typeIsLike: returns true if the interface is of the given type, or
|
||||
is a pointer to the given type.
|
||||
- kindOf: Takes an interface and returns a string representation of its kind.
|
||||
- kindIs: Returns true if the given string matches the kind of the given interface.
|
||||
|
||||
Note: None of these can test whether or not something implements a given
|
||||
interface, since doing so would require compiling the interface in ahead of
|
||||
time.
|
||||
|
||||
|
||||
### Math Functions:
|
||||
|
||||
Integer functions will convert integers of any width to `int64`. If a
|
||||
string is passed in, functions will attempt to conver with
|
||||
`strconv.ParseInt(s, 1064)`. If this fails, the value will be treated as 0.
|
||||
|
||||
- add1: Increment an integer by 1
|
||||
- add: Sum integers. `add 1 2 3` renders `6`
|
||||
- sub: Subtract the second integer from the first
|
||||
- div: Divide the first integer by the second
|
||||
- mod: Module of first integer divided by second
|
||||
- mul: Multiply integers integers
|
||||
- max (biggest): Return the biggest of a series of integers. `max 1 2 3`
|
||||
returns `3`.
|
||||
- min: Return the smallest of a series of integers. `min 1 2 3` returns
|
||||
`1`.
|
||||
|
||||
### Cryptographic Functions:
|
||||
|
||||
- derivePassword: Derive a password from the given parameters according to the "Master Password" algorithm (http://masterpasswordapp.com/algorithm.html)
|
||||
Given parameters (in order) are:
|
||||
`counter` (starting with 1), `password_type` (maximum, long, medium, short, basic, or pin), `password`,
|
||||
`user`, and `site`. The following line generates a long password for the user "user" and with a master-password "password" on the site "example.com":
|
||||
```
|
||||
{{ derivePassword 1 "long" "password" "user" "example.com" }}
|
||||
```
|
||||
|
||||
## SemVer Functions:
|
||||
|
||||
These functions provide version parsing and comparisons for SemVer 2 version
|
||||
strings.
|
||||
|
||||
- semver: Parse a semantic version and return a Version object.
|
||||
- semverCompare: Compare a SemVer range to a particular version.
|
||||
|
||||
## Principles:
|
||||
|
||||
The following principles were used in deciding on which functions to add, and
|
||||
|
13
vendor/github.com/Masterminds/sprig/defaults.go
generated
vendored
13
vendor/github.com/Masterminds/sprig/defaults.go
generated
vendored
@@ -1,6 +1,7 @@
|
||||
package sprig
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"reflect"
|
||||
)
|
||||
|
||||
@@ -60,3 +61,15 @@ func coalesce(v ...interface{}) interface{} {
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// toJson encodes an item into a JSON string
|
||||
func toJson(v interface{}) string {
|
||||
output, _ := json.Marshal(v)
|
||||
return string(output)
|
||||
}
|
||||
|
||||
// toPrettyJson encodes an item into a pretty (indented) JSON string
|
||||
func toPrettyJson(v interface{}) string {
|
||||
output, _ := json.MarshalIndent(v, "", " ")
|
||||
return string(output)
|
||||
}
|
||||
|
23
vendor/github.com/Masterminds/sprig/defaults_test.go
generated
vendored
23
vendor/github.com/Masterminds/sprig/defaults_test.go
generated
vendored
@@ -82,3 +82,26 @@ func TestCoalesce(t *testing.T) {
|
||||
t.Error(err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestToJson(t *testing.T) {
|
||||
dict := map[string]interface{}{"Top": map[string]interface{}{"bool": true, "string": "test", "number": 42}}
|
||||
|
||||
tpl := `{{.Top | toJson}}`
|
||||
expected := `{"bool":true,"number":42,"string":"test"}`
|
||||
if err := runtv(tpl, expected, dict); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestToPrettyJson(t *testing.T) {
|
||||
dict := map[string]interface{}{"Top": map[string]interface{}{"bool": true, "string": "test", "number": 42}}
|
||||
tpl := `{{.Top | toPrettyJson}}`
|
||||
expected := `{
|
||||
"bool": true,
|
||||
"number": 42,
|
||||
"string": "test"
|
||||
}`
|
||||
if err := runtv(tpl, expected, dict); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
}
|
||||
|
10
vendor/github.com/Masterminds/sprig/dict.go
generated
vendored
10
vendor/github.com/Masterminds/sprig/dict.go
generated
vendored
@@ -1,5 +1,7 @@
|
||||
package sprig
|
||||
|
||||
import "github.com/imdario/mergo"
|
||||
|
||||
func set(d map[string]interface{}, key string, value interface{}) map[string]interface{} {
|
||||
d[key] = value
|
||||
return d
|
||||
@@ -72,3 +74,11 @@ func dict(v ...interface{}) map[string]interface{} {
|
||||
}
|
||||
return dict
|
||||
}
|
||||
|
||||
func merge(dst map[string]interface{}, src map[string]interface{}) interface{} {
|
||||
if err := mergo.Merge(&dst, src); err != nil {
|
||||
// Swallow errors inside of a template.
|
||||
return ""
|
||||
}
|
||||
return dst
|
||||
}
|
||||
|
37
vendor/github.com/Masterminds/sprig/dict_test.go
generated
vendored
37
vendor/github.com/Masterminds/sprig/dict_test.go
generated
vendored
@@ -135,3 +135,40 @@ func TestCompact(t *testing.T) {
|
||||
assert.NoError(t, runt(tpl, expect))
|
||||
}
|
||||
}
|
||||
|
||||
func TestMerge(t *testing.T) {
|
||||
dict := map[string]interface{}{
|
||||
"src": map[string]interface{}{
|
||||
"a": 1,
|
||||
"b": 2,
|
||||
"d": map[string]interface{}{
|
||||
"e": "four",
|
||||
},
|
||||
"g": []int{6, 7},
|
||||
},
|
||||
"dst": map[string]interface{}{
|
||||
"a": "one",
|
||||
"c": 3,
|
||||
"d": map[string]interface{}{
|
||||
"f": 5,
|
||||
},
|
||||
"g": []int{8, 9},
|
||||
},
|
||||
}
|
||||
tpl := `{{merge .dst .src}}`
|
||||
_, err := runRaw(tpl, dict)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
expected := map[string]interface{}{
|
||||
"a": "one", // key overridden
|
||||
"b": 2, // merged from src
|
||||
"c": 3, // merged from dst
|
||||
"d": map[string]interface{}{ // deep merge
|
||||
"e": "four",
|
||||
"f": 5,
|
||||
},
|
||||
"g": []int{8, 9}, // overridden - arrays are not merged
|
||||
}
|
||||
assert.Equal(t, expected, dict["dst"])
|
||||
}
|
||||
|
6
vendor/github.com/Masterminds/sprig/doc.go
generated
vendored
6
vendor/github.com/Masterminds/sprig/doc.go
generated
vendored
@@ -19,7 +19,7 @@ Date Functions
|
||||
- date FORMAT TIME: Format a date, where a date is an integer type or a time.Time type, and
|
||||
format is a time.Format formatting string.
|
||||
- dateModify: Given a date, modify it with a duration: `date_modify "-1.5h" now`. If the duration doesn't
|
||||
parse, it returns the time unaltered. See `time.ParseDuration` for info on duration strings.
|
||||
parse, it returns the time unaltered. See `time.ParseDuration` for info on duration strings.
|
||||
- now: Current time.Time, for feeding into date-related functions.
|
||||
- htmlDate TIME: Format a date for use in the value field of an HTML "date" form element.
|
||||
- dateInZone FORMAT TIME TZ: Like date, but takes three arguments: format, timestamp,
|
||||
@@ -68,7 +68,7 @@ String Slice Functions:
|
||||
- split: strings.Split, but as `split SEP STRING`. The results are returned
|
||||
as a map with the indexes set to _N, where N is an integer starting from 0.
|
||||
Use it like this: `{{$v := "foo/bar/baz" | split "/"}}{{$v._0}}` (Prints `foo`)
|
||||
- splitList: strings.Split, but as `split SEP STRING`. The results are returned
|
||||
- splitList: strings.Split, but as `split SEP STRING`. The results are returned
|
||||
as an array.
|
||||
- toStrings: convert a list to a list of strings. 'list 1 2 3 | toStrings' produces '["1" "2" "3"]'
|
||||
- sortAlpha: sort a list lexicographically.
|
||||
@@ -114,7 +114,7 @@ File Paths:
|
||||
- base: Return the last element of a path. https://golang.org/pkg/path#Base
|
||||
- dir: Remove the last element of a path. https://golang.org/pkg/path#Dir
|
||||
- clean: Clean a path to the shortest equivalent name. (e.g. remove "foo/.."
|
||||
from "foo/../bar.html") https://golang.org/pkg/path#Clean
|
||||
from "foo/../bar.html") https://golang.org/pkg/path#Clean
|
||||
- ext: https://golang.org/pkg/path#Ext
|
||||
- isAbs: https://golang.org/pkg/path#IsAbs
|
||||
|
||||
|
9
vendor/github.com/Masterminds/sprig/docs/dicts.md
generated
vendored
9
vendor/github.com/Masterminds/sprig/docs/dicts.md
generated
vendored
@@ -75,6 +75,15 @@ inserted.
|
||||
A common idiom in Sprig templates is to uses `pluck... | first` to get the first
|
||||
matching key out of a collection of dictionaries.
|
||||
|
||||
## merge
|
||||
|
||||
Merge two dictionaries into one, giving precedence to the dest dictionary:
|
||||
|
||||
```
|
||||
$newdict := merge $dest $source
|
||||
```
|
||||
|
||||
This is a deep merge operation.
|
||||
|
||||
## keys
|
||||
|
||||
|
11
vendor/github.com/Masterminds/sprig/docs/flow_control.md
generated
vendored
Normal file
11
vendor/github.com/Masterminds/sprig/docs/flow_control.md
generated
vendored
Normal file
@@ -0,0 +1,11 @@
|
||||
# Flow Control Functions
|
||||
|
||||
## fail
|
||||
|
||||
Unconditionally returns an empty `string` and an `error` with the specified
|
||||
text. This is useful in scenarios where other conditionals have determined that
|
||||
template rendering should fail.
|
||||
|
||||
```
|
||||
fail "Please accept the end user license agreement"
|
||||
```
|
33
vendor/github.com/Masterminds/sprig/docs/index.md
generated
vendored
33
vendor/github.com/Masterminds/sprig/docs/index.md
generated
vendored
@@ -2,21 +2,22 @@
|
||||
|
||||
The Sprig library provides over 70 template functions for Go's template language.
|
||||
|
||||
- [String Functions](strings.html): `trim`, `wrap`, `randAlpha`, `plural`, etc.
|
||||
- [String List Functions](string_slice.html): `splitList`, `sortAlpha`, etc.
|
||||
- [Math Functions](math.html): `add`, `max`, `mul`, etc.
|
||||
- [Integer Slice Functions](integer_slice.html): `until`, `untilStep`
|
||||
- [Date Functions](date.html): `now`, `date`, etc.
|
||||
- [Defaults Functions](defaults.html): `default`, `empty`, `coalesce`
|
||||
- [Encoding Functions](encoding.html): `b64enc`, `b64dec`, etc.
|
||||
- [Lists and List Functions](lists.html): `list`, `first`, `uniq`, etc.
|
||||
- [Dictionaries and Dict Functions](dicts.html): `dict`, `hasKey`, `pluck`, etc.
|
||||
- [Type Conversion Functions](conversion.html): `atoi`, `int64`, `toString`, etc.
|
||||
- [File Path Functions](paths.html): `base`, `dir`, `ext`, `clean`, `isAbs`
|
||||
- [String Functions](strings.md): `trim`, `wrap`, `randAlpha`, `plural`, etc.
|
||||
- [String List Functions](string_slice.md): `splitList`, `sortAlpha`, etc.
|
||||
- [Math Functions](math.md): `add`, `max`, `mul`, etc.
|
||||
- [Integer Slice Functions](integer_slice.md): `until`, `untilStep`
|
||||
- [Date Functions](date.md): `now`, `date`, etc.
|
||||
- [Defaults Functions](defaults.md): `default`, `empty`, `coalesce`
|
||||
- [Encoding Functions](encoding.md): `b64enc`, `b64dec`, etc.
|
||||
- [Lists and List Functions](lists.md): `list`, `first`, `uniq`, etc.
|
||||
- [Dictionaries and Dict Functions](dicts.md): `dict`, `hasKey`, `pluck`, etc.
|
||||
- [Type Conversion Functions](conversion.md): `atoi`, `int64`, `toString`, etc.
|
||||
- [File Path Functions](paths.md): `base`, `dir`, `ext`, `clean`, `isAbs`
|
||||
- [Flow Control Functions](flow_control.md): `fail`
|
||||
- Advanced Functions
|
||||
- [UUID Functions](uuid.html): `uuidv4`
|
||||
- [OS Functions](os.html): `env`, `expandenv`
|
||||
- [Version Comparison Functions](semver.html): `semver`, `semverCompare`
|
||||
- [Reflection](reflection.html): `typeOf`, `kindIs`, `typeIsLike`, etc.
|
||||
- [Cryptographic and Security Functions](crypto.html): `derivePassword`, `sha256sum`, `genPrivateKey`
|
||||
- [UUID Functions](uuid.md): `uuidv4`
|
||||
- [OS Functions](os.md): `env`, `expandenv`
|
||||
- [Version Comparison Functions](semver.md): `semver`, `semverCompare`
|
||||
- [Reflection](reflection.md): `typeOf`, `kindIs`, `typeIsLike`, etc.
|
||||
- [Cryptographic and Security Functions](crypto.md): `derivePassword`, `sha256sum`, `genPrivateKey`
|
||||
|
||||
|
37
vendor/github.com/Masterminds/sprig/docs/strings.md
generated
vendored
37
vendor/github.com/Masterminds/sprig/docs/strings.md
generated
vendored
@@ -278,6 +278,43 @@ rules. And `0` is considered a plural because the English language treats it
|
||||
as such (`zero anchovies`). The Sprig developers are working on a solution for
|
||||
better internationalization.
|
||||
|
||||
## snakecase
|
||||
|
||||
Convert string from camelCase to snake_case.
|
||||
|
||||
Introduced in 2.12.0.
|
||||
|
||||
```
|
||||
snakecase "FirstName"
|
||||
```
|
||||
|
||||
This above will produce `first_name`.
|
||||
|
||||
## camelcase
|
||||
|
||||
Convert string from snake_case to CamelCase
|
||||
|
||||
Introduced in 2.12.0.
|
||||
|
||||
```
|
||||
camelcase "http_server"
|
||||
```
|
||||
|
||||
This above will produce `HttpServer`.
|
||||
|
||||
## shuffle
|
||||
|
||||
Shuffle a string.
|
||||
|
||||
Introduced in 2.12.0.
|
||||
|
||||
|
||||
```
|
||||
shuffle "hello"
|
||||
```
|
||||
|
||||
The above will randomize the letters in `hello`, perhaps producing `oelhl`.
|
||||
|
||||
## See Also...
|
||||
|
||||
The [Conversion Functions](conversion.html) contain functions for converting
|
||||
|
16
vendor/github.com/Masterminds/sprig/flow_control_test.go
generated
vendored
Normal file
16
vendor/github.com/Masterminds/sprig/flow_control_test.go
generated
vendored
Normal file
@@ -0,0 +1,16 @@
|
||||
package sprig
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestFail(t *testing.T) {
|
||||
const msg = "This is an error!"
|
||||
tpl := fmt.Sprintf(`{{fail "%s"}}`, msg)
|
||||
_, err := runRaw(tpl, nil)
|
||||
assert.Error(t, err)
|
||||
assert.Contains(t, err.Error(), msg)
|
||||
}
|
19
vendor/github.com/Masterminds/sprig/functions.go
generated
vendored
19
vendor/github.com/Masterminds/sprig/functions.go
generated
vendored
@@ -1,6 +1,7 @@
|
||||
package sprig
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"html/template"
|
||||
"os"
|
||||
"path"
|
||||
@@ -10,6 +11,7 @@ import (
|
||||
"time"
|
||||
|
||||
util "github.com/aokoli/goutils"
|
||||
"github.com/huandu/xstrings"
|
||||
)
|
||||
|
||||
// Produce the function map.
|
||||
@@ -122,6 +124,9 @@ var genericMap = map[string]interface{}{
|
||||
"randAscii": randAscii,
|
||||
"randNumeric": randNumeric,
|
||||
"swapcase": util.SwapCase,
|
||||
"shuffle": xstrings.Shuffle,
|
||||
"snakecase": xstrings.ToSnakeCase,
|
||||
"camelcase": xstrings.ToCamelCase,
|
||||
"wrap": func(l int, s string) string { return util.Wrap(s, l) },
|
||||
"wrapWith": func(l int, sep, str string) string { return util.WrapCustom(str, l, sep, true) },
|
||||
// Switch order so that "foobar" | contains "foo"
|
||||
@@ -185,10 +190,12 @@ var genericMap = map[string]interface{}{
|
||||
"sortAlpha": sortAlpha,
|
||||
|
||||
// Defaults
|
||||
"default": dfault,
|
||||
"empty": empty,
|
||||
"coalesce": coalesce,
|
||||
"compact": compact,
|
||||
"default": dfault,
|
||||
"empty": empty,
|
||||
"coalesce": coalesce,
|
||||
"compact": compact,
|
||||
"toJson": toJson,
|
||||
"toPrettyJson": toPrettyJson,
|
||||
|
||||
// Reflection
|
||||
"typeOf": typeOf,
|
||||
@@ -225,6 +232,7 @@ var genericMap = map[string]interface{}{
|
||||
"keys": keys,
|
||||
"pick": pick,
|
||||
"omit": omit,
|
||||
"merge": merge,
|
||||
|
||||
"append": push, "push": push,
|
||||
"prepend": prepend,
|
||||
@@ -247,4 +255,7 @@ var genericMap = map[string]interface{}{
|
||||
// SemVer:
|
||||
"semver": semver,
|
||||
"semverCompare": semverCompare,
|
||||
|
||||
// Flow Control:
|
||||
"fail": func(msg string) (string, error) { return "", errors.New(msg) },
|
||||
}
|
||||
|
26
vendor/github.com/Masterminds/sprig/functions_test.go
generated
vendored
26
vendor/github.com/Masterminds/sprig/functions_test.go
generated
vendored
@@ -3,10 +3,12 @@ package sprig
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"math/rand"
|
||||
"os"
|
||||
"testing"
|
||||
"text/template"
|
||||
|
||||
"github.com/aokoli/goutils"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
@@ -47,6 +49,30 @@ func TestExt(t *testing.T) {
|
||||
assert.NoError(t, runt(`{{ ext "/foo/bar/baz.txt" }}`, ".txt"))
|
||||
}
|
||||
|
||||
func TestSnakeCase(t *testing.T) {
|
||||
assert.NoError(t, runt(`{{ snakecase "FirstName" }}`, "first_name"))
|
||||
assert.NoError(t, runt(`{{ snakecase "HTTPServer" }}`, "http_server"))
|
||||
assert.NoError(t, runt(`{{ snakecase "NoHTTPS" }}`, "no_https"))
|
||||
assert.NoError(t, runt(`{{ snakecase "GO_PATH" }}`, "go_path"))
|
||||
assert.NoError(t, runt(`{{ snakecase "GO PATH" }}`, "go_path"))
|
||||
assert.NoError(t, runt(`{{ snakecase "GO-PATH" }}`, "go_path"))
|
||||
}
|
||||
|
||||
func TestCamelCase(t *testing.T) {
|
||||
assert.NoError(t, runt(`{{ camelcase "http_server" }}`, "HttpServer"))
|
||||
assert.NoError(t, runt(`{{ camelcase "_camel_case" }}`, "_CamelCase"))
|
||||
assert.NoError(t, runt(`{{ camelcase "no_https" }}`, "NoHttps"))
|
||||
assert.NoError(t, runt(`{{ camelcase "_complex__case_" }}`, "_Complex_Case_"))
|
||||
assert.NoError(t, runt(`{{ camelcase "all" }}`, "All"))
|
||||
}
|
||||
|
||||
func TestShuffle(t *testing.T) {
|
||||
goutils.RANDOM = rand.New(rand.NewSource(1))
|
||||
// Because we're using a random number generator, we need these to go in
|
||||
// a predictable sequence:
|
||||
assert.NoError(t, runt(`{{ shuffle "Hello World" }}`, "rldo HWlloe"))
|
||||
}
|
||||
|
||||
// runt runs a template and checks that the output exactly matches the expected string.
|
||||
func runt(tpl, expect string) error {
|
||||
return runtv(tpl, expect, map[string]string{})
|
||||
|
20
vendor/github.com/Masterminds/sprig/glide.lock
generated
vendored
20
vendor/github.com/Masterminds/sprig/glide.lock
generated
vendored
@@ -1,14 +1,24 @@
|
||||
hash: c2d7cb87ff32a0aba767b90bff630c3e4c1ca9904fc72568414d20d79a41e70f
|
||||
updated: 2017-03-13T18:38:30.597881175-06:00
|
||||
hash: b9cc40bfd6dde74a94103b96700df1a9ab29a7fff5650216cf5a05f4fe72fb73
|
||||
updated: 2017-05-02T16:01:04.617727646-06:00
|
||||
imports:
|
||||
- name: github.com/aokoli/goutils
|
||||
version: 9c37978a95bd5c709a15883b6242714ea6709e64
|
||||
- name: github.com/huandu/xstrings
|
||||
version: 3959339b333561bf62a38b424fd41517c2c90f40
|
||||
- name: github.com/imdario/mergo
|
||||
version: 3e95a51e0639b4cf372f2ccf74c86749d747fbdc
|
||||
- name: github.com/Masterminds/goutils
|
||||
version: 45307ec16e3cd47cd841506c081f7afd8237d210
|
||||
- name: github.com/Masterminds/semver
|
||||
version: 59c29afe1a994eacb71c833025ca7acf874bb1da
|
||||
- name: github.com/satori/go.uuid
|
||||
version: 879c5887cd475cd7864858769793b2ceb0d44feb
|
||||
- name: github.com/stretchr/testify
|
||||
version: e3a8ff8ce36581f87a15341206f205b1da467059
|
||||
subpackages:
|
||||
- assert
|
||||
- name: golang.org/x/crypto
|
||||
version: 1f22c0103821b9390939b6776727195525381532
|
||||
version: d172538b2cfce0c13cee31e647d0367aa8cd2486
|
||||
subpackages:
|
||||
- pbkdf2
|
||||
- scrypt
|
||||
@@ -21,7 +31,3 @@ testImports:
|
||||
version: d8ed2627bdf02c080bf22230dbb337003b7aba2d
|
||||
subpackages:
|
||||
- difflib
|
||||
- name: github.com/stretchr/testify
|
||||
version: e3a8ff8ce36581f87a15341206f205b1da467059
|
||||
subpackages:
|
||||
- assert
|
||||
|
7
vendor/github.com/Masterminds/sprig/glide.yaml
generated
vendored
7
vendor/github.com/Masterminds/sprig/glide.yaml
generated
vendored
@@ -1,6 +1,7 @@
|
||||
package: github.com/Masterminds/sprig
|
||||
import:
|
||||
- package: github.com/aokoli/goutils
|
||||
- package: github.com/Masterminds/goutils
|
||||
version: ^1.0.0
|
||||
- package: github.com/satori/go.uuid
|
||||
version: ^1.1.0
|
||||
- package: golang.org/x/crypto
|
||||
@@ -8,3 +9,7 @@ import:
|
||||
- scrypt
|
||||
- package: github.com/Masterminds/semver
|
||||
version: v1.2.2
|
||||
- package: github.com/stretchr/testify
|
||||
- package: github.com/imdario/mergo
|
||||
version: ~0.2.2
|
||||
- package: github.com/huandu/xstrings
|
||||
|
Reference in New Issue
Block a user