tmpl

package
v0.163.1 Latest Latest
Warning

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

Go to latest
Published: Mar 25, 2024 License: MIT Imports: 25 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DisableInsecureFeaturesErr = DisableInsecureFeaturesError{envvar.DisableInsecureFeatures + " is active, insecure function calls are disabled"}

Functions

func NewTextRenderer

func NewTextRenderer(fs *filesystem.FileSystem, basePath string, data any) *templateTextRenderer

func Required

func Required(warn string, val any) (any, error)

func RequiredEnv

func RequiredEnv(name string) (string, error)

func ToYaml

func ToYaml(v any) (string, error)

Types

type Context

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

func (*Context) CreateFuncMap

func (c *Context) CreateFuncMap() template.FuncMap

CreateFuncMap creates a template.FuncMap for the Context struct. It combines the functions from sprig.TxtFuncMap() with the functions defined in the Context's createFuncMap() method. It also adds aliases for certain functions based on the aliases map. The resulting FuncMap is returned.

func (*Context) EnvExec

func (c *Context) EnvExec(envs map[string]any, command string, args []any, inputs ...string) (string, error)

TODO: in the next major version, remove this function.

func (*Context) Exec

func (c *Context) Exec(command string, args []any, inputs ...string) (string, error)

func (*Context) IsFile

func (c *Context) IsFile(filename string) (bool, error)

func (*Context) ReadDir

func (c *Context) ReadDir(path string) ([]string, error)

func (*Context) ReadDirEntries added in v0.145.3

func (c *Context) ReadDirEntries(path string) ([]fs.DirEntry, error)

func (*Context) ReadFile

func (c *Context) ReadFile(filename string) (string, error)

func (*Context) RenderTemplateToBuffer

func (c *Context) RenderTemplateToBuffer(s string, data ...any) (*bytes.Buffer, error)

RenderTemplateToBuffer renders the provided template string with the given data and returns the result as a *bytes.Buffer. The template string is parsed and executed using the Context's newTemplate method. If an error occurs during parsing or execution, it is returned along with the partially rendered template. The data parameter is optional and can be used to provide additional data for template rendering. If no data is provided, the template is rendered with an empty data context.

func (*Context) SetBasePath

func (c *Context) SetBasePath(path string)

SetBasePath sets the base path for the template

func (*Context) SetFileSystem added in v0.145.4

func (c *Context) SetFileSystem(fs *filesystem.FileSystem)

func (*Context) Tpl

func (c *Context) Tpl(text string, data any) (string, error)

type DisableInsecureFeaturesError

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

func (DisableInsecureFeaturesError) Error

type FileRenderer

type FileRenderer struct {
	Context *Context
	Data    any
	// contains filtered or unexported fields
}

func NewFileRenderer

func NewFileRenderer(fs *filesystem.FileSystem, basePath string, data any) *FileRenderer

func NewFirstPassRenderer

func NewFirstPassRenderer(basePath string, data any) *FileRenderer

func (*FileRenderer) RenderTemplateContentToBuffer

func (r *FileRenderer) RenderTemplateContentToBuffer(content []byte) (*bytes.Buffer, error)

func (*FileRenderer) RenderTemplateContentToString

func (r *FileRenderer) RenderTemplateContentToString(content []byte) (string, error)

func (*FileRenderer) RenderTemplateFileToBuffer

func (r *FileRenderer) RenderTemplateFileToBuffer(file string) (*bytes.Buffer, error)

func (*FileRenderer) RenderToBytes

func (r *FileRenderer) RenderToBytes(path string) ([]byte, error)

RenderToBytes loads the content of the file. If its extension is `gotmpl` it treats the content as a go template and renders it.

type MockvalClient

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

MockvalClient is a mock of valClient interface

func NewMockvalClient

func NewMockvalClient(ctrl *gomock.Controller) *MockvalClient

NewMockvalClient creates a new mock instance

func (*MockvalClient) EXPECT

EXPECT returns an object that allows the caller to indicate expected use

func (*MockvalClient) Eval

func (_m *MockvalClient) Eval(template map[string]any) (map[string]any, error)

Eval mocks base method

type MockvalClientMockRecorder

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

MockvalClientMockRecorder is the mock recorder for MockvalClient

func (*MockvalClientMockRecorder) Eval

func (_mr *MockvalClientMockRecorder) Eval(arg0 any) *gomock.Call

Eval indicates an expected call of Eval

type TextRenderer

type TextRenderer interface {
	RenderTemplateText(text string) (string, error)
}

type Values

type Values = map[string]any

func FromYaml

func FromYaml(str string) (Values, error)

func SetValueAtPath

func SetValueAtPath(path string, value any, values Values) (Values, error)

Jump to

Keyboard shortcuts

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