celplate

package module
v0.5.2 Latest Latest
Warning

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

Go to latest
Published: Jun 29, 2026 License: MIT Imports: 3 Imported by: 0

README

celplate

Test

Celplate provides an elegant way to template files using the Common Expression Language (CEL). The package comes with all the batteries included: a generic scanner and a single (CEL) evaluator for it.

By default the scanner assumes that any block of text that start with ${{ is a special input block which has to be evaluated and must end with }}, example:

${{ inputs.serial }}

Too see the library in action, checkout the end to end test for it.

Note that the current implementation does not support escaping the special input block.

Extensions

We've added ext/Strings extensions to the CEL evaluator. This includes a bunch of useful methods, such as charAt, indexOf, join, split, replace, trim etc.

Releasing

To create a new release just create a new tag with a v prefix and push it to main. For more details checkout the go docs on publishing modules.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Evaluator

type Evaluator interface {
	// Evaluate evaluates the given expression and returns its result, and an
	// error, if any.
	Evaluate(expression string) (string, error)
}

Evaluator evaluates expressions nested inside supported blocks (${{ ... }}).

type Scanner

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

func NewScanner

func NewScanner(evaluator Evaluator) *Scanner

NewScanner returns a new generic `Scanner` object.

func (*Scanner) Transform

func (s *Scanner) Transform(input []byte) ([]byte, error)

Transform will transform a given byte slice by using the evaluator. It will continue even if it encounters an error gathering all errors and returning at the end of input.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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