evaluator

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Apr 16, 2024 License: MIT Imports: 4 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Driver

type Driver interface {
	// CreateContext creates a new evaluation context.
	CreateContext(*Environment) (DriverContext, error)
}

Driver represents a template evaluation driver.

type DriverContext

type DriverContext interface {
	// Eval evaluates the provided code and returns the result.
	Eval(code string) (string, error)
}

DriverContext represents the context for template evaluation.

type Environment

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

Environment represents the environment for template evaluation.

func NewEnvironment

func NewEnvironment(fsys fs.FS, props map[string]any, hooksAPI HooksAPI) *Environment

NewEnvironment creates a new instance of Environment with the given parameters.

func (*Environment) Include

func (env *Environment) Include(name string) string

Include includes the template specified by name.

func (*Environment) Props

func (env *Environment) Props() map[string]any

Props returns the properties associated with the environment.

func (*Environment) RegisterHooks added in v0.2.0

func (env *Environment) RegisterHooks(register func(name string, value any) error) error

func (*Environment) Template

func (env *Environment) Template(name string, props map[string]any) string

Template renders the template specified by name with the given properties.

type Evaluator

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

Evaluator represents a template evaluator.

func New

func New(driver Driver, hooks HooksAPI) *Evaluator

New creates a new instance of Evaluator with the given driver and hooks.

func (*Evaluator) Render

func (r *Evaluator) Render(doc *ast.Document, env *Environment) (string, error)

Render renders the given abstract syntax tree document with the provided environment.

type HooksAPI

type HooksAPI interface {
	// Include includes the specified template.
	Include(string) (string, error)
	// Render renders the specified template with the given properties.
	Render(string, map[string]any) (string, error)
}

HooksAPI represents an interface for interacting with template hooks.

type RegisterHooks added in v0.2.0

type RegisterHooks interface {
	Register(onError func(error), reg func(name string, value any) error) error
}

RegisterHooks represents an interface for registering custom hooks

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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