evaluation

package
v0.2.22 Latest Latest
Warning

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

Go to latest
Published: Sep 6, 2023 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func EvalBoolExpression

func EvalBoolExpression(context Context, expression string) (bool, error)

EvalBoolExpression determines whether given go template expression evaluates to true or false

func EvalTemplate

func EvalTemplate(context Context, text string) (string, error)

EvalTemplate interpolates given template text into a final output string

func Render

func Render(context Context, inputDir, outputDir string) error

Render copies all files from inputDir into outputDir, rendering as templates those for which rendering is enabled interpolating folder and file names appropriately and skipping folders and files for which bracket expressions evaluate to false

Types

type Context

type Context interface {
	// GetEvalVars returns a dictionary of the project's variable names mapped to
	// their corresponding values for evaluation purposes. It does not include the
	// process' env var.
	GetEvalVars() map[string]interface{}

	// GetPlaceholders returns a map of special placeholders that can be used instead
	// of go template expressions, for more lightweight templating, especially for the
	// project's name, which appears everywhere.
	GetPlaceholders() map[string]string

	// GetShellVars returns all env vars to be used when invoking shell commands,
	// including the current process' env vars, the project's vars and an augmented
	// PATH var including extra bin dirs.
	GetShellVars(includeProcessVars bool) []string
}

Context encapsulates everything required for template evaluation and rendering

type Insert

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

func NewInsert

func NewInsert(text string) (*Insert, error)

func (Insert) Eval

func (i Insert) Eval(context Context, text string) (string, error)

type RenderMode

type RenderMode int

RenderMode determines how/if rendering enabled/disabled state should change for an item and all its children recursively, compared to parent's state

const (
	// DefaultRendering preserves current rendering mode of parent
	DefaultMode RenderMode = iota

	// TemplateRendering enables template rendering for itself and all children recursively
	TemplateMode

	// CopyRendering disables template rendering for itself and all children recursively
	CopyMode

	// InsertRendering enables template insertion, but only for a single file
	InsertMode
)

type Section

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

Jump to

Keyboard shortcuts

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