sprig

Useful template functions for Go templates.

MIT License

Stars
4.3K
Committers
96
sprig - 2.13.0 Adds New Functions

Published by mattfarina about 7 years ago

This release adds new functions, including:

  • regexMatch, regexFindAll, regexFind, regexReplaceAll, regexReplaceAllLiteral, and regexSplit to work with regular expressions
  • floor, ceil, and round math functions
  • toDate converts a string to a date
  • nindent is just like indent but also prepends a new line
  • ago returns the time from time.Now

Changelog

Added

  • #40: Added basic regex functionality (thanks @alanquillin)
  • #41: Added ceil floor and round functions (thanks @alanquillin)
  • #48: Added toDate function (thanks @andreynering)
  • #50: Added nindent function (thanks @binoculars)
  • #46: Added ago function (thanks @slayer)

Changed

  • #51: Updated godocs to include new string functions (thanks @curtisallen)
  • #49: Added ability to merge multiple dicts (thanks @binoculars)
sprig - New functions

Published by technosophos over 7 years ago

This release adds several new functions:

  • snakecase, camelcase, and shuffle are three new string functions
  • fail allows you to bail out of a template render when conditions are not met

Changelog

  • Fix links to other markdown docs. 967ad1c93844d1c124a1fdd11e326598c8e0aca5 (Chance Zibolski)
  • Add fail function 3ca3f10200798a630f599982452822bce780331e (Kent Rancourt)
  • Fix minor indentation issues 4776d725fbd3e7dbc33207a421dd27c02ef6f4fe (Luk Burchard)
  • Update glide with new dependencies f5b0ed4a680a0943228155eaf6a77a96ead1bc77 (Matt Butcher)
  • Add 'snakecase', 'camelcase' and 'shuffle' c032c8f5cf387d908b2423816eba0c7284d45c48 (Manfred Touron)
  • Updated documentation on merge. eddf742c44c1b2fc4dc23dc22d3a19afc6579072 (Matt Butcher)
sprig - Two Dozen New Functions!

Published by technosophos over 7 years ago

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 and semverCompare were added by popular demand.
  • list replaces tuple
  • 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. 23597e5f6ad0e4d590e71314bfd0251a4a3cf849 (Matt Butcher)
Add without and has functions. 1f3c30139e7139a65b5d6b7f31284d401e5e2487 (Matt Butcher)
Add uniq function. a1c06b6a55acfde86a11947008b0393960879665 (Matt Butcher)
Only install glide during 'make setup' if not already installed. 586619b4e928bd3cca0a46dac8ac6f2c003fd66a (Matt Butcher)
Add setup target to makefile 5db91714c3ebb01eabc8ae26b7d584d6a01c1d30 (Matt Butcher)
Clone the generic map instead of acting directly on it. 10f3ff00763f71fc0a79e770031724db83675929 (Matt Butcher)
Refactor into multiple files. 9e5d6d81df8c6208941133daaba1134065a477e8 (Matt Butcher)
Add pick and omit functions. 44e3642c7dc1354ad15c53fbe4374af4878e765c (Matt Butcher)
Add keys function. 427e90187e0902bc04b64167610f2da7ba26e0e1 (Matt Butcher)
Add 'compact' function. 2009c2546db608c737012557c9d3e836468f0423 (Matt Butcher)
Add 'pluck' function df7a54437d02c7efc12aeb9a44227ca1ae76f861 (Matt Butcher)
Add reverse and coalesce functions. 73a59523c1a8202c02786c296731ef5ce1832ddc (Matt Butcher)
Add toString, toStrings, and sortAlpha. df3624ede7d0c68697394da73bf4434bdfce4d3c (Matt Butcher)
Add list, first, last, initial, rest, prepend, and append. 3e101afd8a97715f7e0dbd41c9988ad6fcaa2d19 (Matt Butcher)
Allow 'join' to take other array/slice types. 713da5382fb1da2b725160e68c0735d3cd196be5 (Matt Butcher)

sprig - 2.8.0 adds path functions and dictionary management

Published by technosophos almost 8 years ago

This release adds two new sets of functions:

  • First, it provides access to several path functions (base, dir, clean, ext, and abs)
  • Second, it adds functions for mutating dictionaries (set, unset, hasKey)
sprig - UUIDv4 Function

Published by technosophos about 8 years ago

This release adds a uuidv4 template function for generating UUIDs inside of a template.

sprig - New trimSuffix, trimPrefix, hasSuffix, and hasPrefix functions

Published by technosophos about 8 years ago

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.

sprig - Add until and untilStep

Published by technosophos about 8 years ago

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
sprig - Add cat, replace, plural, and indent functions

Published by technosophos over 8 years ago

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.
sprig - Add genPrivateKey

Published by technosophos over 8 years ago

Experimenting with some new crypto functions for orchestration tasks, we've added a genPrivateKey function. Thanks to @bacongobbler for the pull request.

sprig - Improve 'default', add example, and add hermetic functions

Published by technosophos over 8 years ago

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.
sprig - min, empty, tuple, dict, more date functions, and better math

Published by technosophos over 8 years ago

This release adds a number of new functions:

  • min complements max (formerly biggest)
  • empty indicates that a value is the empty value for its type
  • tuple 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 (via strconv.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.

sprig - New functions, varargs

Published by technosophos over 8 years ago

This release features a few improvements.

  • Added quote and squote functions for quoting strings.
  • Addedb32enc and b32dec for Base32 encoding and decoding.
  • add now takes varargs: {{ add 1 2 3 }}
  • biggest now takes varargs: {{ biggest 5 6 4 }}
  • README is updated

Our tests indicate that making functions variadic seems to be backward compatible, but we're only doing a few this release in case there are some use cases we hadn't thought of.

sprig - Release 1.1.0

Published by mattfarina almost 9 years ago

  • Added #4: Added contains function. strings.Contains, but with the arguments switched to simplify common pipelines.
  • Added Travis-CI testing support