helpers

package
v1.6.2 Latest Latest
Warning

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

Go to latest
Published: Nov 17, 2020 License: MIT Imports: 7 Imported by: 21

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Add

func Add(a int, b int) int

Add returns a + b

func Ago added in v1.5.7

func Ago(t time.Time, formats ...string) string

Ago returns a time string reporting distance from the current date of form 5 hours ago

func Append

func Append(m []interface{}, args ...interface{}) []interface{}

Append all args to an array, and return that array

func Array

func Array(args ...interface{}) []interface{}

Array takes a set of interface pointers as variadic args, and returns a single array

func Blank

func Blank(s string) bool

Blank returns true if a string is empty

func CSRF

func CSRF() got.HTML

CSRF generates an input field tag containing a CSRF token

func CSV

func CSV(s got.HTML) string

CSV escape (replace , with ,,)

func CentsToBase

func CentsToBase(p int64) string

CentsToBase converts cents to the base currency unit, preserving cent display, with no currency

func CentsToPrice

func CentsToPrice(p int64) string

CentsToPrice converts a price in pence to a human friendly price including currency unit At present it assumes the currency is pounds, it should instead take an optional param for currency or not include it at all

func CentsToPriceShort added in v1.4.1

func CentsToPriceShort(p int64) string

CentsToPriceShort converts a price in pence to a human friendly price abreviated (no pence)

func CommaSeparatedArray

func CommaSeparatedArray(args []string) string

CommaSeparatedArray returns the values as a comma separated string

func Contains

func Contains(list []int64, item int64) bool

Contains returns true if this array of ints contains the given int

func CreateMap

func CreateMap(args ...interface{}) map[string]interface{}

CreateMap - given a set of interface pointers as variadic args, generate and return a map to the values This is currently unused as we just use simpler Map add above to add to context

func Date

func Date(t time.Time, formats ...string) got.HTML

Date returns a formatted date string given a time and optional format Date format layouts are for the date 2006-01-02

func DateField

func DateField(label string, name string, t time.Time, args ...string) got.HTML

DateField sets up a date field with a data-date attribute storing the real date

func Empty

func Empty() map[string]interface{}

Empty returns an empty map[string]interface{} for use as a context

func Escape

func Escape(s string) string

Escape escapes HTML using HTMLEscapeString

func EscapeURL

func EscapeURL(s string) string

EscapeURL escapes URLs using HTMLEscapeString

func Exists added in v1.4.1

func Exists(s string) bool

Exists returns true if this string has a length greater than 0

func Field

func Field(label string, name string, v interface{}, args ...string) got.HTML

Field accepts name string, value interface{}, fieldType string, args ...string

func HTML

func HTML(s string) got.HTML

HTML returns a string (which must not contain user input) as go template HTML

func HTMLAttribute

func HTMLAttribute(s string) got.HTMLAttr

HTMLAttribute returns a string (which must not contain user input) as go template HTMLAttr

func Int64 added in v1.6.1

func Int64(i int) int64

Int64 returns an int64 from an int

func JSON added in v1.5.7

func JSON(t string) got.HTML

JSON escapes a string for use in a json template (html template)

func JSONTime added in v1.5.7

func JSONTime(t time.Time) got.HTML

JSONTime returns a formatted date string with format suitable for using in a json file

func Link(t string, u string, a ...string) got.HTML

Link returns got.HTML with an anchor link given text and URL required Attributes (if supplied) should not contain user input

func Map

func Map(m map[string]interface{}, k string, v interface{}) map[string]interface{}

Map sets a map key and return the map

func Mod

func Mod(a int, b int) int

Mod returns a modulo b

func NumberToCommas added in v1.6.1

func NumberToCommas(n int64) string

NumberToCommas formats large numbers with commas the entire number is still represented

func NumberToHuman added in v1.6.1

func NumberToHuman(n int64) string

NumberToHuman formats large numbers for human consumption some preceision is lost, e.g. 1.3m rather than 130000001

func Odd

func Odd(a int) bool

Odd returns true if a is odd

func OptionsForSelect

func OptionsForSelect(value interface{}, options interface{}) got.HTML

OptionsForSelect creates a select field given an array of keys and values in order

func PriceToCents

func PriceToCents(p string) int

PriceToCents converts a price string in human friendly notation (£45 or £34.40) to a price in pence as an int64

func PriceToCentsString

func PriceToCentsString(p string) string

PriceToCentsString returns a price in cents as a string for use in params

func Sanitize

func Sanitize(s string) got.HTML

Sanitize the html, leaving only tags we consider safe (see the sanitize package for details and tests)

func Script

func Script(name string) got.HTML

Script inserts a script tag

func Select

func Select(label string, name string, value int64, options []Option) got.HTML

Select creates a select field given an array of keys and values in order

func SelectArray

func SelectArray(label string, name string, value interface{}, options interface{}) got.HTML

SelectArray creates a select field given an array of keys and values in order

func Set

func Set(m map[string]interface{}, k string, v interface{}) string

Set a map key and return an empty string

func SetIf

func SetIf(m map[string]interface{}, k string, v interface{}, t bool) string

SetIf sets a map key if the given condition is true

func Strip

func Strip(s string) got.HTML

Strip all html tags and returns as go template HTML

func Style

func Style(name string) got.HTML

Style inserts a css tag

func Subtract added in v1.4.1

func Subtract(a int, b int) int

Subtract returns a - b

func TextArea

func TextArea(label string, name string, v interface{}, args ...string) got.HTML

TextArea returns a field div containing a textarea

func Time

func Time(time time.Time, formats ...string) got.HTML

Time returns a formatted time string given a time and optional format

func Truncate

func Truncate(s string, l int64) string

Truncate text to a given length

func URL

func URL(s string) got.URL

URL returns returns a string (which must not contain user input) as go template URL

func UTCDate

func UTCDate(t time.Time) got.HTML

UTCDate returns a formatted date string in 2006-01-02

func UTCNow

func UTCNow() got.HTML

UTCNow returns a formatted date string in 2006-01-02

func UTCTime

func UTCTime(t time.Time) got.HTML

UTCTime returns a formatted date string in 2006-01-02

func XMLPreamble added in v1.4.1

func XMLPreamble() got.HTML

XMLPreamble returns an XML preamble as got.HTML, primarily to work around a bug in html/template which escapes <? see https://github.com/golang/go/issues/12496

func YearNow added in v1.6.1

func YearNow() got.HTML

YearNow returns a formatted date string for the current year

Types

type Option

type Option struct {
	Id   int64  // The value - FIXME migrate to ID and use as interface
	Name string // The name
}

Option type contains number and string

func NewOption added in v1.6.2

func NewOption(id int64, name string) Option

NewOption returns a new option, given an id and name

func (Option) ID added in v1.6.2

func (o Option) ID() int64

ID returns the value for this select option as an int64 this is supplied in case of use in templates

func (Option) SelectID added in v1.6.2

func (o Option) SelectID() int64

SelectID returns the value for this select option as an int64

func (Option) SelectName added in v1.6.2

func (o Option) SelectName() string

SelectName returns the public name for this select option

func (Option) SelectValue added in v1.6.2

func (o Option) SelectValue() string

SelectValue returns the value for this select option

func (Option) SetID added in v1.6.2

func (o Option) SetID(id int64)

SetID is deprecated

type Selectable

type Selectable interface {
	SelectName() string
	SelectValue() string
}

Selectable provides an interface for options in a select

type SelectableOption

type SelectableOption struct {
	Name  string
	Value string
}

SelectableOption provides a concrete implementation of Selectable - this should be called string option or similar

func NumberOptions

func NumberOptions(args ...int64) []SelectableOption

NumberOptions creates an array of selectables, with an optional min and max value supplied as arguments

func StringOptions

func StringOptions(args ...string) []SelectableOption

StringOptions creates an array of selectables from strings

func (SelectableOption) SelectName

func (o SelectableOption) SelectName() string

SelectName returns the public name for this select option

func (SelectableOption) SelectValue

func (o SelectableOption) SelectValue() string

SelectValue returns the value for this select option

Jump to

Keyboard shortcuts

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