view: github.com/fragmenta/view/helpers Index | Files

package helpers

import "github.com/fragmenta/view/helpers"

Index

Package Files

forms.go helpers.go html.go maths.go

func Add Uses

func Add(a int, b int) int

Add returns a + b

func Append Uses

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

Append all args to an array, and return that array

func Array Uses

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

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

func Blank Uses

func Blank(s string) bool

Blank returns true if a string is empty

func CSRF Uses

func CSRF() got.HTML

CSRF generates an input field tag containing a CSRF token

func CSV Uses

func CSV(s got.HTML) string

CSV escape (replace , with ,,)

func CentsToBase Uses

func CentsToBase(p int64) string

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

func CentsToPrice Uses

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 Uses

func CentsToPriceShort(p int64) string

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

func CommaSeparatedArray Uses

func CommaSeparatedArray(args []string) string

CommaSeparatedArray returns the values as a comma separated string

func Contains Uses

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

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

func CreateMap Uses

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 Uses

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 Uses

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 Uses

func Empty() map[string]interface{}

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

func Escape Uses

func Escape(s string) string

Escape escapes HTML using HTMLEscapeString

func EscapeURL Uses

func EscapeURL(s string) string

EscapeURL escapes URLs using HTMLEscapeString

func Exists Uses

func Exists(s string) bool

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

func Field Uses

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

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

func HTML Uses

func HTML(s string) got.HTML

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

func HTMLAttribute Uses

func HTMLAttribute(s string) got.HTMLAttr

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

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 Uses

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

Map sets a map key and return the map

func Mod Uses

func Mod(a int, b int) int

Mod returns a modulo b

func NumberOptions Uses

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

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

func Odd Uses

func Odd(a int) bool

Odd returns true if a is odd

func OptionsForSelect Uses

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

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

func PriceToCents Uses

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 Uses

func PriceToCentsString(p string) string

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

func Sanitize Uses

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 Uses

func Script(name string) got.HTML

Script inserts a script tag

func Select Uses

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 Uses

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 Uses

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

Set a map key and return an empty string

func SetIf Uses

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 StringOptions Uses

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

StringOptions creates an array of selectables from strings

func Strip Uses

func Strip(s string) got.HTML

Strip all html tags and returns as go template HTML

func Style Uses

func Style(name string) got.HTML

Style inserts a css tag

func Subtract Uses

func Subtract(a int, b int) int

Subtract returns a - b

func TextArea Uses

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

TextArea returns a field div containing a textarea

func Time Uses

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

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

func Truncate Uses

func Truncate(s string, l int64) string

Truncate text to a given length

func URL Uses

func URL(s string) got.URL

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

func UTCDate Uses

func UTCDate(t time.Time) got.HTML

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

func UTCNow Uses

func UTCNow() got.HTML

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

func UTCTime Uses

func UTCTime(t time.Time) got.HTML

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

func XMLPreamble Uses

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

type Option Uses

type Option struct {
    Id   int64
    Name string
}

Option type contains number and string

type Selectable Uses

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

Selectable provides an interface for options in a select

type SelectableOption Uses

type SelectableOption struct {
    Name  string
    Value string
}

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

func (SelectableOption) SelectName Uses

func (o SelectableOption) SelectName() string

SelectName returns the public name for this select option

func (SelectableOption) SelectValue Uses

func (o SelectableOption) SelectValue() string

SelectValue returns the value for this select option

Package helpers imports 7 packages (graph) and is imported by 11 packages. Updated 2017-08-24. Refresh now. Tools for package owners.