template

package
v1.20210826.18 Latest Latest
Warning

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

Go to latest
Published: Aug 26, 2021 License: MIT Imports: 28 Imported by: 3

Documentation

Overview

Package template implements helpers on-top of the stdlib `text/template`.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewVarsFromPath added in v0.3.0

func NewVarsFromPath(path string) (map[string]interface{}, error)

NewVarsFromPath returns a new vars file from a given path.

Types

type Template

type Template struct {
	Viewmodel
	// contains filtered or unexported fields
}

Template is a wrapper for html.Template.

func New

func New() *Template

New creates a new template.

func NewFromFile

func NewFromFile(filepath string) (*Template, error)

NewFromFile creates a new template from a file.

func (*Template) Body

func (t *Template) Body() string

Body returns the template body.

func (*Template) MustProcessString added in v0.3.2

func (t *Template) MustProcessString() string

MustProcessString is a helper to process a template as a string and panic on error.

func (*Template) Name

func (t *Template) Name() string

Name returns the template name if set, or if not set, just "template" as a constant.

func (*Template) Process

func (t *Template) Process(dst io.Writer) error

Process processes the template.

func (*Template) ProcessString added in v0.3.2

func (t *Template) ProcessString() (string, error)

ProcessString is a helper to process the template as a string.

func (*Template) SetVar

func (t *Template) SetVar(key string, value interface{})

SetVar sets a var in the template.

func (*Template) SetVarsFromFile added in v0.3.0

func (t *Template) SetVarsFromFile(path string) error

SetVarsFromFile reads vars from a file and merges them with the current variables set.

func (*Template) ViewFuncs

func (t *Template) ViewFuncs() texttemplate.FuncMap

ViewFuncs returns the view funcs.

func (*Template) WithBody

func (t *Template) WithBody(body string) *Template

WithBody sets the template body and returns a reference to the template object.

func (*Template) WithDelims

func (t *Template) WithDelims(left, right string) *Template

WithDelims sets the template action delimiters, treating empty string as default delimiter.

func (*Template) WithEnvVars added in v0.3.0

func (t *Template) WithEnvVars(envVars env.Vars) *Template

WithEnvVars sets the environment variables.

func (*Template) WithInclude

func (t *Template) WithInclude(body string) *Template

WithInclude includes a (sub) template into the rendering assets.

func (*Template) WithName

func (t *Template) WithName(name string) *Template

WithName sets the template name.

func (*Template) WithVar

func (t *Template) WithVar(key string, value interface{}) *Template

WithVar sets a variable and returns a reference to the template object.

func (*Template) WithVars

func (t *Template) WithVars(vars Vars) *Template

WithVars reads a map of variables into the template.

type Vars

type Vars = map[string]interface{}

Vars is a soft alias to map[string]interface{}.

func MergeVars added in v0.3.0

func MergeVars(vars ...Vars) Vars

MergeVars merges a variadic array of variable sets.

type ViewFuncs

type ViewFuncs struct{}

ViewFuncs is the type stub for view functions.

var (
	Funcs ViewFuncs
)

DefaultViewFuncs is a singleton for viewfuncs.

func (ViewFuncs) Add added in v1.20201204.1

func (vf ViewFuncs) Add(values ...interface{}) (float64, error)

Add adds numbers together.

func (ViewFuncs) AtIndex added in v0.3.4

func (vf ViewFuncs) AtIndex(index int, collection interface{}) (interface{}, error)

AtIndex returns an element at a given index.

func (ViewFuncs) Base64 added in v0.2.0

func (vf ViewFuncs) Base64(v string) string

Base64 encodes data as a string as a base6 string.

func (ViewFuncs) Base64Decode added in v0.2.0

func (vf ViewFuncs) Base64Decode(v string) (string, error)

Base64Decode decodes a base 64 string.

func (ViewFuncs) CSV added in v0.3.2

func (vf ViewFuncs) CSV(collection interface{}) (string, error)

CSV returns a csv of a given collection.

func (ViewFuncs) Ceil added in v0.2.0

func (vf ViewFuncs) Ceil(d float64) float64

Ceil returns the value rounded up to the nearest integer.

func (ViewFuncs) Concat added in v0.2.0

func (vf ViewFuncs) Concat(strs ...string) string

Concat concatenates a list of strings.

func (ViewFuncs) Contains added in v0.2.0

func (vf ViewFuncs) Contains(substr, v string) bool

Contains returns if a string contains a given substring.

func (ViewFuncs) DateLong added in v1.20201204.1

func (vf ViewFuncs) DateLong(t time.Time) string

DateLong returns the short date for a timestamp.

func (ViewFuncs) DateMonthDay added in v0.2.0

func (vf ViewFuncs) DateMonthDay(t time.Time) string

DateMonthDay returns the month dat format for a timestamp. The format string is "1/2".

func (ViewFuncs) DateShort added in v0.2.0

func (vf ViewFuncs) DateShort(t time.Time) string

DateShort returns the short date for a timestamp. The format string is "1/02/2006"

func (ViewFuncs) DateShortRev added in v1.20201204.1

func (vf ViewFuncs) DateShortRev(t time.Time) string

DateShortRev returns the short date for a timestamp in YYYY/mm/dd format.

func (ViewFuncs) Day added in v0.2.0

func (vf ViewFuncs) Day(t time.Time) int

Day returns the day component of a timestamp.

func (ViewFuncs) Divide added in v1.20201204.1

func (vf ViewFuncs) Divide(values ...interface{}) (float64, error)

Divide divides numbers together.

func (ViewFuncs) DurationRound added in v1.20201204.1

func (vf ViewFuncs) DurationRound(d time.Duration, to time.Duration) time.Duration

DurationRound rounds a duration value.

func (ViewFuncs) DurationRoundMillis added in v1.20201204.1

func (vf ViewFuncs) DurationRoundMillis(d time.Duration) time.Duration

DurationRoundMillis rounds a duration value to milliseconds.

func (ViewFuncs) DurationRoundSeconds added in v1.20201204.1

func (vf ViewFuncs) DurationRoundSeconds(d time.Duration) time.Duration

DurationRoundSeconds rounds a duration value to seconds.

func (ViewFuncs) FileExists added in v0.2.0

func (vf ViewFuncs) FileExists(path string) bool

FileExists returns if the file at a given path exists.

func (ViewFuncs) First added in v0.2.0

func (vf ViewFuncs) First(collection interface{}) (interface{}, error)

First returns the first element of a collection.

func (ViewFuncs) Floor added in v0.2.0

func (vf ViewFuncs) Floor(d float64) float64

Floor returns the value rounded down to zero.

func (ViewFuncs) FormatFileSize added in v1.20210701.2

func (vf ViewFuncs) FormatFileSize(sizeBytes int) string

FormatFileSize formats an int as a file size.

func (ViewFuncs) FormatMoney added in v0.2.0

func (vf ViewFuncs) FormatMoney(d float64) string

FormatMoney returns a float as a formatted string rounded to two decimal places.

func (ViewFuncs) FormatPct added in v0.2.0

func (vf ViewFuncs) FormatPct(d float64) string

FormatPct formats a float as a percentage (it is multiplied by 100, then suffixed with '%')

func (ViewFuncs) FuncMap added in v0.2.0

func (vf ViewFuncs) FuncMap() map[string]interface{}

FuncMap returns the name => func mapping.

func (ViewFuncs) GenerateKey added in v0.2.0

func (vf ViewFuncs) GenerateKey(keySize int) string

GenerateKey generates a key of a given size base 64 encoded.

func (ViewFuncs) GenerateOrdinalNames added in v0.2.0

func (vf ViewFuncs) GenerateOrdinalNames(format string, replicas int) []string

GenerateOrdinalNames generates ordinal names by passing the index to a given formatter. The formatter should be in Sprintf format (i.e. using a '%d' token for where the index should go).

Example:

{{ generate_ordinal_names "worker-%d" 3 }} // [worker-0 worker-1 worker-2]

func (ViewFuncs) HMAC512 added in v0.2.0

func (vf ViewFuncs) HMAC512(key, v string) (string, error)

HMAC512 returns the hmac signed sha 512 sum of a string.

func (ViewFuncs) HasPrefix added in v0.2.0

func (vf ViewFuncs) HasPrefix(prefix, v string) bool

HasPrefix returns if a string has a given prefix.

func (ViewFuncs) HasSuffix added in v0.2.0

func (vf ViewFuncs) HasSuffix(suffix, v string) bool

HasSuffix returns if a string has a given suffix.

func (ViewFuncs) Hour added in v0.2.0

func (vf ViewFuncs) Hour(t time.Time) int

Hour returns the hour component of a timestamp.

func (ViewFuncs) IndentSpaces added in v0.2.0

func (vf ViewFuncs) IndentSpaces(spaceCount int, v interface{}) string

IndentSpaces indents a string by a given set of spaces.

func (ViewFuncs) IndentTabs added in v0.2.0

func (vf ViewFuncs) IndentTabs(tabCount int, v interface{}) string

IndentTabs indents a string with a given number of tabs.

func (ViewFuncs) JSONEncode added in v0.2.0

func (vf ViewFuncs) JSONEncode(v interface{}) (string, error)

JSONEncode returns an object encoded as json.

func (ViewFuncs) JSONEncodePretty added in v0.2.0

func (vf ViewFuncs) JSONEncodePretty(v interface{}) (string, error)

JSONEncodePretty encodes an object as json with indentation.

func (ViewFuncs) Join added in v0.2.0

func (vf ViewFuncs) Join(sep string, collection interface{}) (string, error)

Join creates a string joined with a given separator.

func (ViewFuncs) Last added in v0.2.0

func (vf ViewFuncs) Last(collection interface{}) (interface{}, error)

Last returns the last element of a collection.

func (ViewFuncs) Matches added in v0.2.0

func (vf ViewFuncs) Matches(expr, v string) (bool, error)

Matches returns if a string matches a given regular expression.

func (ViewFuncs) Millisecond added in v0.2.0

func (vf ViewFuncs) Millisecond(t time.Time) int

Millisecond returns the millisecond component of a timestamp.

func (ViewFuncs) Minute added in v0.2.0

func (vf ViewFuncs) Minute(t time.Time) int

Minute returns the minute component of a timestamp.

func (ViewFuncs) Month added in v0.2.0

func (vf ViewFuncs) Month(t time.Time) int

Month returns the month component of a timestamp.

func (ViewFuncs) Multiply added in v1.20201204.1

func (vf ViewFuncs) Multiply(values ...interface{}) (float64, error)

Multiply multiplies numbers together.

func (ViewFuncs) Now added in v0.2.0

func (vf ViewFuncs) Now() time.Time

Now returns the current time in the system timezone.

func (ViewFuncs) NowUTC added in v0.2.0

func (vf ViewFuncs) NowUTC() time.Time

NowUTC returns the current time in the UTC timezone.

func (ViewFuncs) ParseBool added in v0.2.0

func (vf ViewFuncs) ParseBool(raw interface{}) (bool, error)

ParseBool attempts to parse a value as a bool. "truthy" values include "true", "1", "yes". "falsey" values include "false", "0", "no".

func (ViewFuncs) ParseFloat64 added in v1.20201204.1

func (vf ViewFuncs) ParseFloat64(v string) (float64, error)

ParseFloat64 parses a value as a float64.

func (ViewFuncs) ParseInt added in v1.20201204.1

func (vf ViewFuncs) ParseInt(v interface{}) (int, error)

ParseInt parses a value as an integer.

func (ViewFuncs) ParseInt64 added in v1.20201204.1

func (vf ViewFuncs) ParseInt64(v interface{}) (int64, error)

ParseInt64 parses a value as an int64.

func (ViewFuncs) ParseJSON added in v0.2.0

func (vf ViewFuncs) ParseJSON(v string) (interface{}, error)

ParseJSON returns an object encoded as json.

func (ViewFuncs) ParseSemver added in v0.2.0

func (vf ViewFuncs) ParseSemver(v string) (*semver.Version, error)

ParseSemver parses a semantic version string.

func (ViewFuncs) ParseTime added in v0.2.0

func (vf ViewFuncs) ParseTime(format, v string) (time.Time, error)

ParseTime parses a time string with a given format.

func (ViewFuncs) ParseURL added in v0.2.0

func (vf ViewFuncs) ParseURL(v string) (*url.URL, error)

ParseURL parses a url.

func (ViewFuncs) ParseUUID added in v0.2.0

func (vf ViewFuncs) ParseUUID(v string) (uuid.UUID, error)

ParseUUID parses a uuid.

func (ViewFuncs) ParseUnix added in v0.2.0

func (vf ViewFuncs) ParseUnix(v int64) time.Time

ParseUnix returns a timestamp from a unix format.

func (ViewFuncs) ParseYAML added in v0.2.0

func (vf ViewFuncs) ParseYAML(v string) (interface{}, error)

ParseYAML decodes a corups as yaml.

func (ViewFuncs) Prefix added in v0.2.0

func (vf ViewFuncs) Prefix(pref, v string) string

Prefix appends a given string to a prefix.

func (ViewFuncs) Process added in v0.3.0

func (vf ViewFuncs) Process(vm Viewmodel, contents string) (string, error)

Process processes the given contents using a given template viewmodel

func (ViewFuncs) Quote added in v0.3.2

func (vf ViewFuncs) Quote(v string) string

Quote returns a string wrapped in " characters. It will trim space before and after, and only add quotes if they don't already exist.

func (ViewFuncs) RFC3339 added in v0.2.0

func (vf ViewFuncs) RFC3339(t time.Time) string

RFC3339 returns the RFC3339 format for a timestamp.

func (ViewFuncs) RandomLetters added in v0.2.0

func (vf ViewFuncs) RandomLetters(length int) string

RandomLetters returns a string of random letters.

func (ViewFuncs) RandomLettersWithNumbers added in v0.2.0

func (vf ViewFuncs) RandomLettersWithNumbers(count int) string

RandomLettersWithNumbers returns a string of random letters.

func (ViewFuncs) RandomLettersWithNumbersAndSymbols added in v0.2.0

func (vf ViewFuncs) RandomLettersWithNumbersAndSymbols(count int) string

RandomLettersWithNumbersAndSymbols returns a string of random letters.

func (ViewFuncs) ReadFile added in v0.2.0

func (vf ViewFuncs) ReadFile(path string) (string, error)

ReadFile reads the contents of a file path as a string.

func (ViewFuncs) Reverse added in v1.20201204.1

func (vf ViewFuncs) Reverse(collection interface{}) (interface{}, error)

Reverse reverses an array.

func (ViewFuncs) Round added in v0.2.0

func (vf ViewFuncs) Round(places, d float64) float64

Round returns the value rounded to a given set of places. It uses midpoint rounding.

func (ViewFuncs) SHA256 added in v0.2.0

func (vf ViewFuncs) SHA256(v string) string

SHA256 returns the sha256 sum of a string.

func (ViewFuncs) SHA512 added in v0.2.0

func (vf ViewFuncs) SHA512(v string) string

SHA512 returns the sha512 sum of a string.

func (ViewFuncs) Second added in v0.2.0

func (vf ViewFuncs) Second(t time.Time) int

Second returns the seconds component of a timestamp.

func (ViewFuncs) SemverBumpMajor added in v0.2.0

func (vf ViewFuncs) SemverBumpMajor(v *semver.Version) *semver.Version

SemverBumpMajor returns a semver with an incremented major version.

func (ViewFuncs) SemverBumpMinor added in v0.2.0

func (vf ViewFuncs) SemverBumpMinor(v *semver.Version) *semver.Version

SemverBumpMinor returns a semver with an incremented minor version.

func (ViewFuncs) SemverBumpPatch added in v0.2.0

func (vf ViewFuncs) SemverBumpPatch(v *semver.Version) *semver.Version

SemverBumpPatch returns a semver with an incremented patch version.

func (ViewFuncs) SemverMajor added in v0.2.0

func (vf ViewFuncs) SemverMajor(v *semver.Version) int

SemverMajor returns the major component of a semver.

func (ViewFuncs) SemverMinor added in v0.2.0

func (vf ViewFuncs) SemverMinor(v *semver.Version) int

SemverMinor returns the minor component of a semver.

func (ViewFuncs) SemverPatch added in v0.2.0

func (vf ViewFuncs) SemverPatch(v *semver.Version) int

SemverPatch returns the patch component of a semver.

func (ViewFuncs) SequenceInts added in v1.20201204.1

func (vf ViewFuncs) SequenceInts(start, end int) []int

SequenceInts returns an array of ints from min to max, not including max. Given (0,5) as inputs, it would return [0,1,2,3,4]

func (ViewFuncs) Since added in v0.2.0

func (vf ViewFuncs) Since(t time.Time) time.Duration

Since returns the duration since a given timestamp. It is relative, meaning the value returned can be negative.

func (ViewFuncs) SinceUTC added in v0.2.0

func (vf ViewFuncs) SinceUTC(t time.Time) time.Duration

SinceUTC returns the duration since a given timestamp in UTC. It is relative, meaning the value returned can be negative.

func (ViewFuncs) Slice added in v0.2.0

func (vf ViewFuncs) Slice(from, to int, collection interface{}) (interface{}, error)

Slice returns a subrange of a collection.

func (ViewFuncs) Slugify added in v1.20201204.1

func (vf ViewFuncs) Slugify(v string) string

Slugify returns a slug format string. It replaces whitespace with `-` It path escapes any other characters.

func (ViewFuncs) Split added in v0.2.0

func (vf ViewFuncs) Split(sep, v string) []string

Split splits a string by a separator.

func (ViewFuncs) SplitN added in v0.2.0

func (vf ViewFuncs) SplitN(sep string, n float64, v string) []string

SplitN splits a string by a separator a given number of times.

func (ViewFuncs) StripQuotes added in v1.0.0

func (vf ViewFuncs) StripQuotes(v string) string

StripQuotes strips leading and trailing quotes.

func (ViewFuncs) Subtract added in v1.20201204.1

func (vf ViewFuncs) Subtract(values ...interface{}) (float64, error)

Subtract divides numbers together.

func (ViewFuncs) Suffix added in v0.2.0

func (vf ViewFuncs) Suffix(suf, v string) string

Suffix appends a given prefix to a string.

func (ViewFuncs) TSV added in v0.3.2

func (vf ViewFuncs) TSV(collection interface{}) (string, error)

TSV returns a tab separated values of a given collection.

func (ViewFuncs) TimeFormat added in v1.0.0

func (vf ViewFuncs) TimeFormat(format string, t time.Time) string

TimeFormat returns the time with a given format string.

func (ViewFuncs) TimeInLocation added in v0.2.0

func (vf ViewFuncs) TimeInLocation(loc string, t time.Time) (time.Time, error)

TimeInLocation returns the time in a given location by string. If the location is invalid, this will error.

func (ViewFuncs) TimeInUTC added in v1.0.0

func (vf ViewFuncs) TimeInUTC(t time.Time) time.Time

TimeInUTC returns the time in a given location by string. If the location is invalid, this will error.

func (ViewFuncs) TimeIsEpoch added in v1.20210701.2

func (vf ViewFuncs) TimeIsEpoch(t time.Time) bool

TimeIsEpoch returns if the time is the unix epoch time or not.

func (ViewFuncs) TimeIsZero added in v1.20210701.2

func (vf ViewFuncs) TimeIsZero(t time.Time) bool

TimeIsZero returns if the time is set or not.

func (ViewFuncs) TimeKitchen added in v0.2.0

func (vf ViewFuncs) TimeKitchen(t time.Time) string

TimeKitchen returns the kitchen format for a timestamp. The format string is "3:04PM".

func (ViewFuncs) TimeMedium added in v0.2.0

func (vf ViewFuncs) TimeMedium(t time.Time) string

TimeMedium returns the medium format for a timestamp. The format string is "1/02/2006 3:04:05 PM".

func (ViewFuncs) TimeShort added in v0.2.0

func (vf ViewFuncs) TimeShort(t time.Time) string

TimeShort returns the short format for a timestamp. The format string is "1/02/2006 3:04:05 PM".

func (ViewFuncs) TimeSub added in v1.20210701.2

func (vf ViewFuncs) TimeSub(t1, t2 time.Time) time.Duration

TimeSub the duration difference between two times.

func (ViewFuncs) ToBytes added in v0.2.0

func (vf ViewFuncs) ToBytes(v interface{}) []byte

ToBytes attempts to return a bytes representation of a value.

func (ViewFuncs) ToDuration added in v1.20210204.2

func (vf ViewFuncs) ToDuration(val interface{}) (typedVal time.Duration, err error)

ToDuration returns a given value as a duration.

func (ViewFuncs) ToFloat64 added in v0.2.0

func (vf ViewFuncs) ToFloat64(val interface{}) (typedVal float64, err error)

ToFloat64 returns a given value as a float64.

func (ViewFuncs) ToInt added in v0.2.0

func (vf ViewFuncs) ToInt(val interface{}) (typedVal int, err error)

ToInt returns a given value as a int64.

func (ViewFuncs) ToLower added in v0.2.0

func (vf ViewFuncs) ToLower(v string) string

ToLower returns a string case shifted to lower case.

func (ViewFuncs) ToString added in v0.2.0

func (vf ViewFuncs) ToString(v interface{}) string

ToString attempts to return a string representation of a value.

func (ViewFuncs) ToTitle added in v0.2.0

func (vf ViewFuncs) ToTitle(v string) string

ToTitle returns a title cased string.

func (ViewFuncs) ToUpper added in v0.2.0

func (vf ViewFuncs) ToUpper(v string) string

ToUpper returns a string case shifted to upper case.

func (ViewFuncs) TrimPrefix added in v1.0.0

func (vf ViewFuncs) TrimPrefix(prefix, v string) string

TrimPrefix returns if a string has a given prefix.

func (ViewFuncs) TrimSpace added in v0.2.0

func (vf ViewFuncs) TrimSpace(v string) string

TrimSpace trims whitespace from the beginning and end of a string.

func (ViewFuncs) TrimSuffix added in v1.0.0

func (vf ViewFuncs) TrimSuffix(suffix, v string) string

TrimSuffix returns if a string has a given suffix.

func (ViewFuncs) URLEncode added in v1.20201204.1

func (vf ViewFuncs) URLEncode(value string) string

URLEncode encodes a value as a url token.

func (ViewFuncs) URLHost added in v0.2.0

func (vf ViewFuncs) URLHost(v *url.URL) string

URLHost returns the host of a url.

func (ViewFuncs) URLPath added in v0.2.0

func (vf ViewFuncs) URLPath(v *url.URL) string

URLPath returns the url path.

func (ViewFuncs) URLPort added in v0.2.0

func (vf ViewFuncs) URLPort(v *url.URL) string

URLPort returns the url port. If none is explicitly specified, this will return empty string.

func (ViewFuncs) URLQuery added in v0.2.0

func (vf ViewFuncs) URLQuery(name string, v *url.URL) string

URLQuery returns a url query param.

func (ViewFuncs) URLRawQuery added in v0.2.0

func (vf ViewFuncs) URLRawQuery(v *url.URL) string

URLRawQuery returns the url raw query.

func (ViewFuncs) URLScheme added in v0.2.0

func (vf ViewFuncs) URLScheme(v *url.URL) string

URLScheme returns the scheme of a url.

func (ViewFuncs) UUIDv4 added in v0.2.0

func (vf ViewFuncs) UUIDv4() uuid.UUID

UUIDv4 generates a uuid v4.

func (ViewFuncs) Unix added in v0.2.0

func (vf ViewFuncs) Unix(t time.Time) int64

Unix returns the unix format for a timestamp.

func (ViewFuncs) UnixNano added in v1.20201204.1

func (vf ViewFuncs) UnixNano(t time.Time) int64

UnixNano returns the timetamp as nanoseconds from 1970-01-01.

func (ViewFuncs) WithURLHost added in v0.2.0

func (vf ViewFuncs) WithURLHost(host string, v *url.URL) *url.URL

WithURLHost returns the host of a url.

func (ViewFuncs) WithURLPath added in v0.2.0

func (vf ViewFuncs) WithURLPath(path string, v *url.URL) *url.URL

WithURLPath returns the url path.

func (ViewFuncs) WithURLPort added in v0.2.0

func (vf ViewFuncs) WithURLPort(port string, v *url.URL) *url.URL

WithURLPort sets the url port.

func (ViewFuncs) WithURLQuery added in v0.2.0

func (vf ViewFuncs) WithURLQuery(key, value string, v *url.URL) *url.URL

WithURLQuery returns a url query param.

func (ViewFuncs) WithURLRawQuery added in v0.2.0

func (vf ViewFuncs) WithURLRawQuery(rawQuery string, v *url.URL) *url.URL

WithURLRawQuery returns the url path.

func (ViewFuncs) WithURLScheme added in v0.2.0

func (vf ViewFuncs) WithURLScheme(scheme string, v *url.URL) *url.URL

WithURLScheme returns the scheme of a url.

func (ViewFuncs) YAMLEncode added in v0.2.0

func (vf ViewFuncs) YAMLEncode(v interface{}) (string, error)

YAMLEncode returns an object encoded as yaml.

func (ViewFuncs) Year added in v0.2.0

func (vf ViewFuncs) Year(t time.Time) int

Year returns the year component of a timestamp.

type Viewmodel added in v0.3.0

type Viewmodel struct {
	// contains filtered or unexported fields
}

Viewmodel is the template viewmodel. It surfaces a subset of the template api. It is set / accessed by the outer template.

func (Viewmodel) Env added in v0.3.0

func (vm Viewmodel) Env(key string, defaults ...string) (string, error)

Env returns an environment variable.

func (Viewmodel) ExpandEnv added in v0.3.0

func (vm Viewmodel) ExpandEnv(s string) string

ExpandEnv replaces $var or ${var} based on the configured environment variables.

func (Viewmodel) Has added in v1.20201204.1

func (vm Viewmodel) Has(key string) bool

Has is an alias to `HasVar`.

func (Viewmodel) HasEnv added in v0.3.0

func (vm Viewmodel) HasEnv(key string) bool

HasEnv returns if an env var is set.

func (Viewmodel) HasVar added in v0.3.0

func (vm Viewmodel) HasVar(key string) bool

HasVar returns if a variable is set.

func (Viewmodel) Var added in v0.3.0

func (vm Viewmodel) Var(key string, defaults ...interface{}) (interface{}, error)

Var returns the value of a variable, or panics if the variable is not set.

func (Viewmodel) Vars added in v0.3.2

func (vm Viewmodel) Vars() Vars

Vars returns the vars collection.

Jump to

Keyboard shortcuts

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