Documentation
¶
Overview ¶
Package builtin provides simple functions that can be used as global functions in a Scriggo template.
For example, to use the Min and Max functions as global min and max functions
globals := templates.Declarations{
"min": builtin.Min,
"max": builtin.Max,
}
opts := &templates.BuildOptions{
Globals: globals,
}
template, err := scriggoTemplates.Build(fsys, file, opts)
And to use them in a template
{{ min(x, y) }}
{{ max(x, y) }}
Use this Declarations value to use all the builtin of this package in a template
templates.Declarations{
"abbreviate": builtin.Abbreviate,
"abs": builtin.Abs,
"base64": builtin.Base64,
"capitalize": builtin.Capitalize,
"capitalizeAll": builtin.CapitalizeAll,
"hasPrefix": builtin.HasPrefix,
"hasSuffix": builtin.HasSuffix,
"hex": builtin.Hex,
"hmacSHA1": builtin.HmacSHA1,
"hmacSHA256": builtin.HmacSHA256,
"htmlEscape": builtin.HtmlEscape,
"index": builtin.Index,
"indexAny": builtin.IndexAny,
"join": builtin.Join,
"lastIndex": builtin.LastIndex,
"max": builtin.Max,
"md5": builtin.Md5,
"min": builtin.Min,
"queryEscape": builtin.QueryEscape,
"replace": builtin.Replace,
"replaceAll": builtin.ReplaceAll,
"reverse": builtin.Reverse,
"runeCount": builtin.RuneCount,
"sha1": builtin.Sha1,
"sha256": builtin.Sha256,
"sort": builtin.Sort,
"split": builtin.Split,
"splitN": builtin.SplitN,
"sprint": builtin.Sprint,
"sprintf": builtin.Sprintf,
"toKebab": builtin.ToKebab,
"toLower": builtin.ToLower,
"toUpper": builtin.ToUpper,
"trim": builtin.Trim,
"trimLeft": builtin.TrimLeft,
"trimPrefix": builtin.TrimPrefix,
"trimRight": builtin.TrimRight,
"trimSuffix": builtin.TrimSuffix,
}
Index ¶
- func Abbreviate(s string, n int) string
- func Abs(x int) int
- func Base64(s string) string
- func Capitalize(src string) string
- func CapitalizeAll(src string) string
- func HasPrefix(s, prefix string) bool
- func HasSuffix(s, suffix string) bool
- func Hex(src string) string
- func HmacSHA1(message, key string) string
- func HmacSHA256(message, key string) string
- func HtmlEscape(s string) templates.HTML
- func Index(s, substr string) int
- func IndexAny(s, chars string) int
- func Join(elems []string, sep string) string
- func LastIndex(s, substr string) int
- func Max(x, y int) int
- func Md5(src string) string
- func Min(x, y int) int
- func QueryEscape(s string) string
- func Replace(s, old, new string, n int) string
- func ReplaceAll(s, old, new string) string
- func Reverse(data interface{})
- func RuneCount(s string) (n int)
- func Sha1(src string) string
- func Sha256(s string) string
- func Sort(slice interface{}, less func(i, j int) bool)
- func Split(s, sep string) []string
- func SplitN(s, sep string, n int) []string
- func Sprint(a ...interface{}) string
- func Sprintf(format string, a ...interface{}) string
- func ToKebab(s string) string
- func ToLower(s string) string
- func ToUpper(s string) string
- func Trim(s, cutset string) string
- func TrimLeft(s, cutset string) string
- func TrimPrefix(s, prefix string) string
- func TrimRight(s, cutset string) string
- func TrimSuffix(s, suffix string) string
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Abbreviate ¶
Abbreviate abbreviates s to almost n runes. If s is longer than n runes, the abbreviated string terminates with "...".
func Capitalize ¶
Capitalize returns a copy of the string src with the first non-separator in upper case.
func CapitalizeAll ¶
CapitalizeAll returns a copy of the string src with the first letter of each word in upper case.
func HmacSHA1 ¶
HmacSHA1 returns the HMAC-SHA1 tag for the given message and key, as a base64 encoded string.
func HmacSHA256 ¶
HmacSHA256 returns the HMAC-SHA256 tag for the given message and key, as a base64 encoded string.
func HtmlEscape ¶
HtmlEscape escapes s, replacing the characters <, >, &, " and ' and returns the escaped string as templates.HTML type.
func Index ¶
Index returns the index of the first instance of substr in s, or -1 if substr is not present in s.
func IndexAny ¶
IndexAny returns the index of the first instance of any Unicode code point from chars in s, or -1 if no Unicode code point from chars is present in s.
func Join ¶
Join concatenates the elements of its first argument to create a single string. The separator string sep is placed between elements in the resulting string.
func LastIndex ¶
LastIndex returns the index of the last instance of substr in s, or -1 if substr is not present in s.
func QueryEscape ¶
QueryEscape escapes the string so it can be safely placed inside a URL query.
func Replace ¶
Replace returns a copy of the string s with the first n non-overlapping instances of old replaced by new. If old is empty, it matches at the beginning of the string and after each UTF-8 sequence, yielding up to k+1 replacements for a k-rune string. If n < 0, there is no limit on the number of replacements.
func ReplaceAll ¶
ReplaceAll returns a copy of the string s with all non-overlapping instances of old replaced by new. If old is empty, it matches at the beginning of the string and after each UTF-8 sequence, yielding up to k+1 replacements for a k-rune string.
func RuneCount ¶
RuneCount returns the number of runes in s. Erroneous and short encodings are treated as single runes of width 1 byte.
func Sort ¶
Sort sorts the provided slice given the provided less function.
The function panics if the provided interface is not a slice.
func Split ¶
Split slices s into all substrings separated by sep and returns a slice of the substrings between those separators.
If s does not contain sep and sep is not empty, Split returns a slice of length 1 whose only element is s.
If sep is empty, Split splits after each UTF-8 sequence. If both s and sep are empty, Split returns an empty slice.
It is equivalent to SplitN with a count of -1.
func SplitN ¶
SplitN slices s into substrings separated by sep and returns a slice of the substrings between those separators.
The count determines the number of substrings to return:
n > 0: at most n substrings; the last substring will be the unsplit remainder. n == 0: the result is nil (zero substrings) n < 0: all substrings
Edge cases for s and sep (for example, empty strings) are handled as described in the documentation for Split.
func Sprint ¶
func Sprint(a ...interface{}) string
Sprint formats using the default formats for its operands and returns the resulting string. Spaces are added between operands when neither is a string.
func Trim ¶
Trim returns a slice of the string s with all leading and trailing Unicode code points contained in cutset removed.
func TrimLeft ¶
TrimLeft returns a slice of the string s with all leading Unicode code points contained in cutset removed.
To remove a prefix, use TrimPrefix instead.
func TrimPrefix ¶
TrimPrefix returns s without the provided leading prefix string. If s doesn't start with prefix, s is returned unchanged.
func TrimRight ¶
TrimRight returns a slice of the string s, with all trailing Unicode code points contained in cutset removed.
To remove a suffix, use TrimSuffix instead.
func TrimSuffix ¶
TrimSuffix returns s without the provided trailing suffix string. If s doesn't end with suffix, s is returned unchanged.
Types ¶
This section is empty.