Documentation ¶
Overview ¶
Package jetfunc provides provides set of functions, which can be used along with the Jet templating engine. It supports jet v6. See the templating engine itself, on address https://github.com/CloudyKit/jet.
Usage in templates ¶
All functions can be accessed from template using both camelCase name, or PascalCase name. For example, both of these forms will work:
{{ leftPad('what',10) }} {{ LeftPad('what',10 }}
Usage in go code
package main import ( "https://github.com/CloudyKit/jet/v6" "gitlab.com/Herout/jetfunc" ) func main() { dir := "path/to/template/dir" set := jet.NewSet(jet.NewOSFileSystemLoader(dir), jet.WithSafeWriter(nil)) jetfunc.AddFunctionsToSet(set) // ... and now, do something with the set }
Disclaimer ¶
This is an alpha release. API is unstable. Should this break your code, you get to keep both pieces.
Index ¶
- func AddFunctionsToSet(v *jet.Set)
- func Default(a jet.Arguments) reflect.Value
- func EqualFold(a jet.Arguments) reflect.Value
- func IfFirst(a jet.Arguments) reflect.Value
- func LeftPad(a jet.Arguments) reflect.Value
- func QQUote(a jet.Arguments) reflect.Value
- func Quote(a jet.Arguments) reflect.Value
- func RightPad(a jet.Arguments) reflect.Value
- func StashGet(a jet.Arguments) reflect.Value
- func StashReset(a jet.Arguments) reflect.Value
- func StashSet(a jet.Arguments) reflect.Value
- func Substring(a jet.Arguments) reflect.Value
- func TrimPrefix(a jet.Arguments) reflect.Value
- func TrimSuffix(a jet.Arguments) reflect.Value
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AddFunctionsToSet ¶
func AddFunctionsToSet(v *jet.Set)
AddFunctionsToSet registers all functions to jet.Set.
func Default ¶
Default takes one or more parameters, and returns first non-empty string from these parameters, or empty string.
{{ default(a,b,c,'return this if all are empty') }}
func IfFirst ¶
IfFirst accepts two, or three parameters.
{{ ifFirst(aNumber,wantFirst,wantElse)}}
The function:
- returns wantFirst string, if first parameter (aNumber) is integer, and also aNumber == 0
- else returns wantElse string; if wantElse is not provided, returns empty string.
func LeftPad ¶
LeftPad returns string padded left by spaces, or by the third parameter, if such is provided. Input parametewrs are:
- toPad - mandatory string, which will be padded
- toLen - mandatory integer, pad to which length
- padChar - optional string, defaults to space
func QQUote ¶
QQUote accepts one, or two parameters.
- want - string, will be returned quoted by double qoute, all inside doubleqoutes will be doubled.
- ie: {{ doubleQuote('this') }} renders as "this"
- ie: {{ doubleQuote('this "is" Sparta') }} renders as "this ""is"" Sparta"
- orElse - string, optional; this will be returned 'as is' if want == ""
- ie: {{ doubleQuote(”,'NULL') }} renderes as NULL
func Quote ¶
Quote accepts one, or two parameters.
- want - string, will be returned quoted, all inside quotes will be doubled.
- ie: {{ doubleQuote('this') }} renders as 'this'
- ie: {{ doubleQuote('this ”is” Sparta') }} renders as 'this ”is” Sparta'
- orElse - string, optional; this will be returned as-is, if want == ""
- ie: {{ doubleQuote(”,'NULL') }} renderes as NULL
func RightPad ¶
RightPad returns string padded right by spaces, or by the third parameter, if such is provided. Input parametewrs are:
- toPad - mandatory string, which will be padded
- toLen - mandatory integer, pad to which length
- padChar - optional string, defaults to space
func StashReset ¶
StashReset creates an empty global stash. The global stash is mutex protected map[string]string, which can later on be accessed via StashSet and StashGet functions. The function takes one oprional parameter. If the value provided is string "true", then StashGet WILL panic if you attempt to access key which was nat yet stored using StashSet.
func Substring ¶
Substring returns a substring, based on following three parameters.
- what - string, which we want to get substring from.
- startAt - integer, starting position from which we want to get substring
- wantRunes - optional, integer, number of runes we want to get; if not provided, gets the rest of the string.
On any error, Substring returns whole "what" parameter.
func TrimPrefix ¶
TrimPrefix is a wrapper over strings.TrimPrefix.
func TrimSuffix ¶
TrimSuffix is a wrapper over strings.TrimSuffix.
Types ¶
This section is empty.