Releases: Masterminds/sprig
New functions
This release adds several new functions:
snakecase
,camelcase
, andshuffle
are three new string functionsfail
allows you to bail out of a template render when conditions are not met
Changelog
- Fix links to other markdown docs. 967ad1c (Chance Zibolski)
- Add fail function 3ca3f10 (Kent Rancourt)
- Fix minor indentation issues 4776d72 (Luk Burchard)
- Update glide with new dependencies f5b0ed4 (Matt Butcher)
- Add 'snakecase', 'camelcase' and 'shuffle' c032c8f (Manfred Touron)
- Updated documentation on merge. eddf742 (Matt Butcher)
Two Dozen New Functions!
Inspired by the utility library underscore.js, we've added a bunch of new utility functions to Sprig. Many of these are designed to work on dict
and list
types (and for the time being, on tuple
as well).
Highlights:
semver
andsemverCompare
were added by popular demand.list
replacestuple
join
was fixed- Added:
- first
- last
- intial
- rest
- prepend
- append
- toString
- toStrings
- sortAlpha
- reverse
- coalesce
- pluck
- pick
- compact
- keys
- omit
- uniq
- has
- without
Complete changes:
Add semver and semverCompare. 23597e5 (Matt Butcher)
Add without and has functions. 1f3c301 (Matt Butcher)
Add uniq function. a1c06b6 (Matt Butcher)
Only install glide during 'make setup' if not already installed. 586619b (Matt Butcher)
Add setup target to makefile 5db9171 (Matt Butcher)
Clone the generic map instead of acting directly on it. 10f3ff0 (Matt Butcher)
Refactor into multiple files. 9e5d6d8 (Matt Butcher)
Add pick and omit functions. 44e3642 (Matt Butcher)
Add keys function. 427e901 (Matt Butcher)
Add 'compact' function. 2009c25 (Matt Butcher)
Add 'pluck' function df7a544 (Matt Butcher)
Add reverse and coalesce functions. 73a5952 (Matt Butcher)
Add toString, toStrings, and sortAlpha. df3624e (Matt Butcher)
Add list, first, last, initial, rest, prepend, and append. 3e101af (Matt Butcher)
Allow 'join' to take other array/slice types. 713da53 (Matt Butcher)
2.8.0 adds path functions and dictionary management
This release adds two new sets of functions:
- First, it provides access to several path functions (
base
,dir
,clean
,ext
, andabs
) - Second, it adds functions for mutating dictionaries (
set
,unset
,hasKey
)
UUIDv4 Function
This release adds a uuidv4
template function for generating UUIDs inside of a template.
New trimSuffix, trimPrefix, hasSuffix, and hasPrefix functions
Four new functions from the strings
package have been exposed as template functions. Following established conventions, we've reversed the order of parameters to better suite template usage:
{{"$5.00" | trimPrefix "$"}}
Additionally, new aliases have been added for a few functions that didn't follow the naming conventions. There is now a trimAll
(used in preference to trimall
) and abbrevBoth
(in preference to abbrevboth
).
At the 3.0 release (whenever that happens), trimall
and abbrevboth
will be removed.
Add until and untilStep
This release adds two functions: until
and untilStep
. These functions generate integer slices. They are designed to be used for iteration:
{{range $i, $val := until 5}}{{end}}
In the above, $i
is the index, and $val
is the value. Both will iterate from 0
to 4
.
For more control, you may use untilStep
. The above can be replicated exactly:
{{range $i, $val := until 0 5 1}}{{end}}
untilStep
takes three arguments: untilStep $start $end $step
:
$start
: The starting value$end
: The end value$step
: The increment value
Here's an example that will produce even numbers less than 10:
{{range $i, $val := until 0 10 2}}
{{$val}}
{{end}}
The above will produce
0
2
4
6
8
Add cat, replace, plural, and indent functions
New functions:
- cat: Concatenate strings with whitespace separators.
- replace: Replace parts of a string:
replace " " "-" "Me First"
renders "Me-First" - plural: Format plurals:
len "foo" | plural "one foo" "many foos"
renders "many foos" - indent: Indent blocks of text in a way that is sensitive to "\n" characters.
Add genPrivateKey
Experimenting with some new crypto functions for orchestration tasks, we've added a genPrivateKey function. Thanks to @bacongobbler for the pull request.
Improve 'default', add example, and add hermetic functions
This release adds the following:
default
now prints the default value when it does not receive a value down the pipeline. It is much safer now to do{{.Foo | default "bar"}}
.- Added accessors for "hermetic" functions. These return only functions that, when given the same input, produce the same output.
min, empty, tuple, dict, more date functions, and better math
This release adds a number of new functions:
min
complementsmax
(formerlybiggest
)empty
indicates that a value is the empty value for its typetuple
creates a tuple inside of a template:{{$t := tuple "a", "b" "c"}}
dict
creates a dictionary inside of a template{{$d := dict "key1" "val1" "key2" "val2"}}
- Date formatters have been added for HTML dates (as used in
date
input fields) - Integer math functions can convert from a number of types, including
string
(viastrconv.ParseInt
).
Because we switched from int
to int64
as the return value for all integer math functions, the library's major version number has been incremented.