template

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Jul 27, 2025 License: MPL-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BaseTemplate

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

BaseTemplate provides common functionality for template implementations

func NewBaseTemplate

func NewBaseTemplate(injector di.Injector) *BaseTemplate

NewBaseTemplate creates a new BaseTemplate instance

func (*BaseTemplate) Initialize

func (t *BaseTemplate) Initialize() error

Initialize sets up the BaseTemplate dependencies

type JsonnetTemplate

type JsonnetTemplate struct {
	*BaseTemplate
}

JsonnetTemplate handles jsonnet template processing with configurable rules

func NewJsonnetTemplate

func NewJsonnetTemplate(injector di.Injector) *JsonnetTemplate

NewJsonnetTemplate constructs a JsonnetTemplate with default processing rules for blueprint and terraform Jsonnet files. It initializes the embedded BaseTemplate and assigns rules for blueprint.jsonnet and terraform/*.jsonnet path handling. The blueprint rule matches the exact "blueprint.jsonnet" filename and generates the "blueprint" key. The terraform rule matches files under the "terraform/" directory with a ".jsonnet" extension and generates keys by stripping the extension.

func (*JsonnetTemplate) Initialize

func (t *JsonnetTemplate) Initialize() error

Initialize sets up the JsonnetTemplate dependencies

func (*JsonnetTemplate) Process

func (t *JsonnetTemplate) Process(templateData map[string][]byte, renderedData map[string]any) error

Process applies configured processing rules to jsonnet templates and populates renderedData with evaluated results. For each template in templateData, the method checks all rules for a matching PathMatcher. If a rule matches, it processes the template using processJsonnetTemplate, stores the result in renderedData under the key generated by the rule's KeyGenerator, and skips further rule checks for that template. Returns an error if processing fails.

type JsonnetVM

type JsonnetVM interface {
	ExtCode(key, val string)
	EvaluateAnonymousSnippet(filename, snippet string) (string, error)
}

JsonnetVM provides an interface for Jsonnet virtual machine operations

type MockTemplate

type MockTemplate struct {
	InitializeFunc func() error
	ProcessFunc    func(templateData map[string][]byte, renderedData map[string]any) error
}

MockTemplate is a mock implementation of the Template interface for testing

func NewMockTemplate

func NewMockTemplate(injector di.Injector) *MockTemplate

NewMockTemplate creates a new MockTemplate instance

func (*MockTemplate) Initialize

func (m *MockTemplate) Initialize() error

Initialize calls the mock InitializeFunc if set, otherwise returns nil

func (*MockTemplate) Process

func (m *MockTemplate) Process(templateData map[string][]byte, renderedData map[string]any) error

Process calls the mock ProcessFunc if set, otherwise returns nil

type ProcessingRule

type ProcessingRule struct {
	// PathMatcher determines if a file path should be processed by this rule
	PathMatcher func(string) bool
	// KeyGenerator generates the output key from the input path
	KeyGenerator func(string) string
}

ProcessingRule defines how to match and process template files

type RealJsonnetVM

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

RealJsonnetVM is the real implementation of JsonnetVM

func (*RealJsonnetVM) EvaluateAnonymousSnippet

func (j *RealJsonnetVM) EvaluateAnonymousSnippet(filename, snippet string) (string, error)

EvaluateAnonymousSnippet evaluates a Jsonnet snippet

func (*RealJsonnetVM) ExtCode

func (j *RealJsonnetVM) ExtCode(key, val string)

ExtCode sets external code for the Jsonnet VM

type Shims

type Shims struct {
	ReadFile      func(name string) ([]byte, error)
	ReadDir       func(name string) ([]os.DirEntry, error)
	Stat          func(name string) (os.FileInfo, error)
	WriteFile     func(name string, data []byte, perm os.FileMode) error
	MkdirAll      func(path string, perm os.FileMode) error
	Getenv        func(key string) string
	YamlUnmarshal func(data []byte, v any) error
	YamlMarshal   func(v any) ([]byte, error)
	JsonMarshal   func(v any) ([]byte, error)
	JsonUnmarshal func(data []byte, v any) error
	NewJsonnetVM  func() JsonnetVM
	FilepathBase  func(path string) string
}

Shims provides mockable wrappers around system and runtime functions

func NewShims

func NewShims() *Shims

NewShims creates a new Shims instance with default implementations

type Template

type Template interface {
	Initialize() error
	Process(templateData map[string][]byte, renderedData map[string]any) error
}

Template defines the interface for template processors

Jump to

Keyboard shortcuts

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