GoToSocial/vendor/github.com/Masterminds/sprig/v3
Vyr Cossont fc3741365c
[bugfix] Fix Swagger spec and add test script (#2698)
* Add Swagger spec test script

* Fix Swagger spec errors not related to statuses with polls

* Add API tests that post a status with a poll

* Fix creating a status with a poll from form params

* Fix Swagger spec errors related to statuses with polls (this is the last error)

* Fix Swagger spec warnings not related to unused definitions

* Suppress a duplicate list update params definition that was somehow causing wrong param names

* Add Swagger test to CI

- updates Drone config
- vendorizes go-swagger
- fixes a file extension issue that caused the test script to generate JSON instead of YAML with the vendorized version

* Put `Sample: ` on its own line everywhere

* Remove unused id param from emojiCategoriesGet

* Add 5 more pairs of profile fields to account update API Swagger

* Remove Swagger prefix from dummy fields

It makes the generated code look weird

* Manually annotate params for statusCreate operation

* Fix all remaining Swagger spec warnings

- Change some models into operation parameters
- Ignore models that already correspond to manually documented operation parameters but can't be trivially changed (those with file fields)

* Documented that creating a status with scheduled_at isn't implemented yet

* sign drone.yml

* Fix filter API Swagger errors

* fixup! Fix filter API Swagger errors

---------

Co-authored-by: tobi <tobi.smethurst@protonmail.com>
2024-03-06 18:05:45 +01:00
..
.gitignore [bugfix] Fix Swagger spec and add test script (#2698) 2024-03-06 18:05:45 +01:00
CHANGELOG.md [bugfix] Fix Swagger spec and add test script (#2698) 2024-03-06 18:05:45 +01:00
LICENSE.txt [bugfix] Fix Swagger spec and add test script (#2698) 2024-03-06 18:05:45 +01:00
Makefile [bugfix] Fix Swagger spec and add test script (#2698) 2024-03-06 18:05:45 +01:00
README.md [bugfix] Fix Swagger spec and add test script (#2698) 2024-03-06 18:05:45 +01:00
crypto.go [bugfix] Fix Swagger spec and add test script (#2698) 2024-03-06 18:05:45 +01:00
date.go [bugfix] Fix Swagger spec and add test script (#2698) 2024-03-06 18:05:45 +01:00
defaults.go [bugfix] Fix Swagger spec and add test script (#2698) 2024-03-06 18:05:45 +01:00
dict.go [bugfix] Fix Swagger spec and add test script (#2698) 2024-03-06 18:05:45 +01:00
doc.go [bugfix] Fix Swagger spec and add test script (#2698) 2024-03-06 18:05:45 +01:00
functions.go [bugfix] Fix Swagger spec and add test script (#2698) 2024-03-06 18:05:45 +01:00
list.go [bugfix] Fix Swagger spec and add test script (#2698) 2024-03-06 18:05:45 +01:00
network.go [bugfix] Fix Swagger spec and add test script (#2698) 2024-03-06 18:05:45 +01:00
numeric.go [bugfix] Fix Swagger spec and add test script (#2698) 2024-03-06 18:05:45 +01:00
reflect.go [bugfix] Fix Swagger spec and add test script (#2698) 2024-03-06 18:05:45 +01:00
regex.go [bugfix] Fix Swagger spec and add test script (#2698) 2024-03-06 18:05:45 +01:00
semver.go [bugfix] Fix Swagger spec and add test script (#2698) 2024-03-06 18:05:45 +01:00
strings.go [bugfix] Fix Swagger spec and add test script (#2698) 2024-03-06 18:05:45 +01:00
url.go [bugfix] Fix Swagger spec and add test script (#2698) 2024-03-06 18:05:45 +01:00

README.md

Sprig: Template functions for Go templates

GoDoc Go Report Card Stability: Sustained

The Go language comes with a built-in template language, but not very many template functions. Sprig is a library that provides more than 100 commonly used template functions.

It is inspired by the template functions found in Twig and in various JavaScript libraries, such as underscore.js.

IMPORTANT NOTES

Sprig leverages mergo to handle merges. In its v0.3.9 release, there was a behavior change that impacts merging template functions in sprig. It is currently recommended to use v0.3.10 or later of that package. Using v0.3.9 will cause sprig tests to fail.

Package Versions

There are two active major versions of the sprig package.

  • v3 is currently stable release series on the master branch. The Go API should remain compatible with v2, the current stable version. Behavior change behind some functions is the reason for the new major version.
  • v2 is the previous stable release series. It has been more than three years since the initial release of v2. You can read the documentation and see the code on the release-2 branch. Bug fixes to this major version will continue for some time.

Usage

Template developers: Please use Sprig's function documentation for detailed instructions and code snippets for the >100 template functions available.

Go developers: If you'd like to include Sprig as a library in your program, our API documentation is available at GoDoc.org.

For standard usage, read on.

Load the Sprig library

To load the Sprig FuncMap:


import (
  "github.com/Masterminds/sprig/v3"
  "html/template"
)

// This example illustrates that the FuncMap *must* be set before the
// templates themselves are loaded.
tpl := template.Must(
  template.New("base").Funcs(sprig.FuncMap()).ParseGlob("*.html")
)


Calling the functions inside of templates

By convention, all functions are lowercase. This seems to follow the Go idiom for template functions (as opposed to template methods, which are TitleCase). For example, this:

{{ "hello!" | upper | repeat 5 }}

produces this:

HELLO!HELLO!HELLO!HELLO!HELLO!

Principles Driving Our Function Selection

We followed these principles to decide which functions to add and how to implement them:

  • Use template functions to build layout. The following types of operations are within the domain of template functions:
    • Formatting
    • Layout
    • Simple type conversions
    • Utilities that assist in handling common formatting and layout needs (e.g. arithmetic)
  • Template functions should not return errors unless there is no way to print a sensible value. For example, converting a string to an integer should not produce an error if conversion fails. Instead, it should display a default value.
  • Simple math is necessary for grid layouts, pagers, and so on. Complex math (anything other than arithmetic) should be done outside of templates.
  • Template functions only deal with the data passed into them. They never retrieve data from a source.
  • Finally, do not override core Go template functions.