Documentation ¶
Index ¶
- Variables
- func ApproximateDuration(d time.Duration) string
- func ClassMap(classMap ...any) (string, error)
- func FormatDuration(d time.Duration) string
- func FormatTime(t time.Time, format string) string
- func Humanize(s string) string
- func InputAttrs(nameID string, attrs ...any) (map[string]any, error)
- func IsBlank(s string) bool
- func NotBlank(s string) bool
- func Pluralize(count any, singular string, plural string) (string, error)
- func Slugify(s string) string
- func Srcset(src string, widths ...string) string
- func Truncate(s string, n int) string
- func YesNo(b bool) string
Constants ¶
This section is empty.
Variables ¶
var FuncMap = template.FuncMap{ "yesno": YesNo, "inputAttrs": InputAttrs, "safeHTML": safeHTML, "safeAttr": safeAttr, "safeCSS": safeCSS, "safeJS": safeJS, "safeURL": safeURL, "classMap": ClassMap, "isEven": isEven, "isOdd": isOdd, "int": toInt64, "slice": slice, "contains": strings.Contains, "hasPrefix": strings.HasPrefix, "hasSuffix": strings.HasSuffix, "humanize": Humanize, "isBlank": IsBlank, "join": strings.Join, "lower": strings.ToLower, "notBlank": NotBlank, "pluralize": Pluralize, "replaceAll": strings.ReplaceAll, "replace": strings.Replace, "slugify": Slugify, "split": strings.Split, "trim": strings.TrimSpace, "trimPrefix": strings.TrimPrefix, "trimSuffix": strings.TrimSuffix, "truncate": Truncate, "upper": strings.ToUpper, "now": time.Now, "since": time.Since, "until": time.Until, }
Functions ¶
func ApproximateDuration ¶
func ClassMap ¶
ClassMap takes a pair of classes and boolean expressions, and returns a single string with the active classes.
func FormatDuration ¶
func Humanize ¶
Humanize a string from snake case, slug, or camel case to a human readable string. Example: "hello_world" -> "Hello world"
func InputAttrs ¶
InputAttrs prepares the data for rendering an input field in a separate template. nameID is used for both the name and ID attributes for simplicity. errors is a slice of strings representing validation messages for this input. attrs are additional attributes provided as key/value pairs. Use a "label" attribute to set the label text, and a "type" attribute to set the input type. Use a "hint" attribute to set the hint text. Use an "error" attribute to set an error message. Use a "togglePassword" attribute to "true" to add a toggle button for password visibility (only for password inputs).
func Slugify ¶
Slugify converts a string to a slug naively. For a more robust solution, consider using a library like github.com/gosimple/slug
func Srcset ¶
Srcset returns a srcset string for an image with the given src and widths. It takes a src string and a variadic list of widths. The widths can be either a number or a number followed by a "w" or "x" suffix. If the width does not have a suffix, it will default to "w". Use "x" for density descriptors. Example:
Srcset("/foo/example.webp", "100", "200", "300") // => "/foo/example-100w.webp, /foo/example-200w.webp, /foo/example-300w.webp" Srcset("/foo/example.webp", "100w", "200w", "300w") // => "/foo/example-100w.webp, /foo/example-200w.webp, /foo/example-300w.webp" Srcset("/example.jpg", "1x", "2x") // => "/example-1x.jpg, /example-2x.jpg"
Types ¶
This section is empty.