template

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: May 12, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package template — list resolution.

Shared resolution path for inputs that need to be a []string but may arrive as: a Go slice already in the variable map (e.g. `[]string` loaded by include_vars), a template expression that renders to a YAML/JSON list literal, a Pongo2-stringified Go slice ("[a b c]"), or a whitespace/comma separated scalar. Used by `with_items` (planner) and `package.names`.

Package template provides template rendering functionality using pongo2.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ResolveList added in v0.5.0

func ResolveList(expr string, vars map[string]interface{}, evaluator expression.Evaluator) ([]interface{}, error)

ResolveList resolves a string expression to a list of items.

Order of attempts (first match wins; later steps only run if earlier steps could not establish a binding for `expr`):

  1. If `expr` is the exact name of a variable, require its value to be a list (returns an error otherwise — strict, preserves with_items semantics).
  2. Otherwise evaluate via the expression evaluator (supports dot notation). If evaluation succeeds, require the result to be a list.
  3. If neither path bound `expr` to a value, parse the expression itself as a literal list/scalar (handles rendered strings like "[a, b]" or "a b c").

The returned slice is []interface{} for compatibility with `with_items`, which uses interface{} per iteration item. Callers needing []string can use ResolveStringList.

func ResolveStringList added in v0.5.0

func ResolveStringList(expr string, vars map[string]interface{}, evaluator expression.Evaluator) ([]string, error)

ResolveStringList resolves a string expression to []string. Non-string items are formatted with %v.

Types

type Pongo2Renderer

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

Pongo2Renderer implements Renderer using the pongo2 template engine.

func (*Pongo2Renderer) Render

func (r *Pongo2Renderer) Render(template string, variables map[string]interface{}) (string, error)

Render renders a template string with the given variables.

type Renderer

type Renderer interface {
	Render(template string, variables map[string]interface{}) (string, error)
}

Renderer defines the interface for template rendering.

func NewPongo2Renderer

func NewPongo2Renderer() (Renderer, error)

NewPongo2Renderer creates a new Pongo2Renderer with filters registered. Returns an error if filter registration fails (e.g., filter name already registered).

Jump to

Keyboard shortcuts

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