jetfuncs

package module
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Jan 13, 2020 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Funcs = map[string]interface{}{
	"default": jet.Func(func(a jet.Arguments) reflect.Value {
		a.RequireNumOfArguments("default", 2, 2)
		arg0 := a.Get(0)

		ctx := a.Runtime().Context()
		if ctx.Kind() == reflect.Ptr {
			ctx = ctx.Elem()
		}

		switch ctx.Kind() {
		case reflect.Map:
			if r := ctx.MapIndex(arg0); r.IsValid() {
				return r
			}
		case reflect.Struct:
			if r := ctx.FieldByName(arg0.String()); r.IsValid() {
				return r
			}
		}

		ret := a.Runtime().Resolve(arg0.String())
		if ret.Kind() != reflect.Invalid {
			return ret
		}
		return a.Get(1)
	}),
	"isZero":     isZero,
	"trimPrefix": strings.TrimPrefix,
	"trimSuffix": strings.TrimSuffix,
	"join":       strings.Join,
	"format":     fmt.Sprintf,
}

Functions

This section is empty.

Types

This section is empty.

Jump to

Keyboard shortcuts

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