helper

package
v2.10.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 23, 2024 License: MIT Imports: 18 Imported by: 4

Documentation

Index

Constants

This section is empty.

Variables

View Source
var RegisteredFuncs template.FuncMap = template.FuncMap{
	"humanSize":                    HumanSize,
	"stringArrayContains":          StringArrayContains,
	"safeHTML":                     SafeHTML,
	"timeFormat24h":                TimeFormat24h,
	"timeFormat12h":                TimeFormat12h,
	"dateFormat":                   DateFormat,
	"dateTimeFormat":               DateTimeFormat,
	"dateFormatYYYYMMDD":           DateFormatYYYYMMDD,
	"dateFormatYYYYMMDDNoSlashes":  DateFormatYYYYMMDDNoSlash,
	"datePeriodFormat":             DatePeriodFormat,
	"dateTimeOnsDatePatternFormat": DateTimeOnsDatePatternFormat,
	"last":                         Last,
	"loop":                         Loop,
	"add":                          Add,
	"subtract":                     Subtract,
	"multiply":                     Multiply,
	"slug":                         Slug,
	"legacyDatasetDownloadURI":     LegacyDatasetDownloadURI,
	"markdown":                     Markdown,
	"localise":                     Localise,
	"domainSetLang":                DomainSetLang,
	"hasField":                     HasField,
	"notLastItem":                  NotLastItem,
	"concatenateStrings":           ConcatenateStrings,
	"truncateToMaximuCharacters":   TruncateToMaximumCharacters,
	"trimPrefixedPeriod":           TrimPrefixedPeriod,
	"intToString":                  IntToString,
	"lower":                        Lower,
	"thousandsSeparator":           ThousandsSeparator,
}

Functions

func Add

func Add(x, y int) int

func ConcatenateStrings

func ConcatenateStrings(tokens ...string) string

ConcatenateStrings takes a number of string arguments and concatenates them

func DateFormat

func DateFormat(s string) string

func DateFormatYYYYMMDD

func DateFormatYYYYMMDD(s string) string

func DateFormatYYYYMMDDNoSlash

func DateFormatYYYYMMDDNoSlash(s string) string

func DatePeriodFormat

func DatePeriodFormat(s string) string

DatePeriodFormat will format a time-series date period string to a human accessible format e.g. "2019 JAN-FEB" to "Jan - Feb 2019" "2010 Q1" to "Jan - Mar 2010"

func DateTimeFormat

func DateTimeFormat(s string) string

func DateTimeOnsDatePatternFormat

func DateTimeOnsDatePatternFormat(s, lang string) string

func DomainSetLang

func DomainSetLang(domain string, uri string, language string) string

func HasField

func HasField(data interface{}, name string) bool

HasField checks to see if the field is present in the struct

func HumanSize

func HumanSize(size string) (string, error)

func InitialiseLocalisationsHelper

func InitialiseLocalisationsHelper(assetFn func(name string) ([]byte, error))

InitialiseLocalisationsHelper sets up the core and service specific localisations for use in the templates with the Localise helper function

func IntToString

func IntToString(val int) string

IntToString converts an interger to a string

func Last

func Last(x int, a interface{}) bool

func LegacyDatasetDownloadURI

func LegacyDatasetDownloadURI(pageURI, filename string) string

LegacyDataSetDownloadURI builds a URI string for a legacy dataset download URI.

func Localise

func Localise(key string, language string, plural int, templateArguments ...string) string

func Loop

func Loop(n, m int) []int

Loop runs through the numbers provided and prints them out

func Lower

func Lower(s string) string

func Markdown

func Markdown(md string) template.HTML

Markdown converts markdown to HTML

func Multiply

func Multiply(x, y int) int

Multiply multiplies two integers

func NotLastItem

func NotLastItem(length, index int) bool

NotLastItem returns true/false based on if the index equals the length Example of use is in JSON-LD partials, where we must determine whether or not a comma should be rendered in a range

func SafeHTML

func SafeHTML(s string) template.HTML

func Slug

func Slug(s string) string

func StringArrayContains

func StringArrayContains(s string, items []string) bool

func Subtract

func Subtract(x, y int) int

func ThousandsSeparator

func ThousandsSeparator(i int) string

func TimeFormat12h

func TimeFormat12h(s string) string

TimeForma12h extracts time value for 12hr clock from ISO8601 formatted timestamps

func TimeFormat24h

func TimeFormat24h(s string) string

TimeFormat24h extracts time value for 24hr clock from ISO8601 formatted timestamps

func TrimPrefixedPeriod

func TrimPrefixedPeriod(input string) string

TrimPrefixedPeriod remove prefixed periods from the start of the string

func TruncateToMaximumCharacters

func TruncateToMaximumCharacters(text string, maxLength int) string

TruncateToMaximumCharacters returns a substring of parameter 'text' if the text is longer than the specified maximum length

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL