From 4b6aa245bd23d65e37f74c0404044ddf63a53b55 Mon Sep 17 00:00:00 2001 From: Marcin Maciaszczyk Date: Mon, 23 Sep 2024 17:09:27 +0200 Subject: [PATCH] feat: Document Liquid template functions (#35) * add method to return registered filters info * fix condition * add make target to generate docs * add docs * add more docs * add fixme * add docs to result * update struct * add more docs * save to file * move docs * update docs * update docs * update docs * add missing quote mark * extract functions * add check if docs are up-to-date * update docs * point to make target * update dependencies * escape new line char * remove duplicated import * remove unused file --- Makefile | 5 +- docs/liquid-filters.md | 1457 ++++++++++++++++++++++++++++++++ go.mod | 28 +- go.sum | 92 +- internal/template/docs.go | 51 ++ internal/template/docs_test.go | 19 + template/liquid.go | 58 +- template/liquid_docs.go | 212 +++++ template/liquid_test.go | 14 + test/_simple.tpl | 1 - 10 files changed, 1846 insertions(+), 91 deletions(-) create mode 100644 docs/liquid-filters.md create mode 100644 internal/template/docs.go create mode 100644 internal/template/docs_test.go create mode 100644 template/liquid_docs.go create mode 100644 template/liquid_test.go delete mode 100644 test/_simple.tpl diff --git a/Makefile b/Makefile index 5e969cb..1c1d53d 100644 --- a/Makefile +++ b/Makefile @@ -17,4 +17,7 @@ release-vsn: # tags and pushes a new release git checkout main; \ git pull --rebase; \ git tag -a $$tag -m "new release"; \ - git push origin $$tag \ No newline at end of file + git push origin $$tag + +gen-docs: # generates docs for registered liquid template functions + go run github.com/pluralsh/polly/internal/template \ No newline at end of file diff --git a/docs/liquid-filters.md b/docs/liquid-filters.md new file mode 100644 index 0000000..e4cf370 --- /dev/null +++ b/docs/liquid-filters.md @@ -0,0 +1,1457 @@ +# Supported Liquid Filters + +## abbrev + + + + +_Implementation_: github.com/Masterminds/sprig/v3.abbrev + +## abbrevboth + + + + +_Implementation_: github.com/Masterminds/sprig/v3.abbrevboth + +## add +Sums numbers. Accepts two or more inputs. `add 1 2 3` will return `6`. + + + +_Implementation_: github.com/Masterminds/sprig/v3.init.func15 + +## add1 +Increments by 1. `add1 3` will return `4`. + + + +_Implementation_: github.com/Masterminds/sprig/v3.init.func14 + +## add1f +Increments float number by 1. + + + +_Implementation_: github.com/Masterminds/sprig/v3.init.func21 + +## addf +Sums float numbers. + + + +_Implementation_: github.com/Masterminds/sprig/v3.init.func22 + +## adler32sum +Receives a string and computes its Adler-32 checksum. + + + +_Implementation_: github.com/Masterminds/sprig/v3.adler32sum + +## ago +Returns duration from current time in seconds resolution. + + + +_Implementation_: github.com/Masterminds/sprig/v3.dateAgo + +## all +Takes a list of values ad returns true if all values are non-empty. + + + +_Implementation_: github.com/Masterminds/sprig/v3.all + +## any +Takes a list of values ad returns true if any values are non-empty. + + + +_Implementation_: github.com/Masterminds/sprig/v3.any + +## append +Appends a new item to existing list, creating a new list. + + + +_Implementation_: github.com/Masterminds/sprig/v3.push + +## atoi +Converts a string to an integer. + + + +_Implementation_: github.com/Masterminds/sprig/v3.init.func12 + +## b32dec +Decodes string from Base32 format. + + + +_Implementation_: github.com/Masterminds/sprig/v3.base32decode + +## b32enc +Encodes string with Base32 format. + + + +_Implementation_: github.com/Masterminds/sprig/v3.base32encode + +## b64dec +Decodes string from Base64 format. + + + +_Implementation_: github.com/Masterminds/sprig/v3.base64decode + +## b64enc +Encodes string with Base64 format. + + + +_Implementation_: github.com/Masterminds/sprig/v3.base64encode + +## base + + + + +_Implementation_: path.Base + +## bcrypt +Receives a string and generates its bcrypt hash. + + + +_Implementation_: github.com/Masterminds/sprig/v3.bcrypt + +## biggest + + + + +_Implementation_: github.com/Masterminds/sprig/v3.max + +## buildCustomCert +Allows customizing the certificate. It takes Base64 encoded PEM format certificate and private key as arguments and returns object with PEM-encoded certificate and key. Note that the returned object can be passed to the `genSignedCert` function to sign a certificate using this CA. + + + +_Implementation_: github.com/Masterminds/sprig/v3.buildCustomCertificate + +## camelcase + + + + +_Implementation_: github.com/huandu/xstrings.ToPascalCase + +## cat + + + + +_Implementation_: github.com/Masterminds/sprig/v3.cat + +## ceil +Returns greatest float value greater than or equal to input value. `ceil 123.001` will return `124.0`. + + + +_Implementation_: github.com/Masterminds/sprig/v3.ceil + +## chunk + + + + +_Implementation_: github.com/Masterminds/sprig/v3.chunk + +## clean + + + + +_Implementation_: path.Clean + +## coalesce + + + + +_Implementation_: github.com/Masterminds/sprig/v3.coalesce + +## compact +Accepts a list and removes entries with empty values. + + + +_Implementation_: github.com/Masterminds/sprig/v3.compact + +## concat +Concatenates arbitrary number of lists into one. + + + +_Implementation_: github.com/Masterminds/sprig/v3.concat + +## contains +Tests if one string is contained inside of another. `contains "cat" "catch"` will return `true`. + + + +_Implementation_: github.com/Masterminds/sprig/v3.init.func9 + +## date +Formats date. + + + +_Implementation_: github.com/Masterminds/sprig/v3.date + +## dateInZone +Same as `date` but with a timezone. + + + +_Implementation_: github.com/Masterminds/sprig/v3.dateInZone + +## dateModify + + + + +_Implementation_: github.com/Masterminds/sprig/v3.dateModify + +## date_in_zone + + + + +_Implementation_: github.com/Masterminds/sprig/v3.dateInZone + +## date_modify + + + + +_Implementation_: github.com/Masterminds/sprig/v3.dateModify + +## decryptAES +Receives a Base64 string encoded by the AES-256 CBC algorithm and returns the decoded text. + + + +_Implementation_: github.com/Masterminds/sprig/v3.decryptAES + +## deepCopy + + + + +_Implementation_: github.com/Masterminds/sprig/v3.deepCopy + +## deepEqual + + + + +_Implementation_: reflect.DeepEqual + +## default + + + + +_Implementation_: github.com/pluralsh/polly/template.dfault + +## derivePassword + + + + +_Implementation_: github.com/Masterminds/sprig/v3.derivePassword + +## dict + + + + +_Implementation_: github.com/Masterminds/sprig/v3.dict + +## dig + + + + +_Implementation_: github.com/Masterminds/sprig/v3.dig + +## dir + + + + +_Implementation_: path.Dir + +## div +Performs integer division. + + + +_Implementation_: github.com/Masterminds/sprig/v3.init.func17 + +## divf + + + + +_Implementation_: github.com/Masterminds/sprig/v3.init.func24 + +## duration +Formats a given amount of seconds as a `time.Duration`. + + + +_Implementation_: github.com/Masterminds/sprig/v3.duration + +## durationRound + + + + +_Implementation_: github.com/Masterminds/sprig/v3.durationRound + +## empty + + + + +_Implementation_: github.com/Masterminds/sprig/v3.empty + +## encryptAES +Encrypts text with AES-256 CBC and returns a Base64 encoded string. + + + +_Implementation_: github.com/Masterminds/sprig/v3.encryptAES + +## env +Reads environment variable. + + + +_Implementation_: os.Getenv + +## expandenv +Substitutes environment variable in a string. + + + +_Implementation_: os.ExpandEnv + +## ext +Returns file extension. `ext "foo.bar"` will return `"bar"`. + + + +_Implementation_: path.Ext + +## 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. + + + +_Implementation_: github.com/Masterminds/sprig/v3.init.func26 + +## first +Returns head item on a list. + + + +_Implementation_: github.com/Masterminds/sprig/v3.first + +## float64 +Converts to a `float64`. + + + +_Implementation_: github.com/Masterminds/sprig/v3.toFloat64 + +## floor +Returns the greatest float value greater than or equal to input value. `floor 123.9999` will return `123.0`. + + + +_Implementation_: github.com/Masterminds/sprig/v3.floor + +## fromJson + + +_Aliases_: from_json + +_Implementation_: github.com/Masterminds/sprig/v3.fromJson + +## genCA +Generates a new, self-signed x509 SSL Certificate Authority using 2048-bit RSA private key. It takes subject common name (CN) and cert validity duration in days as parameters. It returns object with PEM-encoded certificate and key. Note that the returned object can be passed to the `genSignedCert` function to sign a certificate using this CA. + + + +_Implementation_: github.com/Masterminds/sprig/v3.generateCertificateAuthority + +## genCAWithKey +Generates a new, self-signed x509 SSL Certificate Authority using given private key. It takes subject common name (CN), cert validity duration in days and private key (PEM-encoded; DSA keys are not supported) as parameters. It returns object with PEM-encoded certificate and key. Note that the returned object can be passed to the `genSignedCert` function to sign a certificate using this CA. + + + +_Implementation_: github.com/Masterminds/sprig/v3.generateCertificateAuthorityWithPEMKey + +## genPrivateKey + + + + +_Implementation_: github.com/Masterminds/sprig/v3.generatePrivateKey + +## genSelfSignedCert +Generates an SSL self-signed certificate. + + + +_Implementation_: github.com/Masterminds/sprig/v3.generateSelfSignedCertificate + +## genSelfSignedCertWithKey + + + + +_Implementation_: github.com/Masterminds/sprig/v3.generateSelfSignedCertificateWithPEMKey + +## genSignedCert +Generates an SSL certificate and key based on a given CA. + + + +_Implementation_: github.com/Masterminds/sprig/v3.generateSignedCertificate + +## genSignedCertWithKey + + + + +_Implementation_: github.com/Masterminds/sprig/v3.generateSignedCertificateWithPEMKey + +## get + + + + +_Implementation_: github.com/Masterminds/sprig/v3.get + +## getHostByName + + + + +_Implementation_: github.com/Masterminds/sprig/v3.getHostByName + +## has +Checks if a list has a particular element. + + + +_Implementation_: github.com/Masterminds/sprig/v3.has + +## hasKey + + + + +_Implementation_: github.com/Masterminds/sprig/v3.hasKey + +## hasPrefix + + + + +_Implementation_: github.com/Masterminds/sprig/v3.init.func10 + +## hasSuffix + + + + +_Implementation_: github.com/Masterminds/sprig/v3.init.func11 + +## htmlDate +Formats a date for inserting into HTML date picker input field. + + + +_Implementation_: github.com/Masterminds/sprig/v3.htmlDate + +## htmlDateInZone +Same as `htmlDate` but with a timezone. + + + +_Implementation_: github.com/Masterminds/sprig/v3.htmlDateInZone + +## htpasswd + + + + +_Implementation_: github.com/Masterminds/sprig/v3.htpasswd + +## indent + + + + +_Implementation_: github.com/pluralsh/polly/template.indent + +## initial +Compliments `last` by retuning all but the last element. + + + +_Implementation_: github.com/Masterminds/sprig/v3.initial + +## initials + + + + +_Implementation_: github.com/Masterminds/sprig/v3.initials + +## int +Converts to a `int`. + + + +_Implementation_: github.com/Masterminds/sprig/v3.toInt + +## int64 +Converts to a `int64`. + + + +_Implementation_: github.com/Masterminds/sprig/v3.toInt64 + +## isAbs +Checks whether a path is absolute. + + + +_Implementation_: path.IsAbs + +## join + + + + +_Implementation_: github.com/Masterminds/sprig/v3.join + +## kebabcase + + + + +_Implementation_: github.com/huandu/xstrings.ToKebabCase + +## keys + + + + +_Implementation_: github.com/Masterminds/sprig/v3.keys + +## kindIs + + + + +_Implementation_: github.com/Masterminds/sprig/v3.kindIs + +## kindOf + + + + +_Implementation_: github.com/Masterminds/sprig/v3.kindOf + +## last + + + + +_Implementation_: github.com/Masterminds/sprig/v3.last + +## list + + + + +_Implementation_: github.com/Masterminds/sprig/v3.list + +## lower +Converts the entire string to lowercase. `upper "HELLO"` will return `hello`. + + + +_Implementation_: strings.ToLower + +## max +Returns the largest of a series of integers. `max 1 2 3` will return `3`. + + + +_Implementation_: github.com/Masterminds/sprig/v3.max + +## maxf + + + + +_Implementation_: github.com/Masterminds/sprig/v3.maxf + +## merge + + + + +_Implementation_: github.com/Masterminds/sprig/v3.merge + +## mergeOverwrite + + + + +_Implementation_: github.com/Masterminds/sprig/v3.mergeOverwrite + +## min +Returns the smallest of a series of integers. `min 1 2 3` will return `1`. + + + +_Implementation_: github.com/Masterminds/sprig/v3.min + +## minf + + + + +_Implementation_: github.com/Masterminds/sprig/v3.minf + +## mod + + + + +_Implementation_: github.com/Masterminds/sprig/v3.init.func18 + +## mul +Multiples numbers. Accepts two or more inputs. `mul 1 2 3` will return `6`. + + + +_Implementation_: github.com/Masterminds/sprig/v3.init.func19 + +## mulf + + + + +_Implementation_: github.com/Masterminds/sprig/v3.init.func25 + +## mustAppend +Appends a new item to existing list, creating a new list. Like other `must` functions instead of panicking when there is a problem it will return an error to the template engine. + + + +_Implementation_: github.com/Masterminds/sprig/v3.mustPush + +## mustChunk + + + + +_Implementation_: github.com/Masterminds/sprig/v3.mustChunk + +## mustCompact +Accepts a list and removes entries with empty values. Like other `must` functions instead of panicking when there is a problem it will return an error to the template engine. + + + +_Implementation_: github.com/Masterminds/sprig/v3.mustCompact + +## mustDateModify + + + + +_Implementation_: github.com/Masterminds/sprig/v3.mustDateModify + +## mustDeepCopy + + + + +_Implementation_: github.com/Masterminds/sprig/v3.mustDeepCopy + +## mustFirst +Returns head item on a list. Like other `must` functions instead of panicking when there is a problem it will return an error to the template engine. + + + +_Implementation_: github.com/Masterminds/sprig/v3.mustFirst + +## mustFromJson + + + + +_Implementation_: github.com/Masterminds/sprig/v3.mustFromJson + +## mustHas +Checks if a list has a particular element. Like other `must` functions instead of panicking when there is a problem it will return an error to the template engine. + + + +_Implementation_: github.com/Masterminds/sprig/v3.mustHas + +## mustInitial +Compliments `last` by retuning all but the last element. Like other `must` functions instead of panicking when there is a problem it will return an error to the template engine. + + + +_Implementation_: github.com/Masterminds/sprig/v3.mustInitial + +## mustLast + + + + +_Implementation_: github.com/Masterminds/sprig/v3.mustLast + +## mustMerge + + + + +_Implementation_: github.com/Masterminds/sprig/v3.mustMerge + +## mustMergeOverwrite + + + + +_Implementation_: github.com/Masterminds/sprig/v3.mustMergeOverwrite + +## mustPrepend + + + + +_Implementation_: github.com/Masterminds/sprig/v3.mustPrepend + +## mustPush + + + + +_Implementation_: github.com/Masterminds/sprig/v3.mustPush + +## mustRegexFind + + + + +_Implementation_: github.com/Masterminds/sprig/v3.mustRegexFind + +## mustRegexFindAll + + + + +_Implementation_: github.com/Masterminds/sprig/v3.mustRegexFindAll + +## mustRegexMatch + + + + +_Implementation_: github.com/Masterminds/sprig/v3.mustRegexMatch + +## mustRegexReplaceAll + + + + +_Implementation_: github.com/Masterminds/sprig/v3.mustRegexReplaceAll + +## mustRegexReplaceAllLiteral + + + + +_Implementation_: github.com/Masterminds/sprig/v3.mustRegexReplaceAllLiteral + +## mustRegexSplit + + + + +_Implementation_: github.com/Masterminds/sprig/v3.mustRegexSplit + +## mustRest +Gets tail of the list (everything but the first item). Like other `must` functions instead of panicking when there is a problem it will return an error to the template engine. + + + +_Implementation_: github.com/Masterminds/sprig/v3.mustRest + +## mustReverse +Produces a new list with the reversed elements of the given list. Like other `must` functions instead of panicking when there is a problem it will return an error to the template engine. + + + +_Implementation_: github.com/Masterminds/sprig/v3.mustReverse + +## mustSlice + + + + +_Implementation_: github.com/Masterminds/sprig/v3.mustSlice + +## mustToDate +Converts a string to a date. The first argument is the date layout and the second is the date string. If the string can’t be converted it returns the zero value. Like other `must` functions instead of panicking when there is a problem it will return an error to the template engine. + + + +_Implementation_: github.com/Masterminds/sprig/v3.mustToDate + +## mustToJson + + + + +_Implementation_: github.com/Masterminds/sprig/v3.mustToJson + +## mustToPrettyJson + + + + +_Implementation_: github.com/Masterminds/sprig/v3.mustToPrettyJson + +## mustToRawJson + + + + +_Implementation_: github.com/Masterminds/sprig/v3.mustToRawJson + +## mustUniq +Generates a list with all of the duplicates removed. Like other `must` functions instead of panicking when there is a problem it will return an error to the template engine. + + + +_Implementation_: github.com/Masterminds/sprig/v3.mustUniq + +## mustWithout +Filters items out of a list. Like other `must` functions instead of panicking when there is a problem it will return an error to the template engine. + + + +_Implementation_: github.com/Masterminds/sprig/v3.mustWithout + +## must_date_modify + + + + +_Implementation_: github.com/Masterminds/sprig/v3.mustDateModify + +## nindent + + + + +_Implementation_: github.com/pluralsh/polly/template.nindent + +## nospace +Removes all whitespace from a string. `nospace "hello w o r l d"` will return `helloworld`. + + + +_Implementation_: github.com/Masterminds/goutils.DeleteWhiteSpace + +## omit + + + + +_Implementation_: github.com/Masterminds/sprig/v3.omit + +## osBase +Returns the last element of a file path. `osBase "/foo/bar/baz"` and `osBase "C:\\foo\\bar\\baz"` will return `"baz"` on Linux and Windows, respectively. + + + +_Implementation_: path/filepath.Base + +## osClean +Cleans up a path. `osClean "/foo/bar/../baz"` and `osClean "C:\\foo\\bar\\..\\baz"` will resolve the `..` and return `foo/baz` on Linux and `C:\foo\baz` on Windows. + + + +_Implementation_: path/filepath.Clean + +## osDir +Returns the directory, stripping the last part of the path. So `osDir "/foo/bar/baz"` returns `/foo/bar` on Linux, and `osDir "C:\\foo\\bar\\baz"` returns `C:\\foo\\bar` on Windows. + + + +_Implementation_: path/filepath.Dir + +## osExt +Return the file extension. `osExt "/foo.bar"` and `osExt "C:\\foo.bar"` will return `.bar` on Linux and Windows, respectively. + + + +_Implementation_: path/filepath.Ext + +## osIsAbs +Checks whether a file path is absolute. + + + +_Implementation_: path/filepath.IsAbs + +## pick + + + + +_Implementation_: github.com/Masterminds/sprig/v3.pick + +## pluck + + + + +_Implementation_: github.com/Masterminds/sprig/v3.pluck + +## plural + + + + +_Implementation_: github.com/Masterminds/sprig/v3.plural + +## prepend + + + + +_Implementation_: github.com/Masterminds/sprig/v3.prepend + +## push + + + + +_Implementation_: github.com/Masterminds/sprig/v3.push + +## quote + + + + +_Implementation_: github.com/Masterminds/sprig/v3.quote + +## randAlpha + + + + +_Implementation_: github.com/Masterminds/sprig/v3.randAlpha + +## randAlphaNum + + + + +_Implementation_: github.com/Masterminds/sprig/v3.randAlphaNumeric + +## randAscii + + + + +_Implementation_: github.com/Masterminds/sprig/v3.randAscii + +## randBytes +Accepts a count `N` and generates cryptographically secure random sequence of `N` bytes. The sequence is returned as a Base64 encoded string. + + + +_Implementation_: github.com/Masterminds/sprig/v3.randBytes + +## randInt +Returns a random integer value from min (inclusive) to max (exclusive). `randInt 12 30` will produce a random number in the range from 12 to 30. + + + +_Implementation_: github.com/Masterminds/sprig/v3.init.func20 + +## randNumeric + + + + +_Implementation_: github.com/Masterminds/sprig/v3.randNumeric + +## regexFind + + + + +_Implementation_: github.com/Masterminds/sprig/v3.regexFind + +## regexFindAll + + + + +_Implementation_: github.com/Masterminds/sprig/v3.regexFindAll + +## regexMatch + + + + +_Implementation_: github.com/Masterminds/sprig/v3.regexMatch + +## regexQuoteMeta + + + + +_Implementation_: github.com/Masterminds/sprig/v3.regexQuoteMeta + +## regexReplaceAll + + + + +_Implementation_: github.com/Masterminds/sprig/v3.regexReplaceAll + +## regexReplaceAllLiteral + + + + +_Implementation_: github.com/Masterminds/sprig/v3.regexReplaceAllLiteral + +## regexSplit + + + + +_Implementation_: github.com/Masterminds/sprig/v3.regexSplit + +## repeat + + + + +_Implementation_: github.com/Masterminds/sprig/v3.init.func2 + +## replace + + + + +_Implementation_: strings.ReplaceAll + +## rest +Gets tail of the list (everything but the first item). + + + +_Implementation_: github.com/Masterminds/sprig/v3.rest + +## reverse +Produces a new list with the reversed elements of the given list. + + + +_Implementation_: github.com/Masterminds/sprig/v3.reverse + +## round +Returns a float value with the remainder rounded to the given number to digits after the decimal point. `round 123.55555 3` will return `123.556`. + + + +_Implementation_: github.com/Masterminds/sprig/v3.round + +## semver + + + + +_Implementation_: github.com/Masterminds/sprig/v3.semver + +## semverCompare + + +_Aliases_: semver_compare + +_Implementation_: github.com/Masterminds/sprig/v3.semverCompare + +## seq +Works like Bash `seq` command. Specify 1 parameter (`end`) to generate all counting integers between 1 and `end` inclusive. Specify 2 parameters (`start` and `end`) to generate all counting integers between `start` and `end` inclusive incrementing or decrementing by 1. Specify 3 parameters (`start`, `step` and `end`) to generate all counting integers between `start` and `end` inclusive incrementing or decrementing by `step`. + + + +_Implementation_: github.com/Masterminds/sprig/v3.seq + +## set + + + + +_Implementation_: github.com/Masterminds/sprig/v3.set + +## sha1sum + + + + +_Implementation_: github.com/Masterminds/sprig/v3.sha1sum + +## sha256sum + + +_Aliases_: sha26sum + +_Implementation_: github.com/Masterminds/sprig/v3.sha256sum + +## sha512sum + + + + +_Implementation_: github.com/Masterminds/sprig/v3.sha512sum + +## shuffle + + + + +_Implementation_: github.com/huandu/xstrings.Shuffle + +## slice + + + + +_Implementation_: github.com/Masterminds/sprig/v3.slice + +## snakecase + + + + +_Implementation_: github.com/huandu/xstrings.ToSnakeCase + +## sortAlpha + + + + +_Implementation_: github.com/Masterminds/sprig/v3.sortAlpha + +## split + + + + +_Implementation_: github.com/Masterminds/sprig/v3.split + +## splitList + + + + +_Implementation_: github.com/Masterminds/sprig/v3.init.func13 + +## splitn + + + + +_Implementation_: github.com/Masterminds/sprig/v3.splitn + +## squote + + + + +_Implementation_: github.com/Masterminds/sprig/v3.squote + +## sub + + + + +_Implementation_: github.com/Masterminds/sprig/v3.init.func16 + +## subf + + + + +_Implementation_: github.com/Masterminds/sprig/v3.init.func23 + +## substr + + + + +_Implementation_: github.com/Masterminds/sprig/v3.substring + +## swapcase + + + + +_Implementation_: github.com/Masterminds/goutils.SwapCase + +## ternary +Takes two values and a test value. If the test value is true, the first value will be returned. If the test value is false, the second value will be returned. This is similar to the C ternary operator. `ternary "foo" "bar" true` or `true | "foo" "bar"` will return `"foo"`. + + + +_Implementation_: github.com/pluralsh/polly/template.ternary + +## title +Converts a string to title case. `title "hello world"` will return `"Hello World"`. + + + +_Implementation_: strings.Title + +## toDate +Converts a string to a date. The first argument is the date layout and the second is the date string. If the string can’t be converted it returns the zero value. + + + +_Implementation_: github.com/Masterminds/sprig/v3.toDate + +## toDecimal +Converts a Unix octal to a `int64`.`"0777" | toDecimal` will convert `0777` to `511` and return the value as `int64`. + + + +_Implementation_: github.com/Masterminds/sprig/v3.toDecimal + +## toJson + + +_Aliases_: to_json + +_Implementation_: github.com/Masterminds/sprig/v3.toJson + +## toPrettyJson + + + + +_Implementation_: github.com/Masterminds/sprig/v3.toPrettyJson + +## toRawJson +Encodes an item into JSON string with HTML characters unescaped. `toRawJson .Item` will return unescaped JSON string representation of `.Item`. + + + +_Implementation_: github.com/Masterminds/sprig/v3.toRawJson + +## toString +Converts to a string. + + + +_Implementation_: github.com/Masterminds/sprig/v3.strval + +## toStrings +Converts a list, slice or array to a list of strings. `list 1 2 3 | toString` converts `1`, `2` and `3` to strings and then returns them as a list. + + + +_Implementation_: github.com/Masterminds/sprig/v3.strslice + +## trim +Removes space from either side of a string. `trim " hello "` will return `hello`. + + + +_Implementation_: strings.TrimSpace + +## trimAll +Removes given characters from the front or back of a string. `trimAll "$" "$5.00"` will return `5.00` (as a string). + + + +_Implementation_: github.com/Masterminds/sprig/v3.init.func4 + +## trimPrefix +Trims just the prefix from a string. `trimPrefix "-" "-hello"` will return `hello`. + + + +_Implementation_: github.com/Masterminds/sprig/v3.init.func6 + +## trimSuffix +Trims just the suffix from a string. `trimSuffix "-" "hello-"` will return `hello`. + + + +_Implementation_: github.com/Masterminds/sprig/v3.init.func5 + +## trimall + + + + +_Implementation_: github.com/Masterminds/sprig/v3.init.func3 + +## trunc + + + + +_Implementation_: github.com/Masterminds/sprig/v3.trunc + +## tuple + + + + +_Implementation_: github.com/Masterminds/sprig/v3.list + +## typeIs + + + + +_Implementation_: github.com/Masterminds/sprig/v3.typeIs + +## typeIsLike + + + + +_Implementation_: github.com/Masterminds/sprig/v3.typeIsLike + +## typeOf + + + + +_Implementation_: github.com/Masterminds/sprig/v3.typeOf + +## uniq +Generates a list with all of the duplicates removed. + + + +_Implementation_: github.com/Masterminds/sprig/v3.uniq + +## unixEpoch +Returns the seconds since the Unix epoch. + + + +_Implementation_: github.com/Masterminds/sprig/v3.unixEpoch + +## unset +Given a map and a key it deletes the key from the map. It returns dictionary. Note that if the key is not found this operation will simply return. No error will be generated. + + + +_Implementation_: github.com/Masterminds/sprig/v3.unset + +## until +Builds a range of integers. `until 5` will return a list `[0, 1, 2, 3, 4]`. + + + +_Implementation_: github.com/Masterminds/sprig/v3.until + +## untilStep +Like `until` generates a list of counting integers but it allows to define a start, stop and step. `untilStep 3 6 2` will return `[3, 5]` by starting with 3 and adding 2 until it is equal or greater than 6. + + + +_Implementation_: github.com/Masterminds/sprig/v3.untilStep + +## untitle +Removes title casing. `untitle "Hello World"` will return `"hello world"`. + + + +_Implementation_: github.com/Masterminds/sprig/v3.untitle + +## upper +Converts the entire string to uppercase. `upper "hello"` will return `HELLO`. + + + +_Implementation_: strings.ToUpper + +## urlJoin +Joins map produced by `urlParse` to produce URL string. `urlJoin (dict "fragment" "fragment" "host" "host:80" "path" "/path" "query" "query" "scheme" "http")` will return `proto://host:80/path?query#fragment`. + + + +_Implementation_: github.com/Masterminds/sprig/v3.urlJoin + +## urlParse +Parses string for URL and produces dict with URL parts. For more info check https://golang.org/pkg/net/url/#URL. + + + +_Implementation_: github.com/Masterminds/sprig/v3.urlParse + +## values + + + + +_Implementation_: github.com/Masterminds/sprig/v3.values + +## without +Filters items out of a list. It can take more than one filter. + + + +_Implementation_: github.com/Masterminds/sprig/v3.without + +## wrap +Wraps text at a given column count. `wrap 80 $text` will wrap the string in `$text` at 80 columns. + + + +_Implementation_: github.com/Masterminds/sprig/v3.init.func7 + +## wrapWith +Works as `wrap` but lets you specify the string to wrap with (`wrap` uses `\n`). `wrapWith 5 "\t" "Hello world"` will return `hello world` (where the whitespace is an ASCII tab character). + + + +_Implementation_: github.com/Masterminds/sprig/v3.init.func8 diff --git a/go.mod b/go.mod index 4101d14..de82de3 100644 --- a/go.mod +++ b/go.mod @@ -1,30 +1,32 @@ module github.com/pluralsh/polly -go 1.19 +go 1.22.0 + +toolchain go1.23.0 require ( - github.com/Masterminds/sprig/v3 v3.2.3 + github.com/Masterminds/sprig/v3 v3.3.0 github.com/cenkalti/backoff v2.2.1+incompatible github.com/osteele/liquid v1.4.0 - github.com/samber/lo v1.33.0 + github.com/samber/lo v1.47.0 github.com/stretchr/testify v1.8.1 ) require ( + dario.cat/mergo v1.0.1 // indirect github.com/Masterminds/goutils v1.1.1 // indirect - github.com/Masterminds/semver/v3 v3.2.0 // indirect + github.com/Masterminds/semver/v3 v3.3.0 // indirect github.com/davecgh/go-spew v1.1.1 // indirect - github.com/google/uuid v1.1.1 // indirect - github.com/huandu/xstrings v1.3.3 // indirect - github.com/imdario/mergo v0.3.11 // indirect - github.com/mitchellh/copystructure v1.0.0 // indirect - github.com/mitchellh/reflectwalk v1.0.0 // indirect + github.com/google/uuid v1.6.0 // indirect + github.com/huandu/xstrings v1.5.0 // indirect + github.com/mitchellh/copystructure v1.2.0 // indirect + github.com/mitchellh/reflectwalk v1.0.2 // indirect github.com/osteele/tuesday v1.0.3 // indirect github.com/pmezard/go-difflib v1.0.0 // indirect - github.com/shopspring/decimal v1.2.0 // indirect - github.com/spf13/cast v1.3.1 // indirect - golang.org/x/crypto v0.3.0 // indirect - golang.org/x/exp v0.0.0-20220303212507-bbda1eaf7a17 // indirect + github.com/shopspring/decimal v1.4.0 // indirect + github.com/spf13/cast v1.7.0 // indirect + golang.org/x/crypto v0.27.0 // indirect + golang.org/x/text v0.18.0 // indirect gopkg.in/yaml.v2 v2.4.0 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect ) diff --git a/go.sum b/go.sum index f366dd4..5949204 100644 --- a/go.sum +++ b/go.sum @@ -1,83 +1,59 @@ +dario.cat/mergo v1.0.1 h1:Ra4+bf83h2ztPIQYNP99R6m+Y7KfnARDfID+a+vLl4s= +dario.cat/mergo v1.0.1/go.mod h1:uNxQE+84aUszobStD9th8a29P2fMDhsBdgRYvZOxGmk= github.com/Masterminds/goutils v1.1.1 h1:5nUrii3FMTL5diU80unEVvNevw1nH4+ZV4DSLVJLSYI= github.com/Masterminds/goutils v1.1.1/go.mod h1:8cTjp+g8YejhMuvIA5y2vz3BpJxksy863GQaJW2MFNU= -github.com/Masterminds/semver/v3 v3.2.0 h1:3MEsd0SM6jqZojhjLWWeBY+Kcjy9i6MQAeY7YgDP83g= -github.com/Masterminds/semver/v3 v3.2.0/go.mod h1:qvl/7zhW3nngYb5+80sSMF+FG2BjYrf8m9wsX0PNOMQ= -github.com/Masterminds/sprig/v3 v3.2.3 h1:eL2fZNezLomi0uOLqjQoN6BfsDD+fyLtgbJMAj9n6YA= -github.com/Masterminds/sprig/v3 v3.2.3/go.mod h1:rXcFaZ2zZbLRJv/xSysmlgIM1u11eBaRMhvYXJNkGuM= +github.com/Masterminds/semver/v3 v3.3.0 h1:B8LGeaivUe71a5qox1ICM/JLl0NqZSW5CHyL+hmvYS0= +github.com/Masterminds/semver/v3 v3.3.0/go.mod h1:4V+yj/TJE1HU9XfppCwVMZq3I84lprf4nC11bSS5beM= +github.com/Masterminds/sprig/v3 v3.3.0 h1:mQh0Yrg1XPo6vjYXgtf5OtijNAKJRNcTdOOGZe3tPhs= +github.com/Masterminds/sprig/v3 v3.3.0/go.mod h1:Zy1iXRYNqNLUolqCpL4uhk6SHUMAOSCzdgBfDb35Lz0= github.com/cenkalti/backoff v2.2.1+incompatible h1:tNowT99t7UNflLxfYYSlKYsBpXdEet03Pg2g16Swow4= github.com/cenkalti/backoff v2.2.1+incompatible/go.mod h1:90ReRw6GdpyfrHakVjL/QHaoyV4aDUVVkXQJJJ3NXXM= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/google/uuid v1.1.1 h1:Gkbcsh/GbpXz7lPftLA3P6TYMwjCLYm83jiFQZF/3gY= -github.com/google/uuid v1.1.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= -github.com/huandu/xstrings v1.3.3 h1:/Gcsuc1x8JVbJ9/rlye4xZnVAbEkGauT8lbebqcQws4= -github.com/huandu/xstrings v1.3.3/go.mod h1:y5/lhBue+AyNmUVz9RLU9xbLR0o4KIIExikq4ovT0aE= -github.com/imdario/mergo v0.3.11 h1:3tnifQM4i+fbajXKBHXWEH+KvNHqojZ778UH75j3bGA= -github.com/imdario/mergo v0.3.11/go.mod h1:jmQim1M+e3UYxmgPu/WyfjB3N3VflVyUjjjwH0dnCYA= +github.com/frankban/quicktest v1.14.6 h1:7Xjx+VpznH+oBnejlPUj8oUpdxnVs4f8XU8WnHkI4W8= +github.com/frankban/quicktest v1.14.6/go.mod h1:4ptaffx2x8+WTWXmUCuVU6aPUX1/Mz7zb5vbUoiM6w0= +github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI= +github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= +github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0= +github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= +github.com/huandu/xstrings v1.5.0 h1:2ag3IFq9ZDANvthTwTiqSSZLjDc+BedvHPAp5tJy2TI= +github.com/huandu/xstrings v1.5.0/go.mod h1:y5/lhBue+AyNmUVz9RLU9xbLR0o4KIIExikq4ovT0aE= +github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE= +github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk= github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= -github.com/mitchellh/copystructure v1.0.0 h1:Laisrj+bAB6b/yJwB5Bt3ITZhGJdqmxquMKeZ+mmkFQ= -github.com/mitchellh/copystructure v1.0.0/go.mod h1:SNtv71yrdKgLRyLFxmLdkAbkKEFWgYaq1OVrnRcwhnw= -github.com/mitchellh/reflectwalk v1.0.0 h1:9D+8oIskB4VJBN5SFlmc27fSlIBZaov1Wpk/IfikLNY= -github.com/mitchellh/reflectwalk v1.0.0/go.mod h1:mSTlrgnPZtwu0c4WaC2kGObEpuNDbx0jmZXqmk4esnw= -github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e h1:fD57ERR4JtEqsWbfPhv4DMiApHyliiK5xCTNVSPiaAs= +github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= +github.com/mitchellh/copystructure v1.2.0 h1:vpKXTN4ewci03Vljg/q9QvCGUDttBOGBIa15WveJJGw= +github.com/mitchellh/copystructure v1.2.0/go.mod h1:qLl+cE2AmVv+CoeAwDPye/v+N2HKCj9FbZEVFJRxO9s= +github.com/mitchellh/reflectwalk v1.0.2 h1:G2LzWKi524PWgd3mLHV8Y5k7s6XUvT0Gef6zxSIeXaQ= +github.com/mitchellh/reflectwalk v1.0.2/go.mod h1:mSTlrgnPZtwu0c4WaC2kGObEpuNDbx0jmZXqmk4esnw= github.com/osteele/liquid v1.4.0 h1:WS6lT3MFWUAxNbveF22tMLluOWNghGnKCZHLn7NbJGs= github.com/osteele/liquid v1.4.0/go.mod h1:VmzQQHa5v4E0GvGzqccfAfLgMwRk2V+s1QbxYx9dGak= github.com/osteele/tuesday v1.0.3 h1:SrCmo6sWwSgnvs1bivmXLvD7Ko9+aJvvkmDjB5G4FTU= github.com/osteele/tuesday v1.0.3/go.mod h1:pREKpE+L03UFuR+hiznj3q7j3qB1rUZ4XfKejwWFF2M= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= -github.com/samber/lo v1.33.0 h1:2aKucr+rQV6gHpY3bpeZu69uYoQOzVhGT3J22Op6Cjk= -github.com/samber/lo v1.33.0/go.mod h1:HLeWcJRRyLKp3+/XBJvOrerCQn9mhdKMHyd7IRlgeQ8= -github.com/shopspring/decimal v1.2.0 h1:abSATXmQEYyShuxI4/vyW3tV1MrKAJzCZ/0zLUXYbsQ= -github.com/shopspring/decimal v1.2.0/go.mod h1:DKyhrW/HYNuLGql+MJL6WCR6knT2jwCFRcu2hWCYk4o= -github.com/spf13/cast v1.3.1 h1:nFm6S0SMdyzrzcmThSipiEubIDy8WEXKNZ0UOgiRpng= -github.com/spf13/cast v1.3.1/go.mod h1:Qx5cxh0v+4UWYiBimWS+eyWzqEqokIECu5etghLkUJE= +github.com/rogpeppe/go-internal v1.9.0 h1:73kH8U+JUqXU8lRuOHeVHaa/SZPifC7BkcraZVejAe8= +github.com/rogpeppe/go-internal v1.9.0/go.mod h1:WtVeX8xhTBvf0smdhujwtBcq4Qrzq/fJaraNFVN+nFs= +github.com/samber/lo v1.47.0 h1:z7RynLwP5nbyRscyvcD043DWYoOcYRv3mV8lBeqOCLc= +github.com/samber/lo v1.47.0/go.mod h1:RmDH9Ct32Qy3gduHQuKJ3gW1fMHAnE/fAzQuf6He5cU= +github.com/shopspring/decimal v1.4.0 h1:bxl37RwXBklmTi0C79JfXCEBD1cqqHt0bbgBAGFp81k= +github.com/shopspring/decimal v1.4.0/go.mod h1:gawqmDU56v4yIKSwfBSFip1HdCCXN8/+DMd9qYNcwME= +github.com/spf13/cast v1.7.0 h1:ntdiHjuueXFgm5nzDRdOS4yfT43P5Fnud6DH50rz/7w= +github.com/spf13/cast v1.7.0/go.mod h1:ancEpBxwJDODSW/UG4rDrAqiKolqNNh2DX3mk86cAdo= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw= github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo= -github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= -github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA= github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= github.com/stretchr/testify v1.8.1 h1:w7B6lhMri9wdJUVmEZPGGhZzrYTPvgJArz7wNPgYKsk= github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4= -github.com/thoas/go-funk v0.9.1 h1:O549iLZqPpTUQ10ykd26sZhzD+rmR5pWhuElrhbC20M= -github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY= -golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= -golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= -golang.org/x/crypto v0.3.0 h1:a06MkbcxBrEFc0w0QIZWXrH/9cCX6KJyWbBOIwAn+7A= -golang.org/x/crypto v0.3.0/go.mod h1:hebNnKkNXi2UzZN1eVRvBB7co0a+JxK6XbPiWVs/3J4= -golang.org/x/exp v0.0.0-20220303212507-bbda1eaf7a17 h1:3MTrJm4PyNL9NBqvYDSj3DHl46qQakyfqfWo4jgfaEM= -golang.org/x/exp v0.0.0-20220303212507-bbda1eaf7a17/go.mod h1:lgLbSvA5ygNOMpwM/9anMpWVlVJ7Z+cHWq/eFuinpGE= -golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4= -golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= -golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= -golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c= -golang.org/x/net v0.2.0/go.mod h1:KqCZLdyyvdV855qA2rE3GC2aiw5xGR5TEjj8smXukLY= -golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= -golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.2.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= -golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= -golang.org/x/term v0.2.0/go.mod h1:TVmDHMZPmdnySmBfhjOoOdhjzdE1h4u1VwSiw2l1Nuc= -golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= -golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= -golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= -golang.org/x/text v0.4.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= -golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= -golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= -golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc= -golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +golang.org/x/crypto v0.27.0 h1:GXm2NjJrPaiv/h1tb2UH8QfgC/hOf/+z0p6PT8o1w7A= +golang.org/x/crypto v0.27.0/go.mod h1:1Xngt8kV6Dvbssa53Ziq6Eqn0HqbZi5Z6R0ZpwQzt70= +golang.org/x/text v0.18.0 h1:XvMDiNzPAl0jr17s6W9lcaIhGUfUORdGCNsuLmPG224= +golang.org/x/text v0.18.0/go.mod h1:BuEKDfySbSR4drPmRPG/7iBdf8hvFMuRexcpahXilzY= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= -gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f h1:BLraFXnmrev5lT+xlilqcH8XK9/i0At2xKjWk4p6zsU= -gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= -gopkg.in/yaml.v2 v2.3.0/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY= gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/internal/template/docs.go b/internal/template/docs.go new file mode 100644 index 0000000..f91a34b --- /dev/null +++ b/internal/template/docs.go @@ -0,0 +1,51 @@ +package main + +import ( + "io" + "os" + "sort" + "strings" + "text/template" + + "github.com/Masterminds/sprig/v3" + tmpl "github.com/pluralsh/polly/template" + "github.com/samber/lo" +) + +const ( + docsPath = "docs/liquid-filters.md" + docsTemplate = `# Supported Liquid Filters +{{ range . }} +## {{ .Name }} +{{ .Description }} + +{{ if .Aliases }}_Aliases_: {{ .Aliases | join ", " }}{{ end }} + +_Implementation_: {{ .Implementation }} +{{ end }}` +) + +func main() { + f, err := os.Create(docsPath) + if err != nil { + panic(err) + } + + if err = generateFilterDocs(f, registeredFilters()); err != nil { + panic(err) + } +} + +func registeredFilters() []tmpl.FilterFunction { + filters := lo.Values(tmpl.RegisteredFilters()) + sort.Slice(filters, func(i, j int) bool { + return strings.Compare(filters[i].Name, filters[j].Name) < 0 + }) + + return filters +} + +func generateFilterDocs(writer io.Writer, filters []tmpl.FilterFunction) error { + t := template.Must(template.New("").Funcs(sprig.TxtFuncMap()).Parse(docsTemplate)) + return t.Execute(writer, filters) +} diff --git a/internal/template/docs_test.go b/internal/template/docs_test.go new file mode 100644 index 0000000..ea96cd9 --- /dev/null +++ b/internal/template/docs_test.go @@ -0,0 +1,19 @@ +package main + +import ( + "bytes" + "os" + "testing" + + "github.com/stretchr/testify/assert" +) + +func TestLiquidFunctionDocs(t *testing.T) { + b := new(bytes.Buffer) + err := generateFilterDocs(b, registeredFilters()) + assert.NoError(t, err) + + f, err := os.ReadFile("../../docs/liquid-filters.md") + assert.NoError(t, err) + assert.Equal(t, b.String(), string(f), "docs are outdated, use `make gen-docs` to update them") +} diff --git a/template/liquid.go b/template/liquid.go index a7e93ba..64bf2bc 100644 --- a/template/liquid.go +++ b/template/liquid.go @@ -1,6 +1,8 @@ package template import ( + "reflect" + "runtime" "strings" "github.com/Masterminds/sprig/v3" @@ -8,6 +10,13 @@ import ( "github.com/samber/lo" ) +type FilterFunction struct { + Name string `json:"name"` + Aliases []string `json:"aliases,omitempty"` + Description string `json:"description,omitempty"` + Implementation string `json:"implementation,omitempty"` +} + var ( liquidEngine = liquid.NewEngine() @@ -15,11 +24,11 @@ var ( excludedSprigFunctions = []string{"hello", "now", "uuidv4"} // sprigFunctionNameAliases contains additional aliases for Sprig functions. - sprigFunctionNameAliases = map[string]string{ - "toJson": "to_json", - "fromJson": "from_json", - "semverCompare": "semver_compare", - "sha256sum": "sha26sum", + sprigFunctionNameAliases = map[string][]string{ + "toJson": {"to_json"}, + "fromJson": {"from_json"}, + "semverCompare": {"semver_compare"}, + "sha256sum": {"sha26sum"}, } // internalFunctions to register. These will override Sprig functions if same names are used. @@ -30,31 +39,44 @@ var ( "default": dfault, "ternary": ternary, } + + // registeredFunctions contains information about all registered template functions. + registeredFunctions = map[string]FilterFunction{} ) func init() { - fncs := sprig.TxtFuncMap() - - excludedFunctions := excludedSprigFunctions - for k := range internalFunctions { - excludedFunctions = append(excludedFunctions, k) + sprigFunctions := sprig.TxtFuncMap() + for name, fnc := range sprigFunctions { + _, hasInternalFunctionNameConflict := internalFunctions[name] + if !lo.Contains(excludedSprigFunctions, name) && !hasInternalFunctionNameConflict { + registerFilter(name, sprigFunctionNameAliases[name], fnc) + } } - for name, fnc := range fncs { - if !lo.Contains(excludedFunctions, name) { - liquidEngine.RegisterFilter(name, fnc) - } + for name, fnc := range internalFunctions { + registerFilter(name, nil, fnc) } +} + +func registerFilter(name string, aliases []string, fn any) { + liquidEngine.RegisterFilter(name, fn) - for key, name := range sprigFunctionNameAliases { - liquidEngine.RegisterFilter(name, fncs[key]) + for _, alias := range aliases { + liquidEngine.RegisterFilter(alias, fn) } - for name, fnc := range internalFunctions { - liquidEngine.RegisterFilter(name, fnc) + registeredFunctions[name] = FilterFunction{ + Name: name, + Aliases: aliases, + Description: functionDocs[name], + Implementation: runtime.FuncForPC(reflect.ValueOf(fn).Pointer()).Name(), } } +func RegisteredFilters() map[string]FilterFunction { + return registeredFunctions +} + func RenderLiquid(input []byte, bindings map[string]interface{}) ([]byte, error) { return liquidEngine.ParseAndRender(input, bindings) } diff --git a/template/liquid_docs.go b/template/liquid_docs.go new file mode 100644 index 0000000..6760ddf --- /dev/null +++ b/template/liquid_docs.go @@ -0,0 +1,212 @@ +package template + +var functionDocs = map[string]string{ + "abbrev": "", + "abbrevboth": "", + "add": "Sums numbers. Accepts two or more inputs. `add 1 2 3` will return `6`.", + "add1": "Increments by 1. `add1 3` will return `4`.", + "add1f": "Increments float number by 1.", + "addf": "Sums float numbers.", + "adler32sum": "Receives a string and computes its Adler-32 checksum.", + "ago": "Returns duration from current time in seconds resolution.", + "all": "Takes a list of values ad returns true if all values are non-empty.", + "any": "Takes a list of values ad returns true if any values are non-empty.", + "append": "Appends a new item to existing list, creating a new list.", + "atoi": "Converts a string to an integer.", + "b32dec": "Decodes string from Base32 format.", + "b32enc": "Encodes string with Base32 format.", + "b64dec": "Decodes string from Base64 format.", + "b64enc": "Encodes string with Base64 format.", + "base": "", + "bcrypt": "Receives a string and generates its bcrypt hash.", + "biggest": "", + "buildCustomCert": "Allows customizing the certificate. It takes Base64 encoded PEM format certificate and private key as arguments and returns object with PEM-encoded certificate and key. Note that the returned object can be passed to the `genSignedCert` function to sign a certificate using this CA.", + "camelcase": "", + "cat": "", + "ceil": "Returns greatest float value greater than or equal to input value. `ceil 123.001` will return `124.0`.", + "chunk": "", + "clean": "", + "coalesce": "", + "compact": "Accepts a list and removes entries with empty values.", + "concat": "Concatenates arbitrary number of lists into one.", + "contains": "Tests if one string is contained inside of another. `contains \"cat\" \"catch\"` will return `true`.", + "date": "Formats date.", + "dateInZone": "Same as `date` but with a timezone.", + "dateModify": "", + "date_in_zone": "", + "date_modify": "", + "decryptAES": "Receives a Base64 string encoded by the AES-256 CBC algorithm and returns the decoded text.", + "deepCopy": "", + "deepEqual": "", + "default": "", + "derivePassword": "", + "dict": "", + "dig": "", + "dir": "", + "div": "Performs integer division.", + "divf": "", + "duration": "Formats a given amount of seconds as a `time.Duration`.", + "durationRound": "", + "empty": "", + "encryptAES": "Encrypts text with AES-256 CBC and returns a Base64 encoded string.", + "env": "Reads environment variable.", + "expandenv": "Substitutes environment variable in a string.", + "ext": "Returns file extension. `ext \"foo.bar\"` will return `\"bar\"`.", + "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.", + "first": "Returns head item on a list.", + "float64": "Converts to a `float64`.", + "floor": "Returns the greatest float value greater than or equal to input value. `floor 123.9999` will return `123.0`.", + "fromJson": "", + "genCA": "Generates a new, self-signed x509 SSL Certificate Authority using 2048-bit RSA private key. It takes subject common name (CN) and cert validity duration in days as parameters. It returns object with PEM-encoded certificate and key. Note that the returned object can be passed to the `genSignedCert` function to sign a certificate using this CA.", + "genCAWithKey": "Generates a new, self-signed x509 SSL Certificate Authority using given private key. It takes subject common name (CN), cert validity duration in days and private key (PEM-encoded; DSA keys are not supported) as parameters. It returns object with PEM-encoded certificate and key. Note that the returned object can be passed to the `genSignedCert` function to sign a certificate using this CA.", + "genPrivateKey": "", + "genSelfSignedCert": "Generates an SSL self-signed certificate.", + "genSelfSignedCertWithKey": "", + "genSignedCert": "Generates an SSL certificate and key based on a given CA.", + "genSignedCertWithKey": "", + "get": "", + "getHostByName": "", + "has": "Checks if a list has a particular element.", + "hasKey": "", + "hasPrefix": "", + "hasSuffix": "", + "htmlDate": "Formats a date for inserting into HTML date picker input field.", + "htmlDateInZone": "Same as `htmlDate` but with a timezone.", + "htpasswd": "", + "indent": "", + "initial": "Compliments `last` by retuning all but the last element.", + "initials": "", + "int": "Converts to a `int`.", + "int64": "Converts to a `int64`.", + "isAbs": "Checks whether a path is absolute.", + "join": "", + "kebabcase": "", + "keys": "", + "kindIs": "", + "kindOf": "", + "last": "", + "list": "", + "lower": "Converts the entire string to lowercase. `upper \"HELLO\"` will return `hello`.", + "max": "Returns the largest of a series of integers. `max 1 2 3` will return `3`.", + "maxf": "", + "merge": "", + "mergeOverwrite": "", + "min": "Returns the smallest of a series of integers. `min 1 2 3` will return `1`.", + "minf": "", + "mod": "", + "mul": "Multiples numbers. Accepts two or more inputs. `mul 1 2 3` will return `6`.", + "mulf": "", + "mustAppend": "Appends a new item to existing list, creating a new list. Like other `must` functions instead of panicking when there is a problem it will return an error to the template engine.", + "mustChunk": "", + "mustCompact": "Accepts a list and removes entries with empty values. Like other `must` functions instead of panicking when there is a problem it will return an error to the template engine.", + "mustDateModify": "", + "mustDeepCopy": "", + "mustFirst": "Returns head item on a list. Like other `must` functions instead of panicking when there is a problem it will return an error to the template engine.", + "mustFromJson": "", + "mustHas": "Checks if a list has a particular element. Like other `must` functions instead of panicking when there is a problem it will return an error to the template engine.", + "mustInitial": "Compliments `last` by retuning all but the last element. Like other `must` functions instead of panicking when there is a problem it will return an error to the template engine.", + "mustLast": "", + "mustMerge": "", + "mustMergeOverwrite": "", + "mustPrepend": "", + "mustPush": "", + "mustRegexFind": "", + "mustRegexFindAll": "", + "mustRegexMatch": "", + "mustRegexReplaceAll": "", + "mustRegexReplaceAllLiteral": "", + "mustRegexSplit": "", + "mustRest": "Gets tail of the list (everything but the first item). Like other `must` functions instead of panicking when there is a problem it will return an error to the template engine.", + "mustReverse": "Produces a new list with the reversed elements of the given list. Like other `must` functions instead of panicking when there is a problem it will return an error to the template engine.", + "mustSlice": "", + "mustToDate": "Converts a string to a date. The first argument is the date layout and the second is the date string. If the string can’t be converted it returns the zero value. Like other `must` functions instead of panicking when there is a problem it will return an error to the template engine.", + "mustToJson": "", + "mustToPrettyJson": "", + "mustToRawJson": "", + "mustUniq": "Generates a list with all of the duplicates removed. Like other `must` functions instead of panicking when there is a problem it will return an error to the template engine.", + "mustWithout": "Filters items out of a list. Like other `must` functions instead of panicking when there is a problem it will return an error to the template engine.", + "must_date_modify": "", + "nindent": "", + "nospace": "Removes all whitespace from a string. `nospace \"hello w o r l d\"` will return `helloworld`.", + "omit": "", + "osBase": "Returns the last element of a file path. `osBase \"/foo/bar/baz\"` and `osBase \"C:\\\\foo\\\\bar\\\\baz\"` will return `\"baz\"` on Linux and Windows, respectively.", + "osClean": "Cleans up a path. `osClean \"/foo/bar/../baz\"` and `osClean \"C:\\\\foo\\\\bar\\\\..\\\\baz\"` will resolve the `..` and return `foo/baz` on Linux and `C:\\foo\\baz` on Windows.", + "osDir": "Returns the directory, stripping the last part of the path. So `osDir \"/foo/bar/baz\"` returns `/foo/bar` on Linux, and `osDir \"C:\\\\foo\\\\bar\\\\baz\"` returns `C:\\\\foo\\\\bar` on Windows.", + "osExt": "Return the file extension. `osExt \"/foo.bar\"` and `osExt \"C:\\\\foo.bar\"` will return `.bar` on Linux and Windows, respectively.", + "osIsAbs": "Checks whether a file path is absolute.", + "pick": "", + "pluck": "", + "plural": "", + "prepend": "", + "push": "", + "quote": "", + "randAlpha": "", + "randAlphaNum": "", + "randAscii": "", + "randBytes": "Accepts a count `N` and generates cryptographically secure random sequence of `N` bytes. The sequence is returned as a Base64 encoded string.", + "randInt": "Returns a random integer value from min (inclusive) to max (exclusive). `randInt 12 30` will produce a random number in the range from 12 to 30.", + "randNumeric": "", + "regexFind": "", + "regexFindAll": "", + "regexMatch": "", + "regexQuoteMeta": "", + "regexReplaceAll": "", + "regexReplaceAllLiteral": "", + "regexSplit": "", + "repeat": "", + "replace": "", + "rest": "Gets tail of the list (everything but the first item).", + "reverse": "Produces a new list with the reversed elements of the given list.", + "round": "Returns a float value with the remainder rounded to the given number to digits after the decimal point. `round 123.55555 3` will return `123.556`.", + "semver": "", + "semverCompare": "", + "seq": "Works like Bash `seq` command. Specify 1 parameter (`end`) to generate all counting integers between 1 and `end` inclusive. Specify 2 parameters (`start` and `end`) to generate all counting integers between `start` and `end` inclusive incrementing or decrementing by 1. Specify 3 parameters (`start`, `step` and `end`) to generate all counting integers between `start` and `end` inclusive incrementing or decrementing by `step`.", + "set": "", + "sha1sum": "", + "sha256sum": "", + "sha512sum": "", + "shuffle": "", + "slice": "", + "snakecase": "", + "sortAlpha": "", + "split": "", + "splitList": "", + "splitn": "", + "squote": "", + "sub": "", + "subf": "", + "substr": "", + "swapcase": "", + "ternary": "Takes two values and a test value. If the test value is true, the first value will be returned. If the test value is false, the second value will be returned. This is similar to the C ternary operator. `ternary \"foo\" \"bar\" true` or `true | \"foo\" \"bar\"` will return `\"foo\"`.", + "title": "Converts a string to title case. `title \"hello world\"` will return `\"Hello World\"`.", + "toDate": "Converts a string to a date. The first argument is the date layout and the second is the date string. If the string can’t be converted it returns the zero value.", + "toDecimal": "Converts a Unix octal to a `int64`.`\"0777\" | toDecimal` will convert `0777` to `511` and return the value as `int64`.", + "toJson": "", + "toPrettyJson": "", + "toRawJson": "Encodes an item into JSON string with HTML characters unescaped. `toRawJson .Item` will return unescaped JSON string representation of `.Item`.", + "toString": "Converts to a string.", + "toStrings": "Converts a list, slice or array to a list of strings. `list 1 2 3 | toString` converts `1`, `2` and `3` to strings and then returns them as a list.", + "trim": "Removes space from either side of a string. `trim \" hello \"` will return `hello`.", + "trimAll": "Removes given characters from the front or back of a string. `trimAll \"$\" \"$5.00\"` will return `5.00` (as a string).", + "trimPrefix": "Trims just the prefix from a string. `trimPrefix \"-\" \"-hello\"` will return `hello`.", + "trimSuffix": "Trims just the suffix from a string. `trimSuffix \"-\" \"hello-\"` will return `hello`.", + "trimall": "", + "trunc": "", + "tuple": "", + "typeIs": "", + "typeIsLike": "", + "typeOf": "", + "uniq": "Generates a list with all of the duplicates removed.", + "unixEpoch": "Returns the seconds since the Unix epoch.", + "unset": "Given a map and a key it deletes the key from the map. It returns dictionary. Note that if the key is not found this operation will simply return. No error will be generated.", + "until": "Builds a range of integers. `until 5` will return a list `[0, 1, 2, 3, 4]`.", + "untilStep": "Like `until` generates a list of counting integers but it allows to define a start, stop and step. `untilStep 3 6 2` will return `[3, 5]` by starting with 3 and adding 2 until it is equal or greater than 6.", + "untitle": "Removes title casing. `untitle \"Hello World\"` will return `\"hello world\"`.", + "upper": "Converts the entire string to uppercase. `upper \"hello\"` will return `HELLO`.", + "urlJoin": "Joins map produced by `urlParse` to produce URL string. `urlJoin (dict \"fragment\" \"fragment\" \"host\" \"host:80\" \"path\" \"/path\" \"query\" \"query\" \"scheme\" \"http\")` will return `proto://host:80/path?query#fragment`.", + "urlParse": "Parses string for URL and produces dict with URL parts. For more info check https://golang.org/pkg/net/url/#URL.", + "values": "", + "without": "Filters items out of a list. It can take more than one filter.", + "wrap": "Wraps text at a given column count. `wrap 80 $text` will wrap the string in `$text` at 80 columns.", + "wrapWith": "Works as `wrap` but lets you specify the string to wrap with (`wrap` uses `\\n`). `wrapWith 5 \"\\t\" \"Hello world\"` will return `hello world` (where the whitespace is an ASCII tab character).", +} diff --git a/template/liquid_test.go b/template/liquid_test.go new file mode 100644 index 0000000..d0e35dd --- /dev/null +++ b/template/liquid_test.go @@ -0,0 +1,14 @@ +package template + +import ( + "testing" + + "github.com/samber/lo" + "github.com/stretchr/testify/assert" +) + +func TestLiquidFunctionDocs(t *testing.T) { + missingDocs, redundantDocs := lo.Difference(lo.Keys(registeredFunctions), lo.Keys(functionDocs)) + assert.Empty(t, missingDocs, "found liquid functions without documentation: %s", missingDocs) + assert.Empty(t, redundantDocs, "found documentation for functions that are not registered: %s", redundantDocs) +} diff --git a/test/_simple.tpl b/test/_simple.tpl deleted file mode 100644 index c3cfc31..0000000 --- a/test/_simple.tpl +++ /dev/null @@ -1 +0,0 @@ -a basic {{ .Template }} \ No newline at end of file