fieldinterp

package
v0.23.0 Latest Latest
Warning

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

Go to latest
Published: May 21, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package fieldinterp provides {field} placeholder interpolation with CUE path resolution for nested front-matter access.

Placeholders use the syntax {fieldname}. Nested access uses dot notation ({a.b.c}) and non-identifier keys use CUE quoting ({"my-key".sub}). A literal { is written as {{, and a literal } is written as }}. Missing keys resolve to empty string.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ContainsField

func ContainsField(text string) bool

ContainsField reports whether text contains at least one {field} placeholder (not counting escaped {{ braces).

func DiagnoseYAMLQuoting

func DiagnoseYAMLQuoting(paramName string, val any) string

DiagnoseYAMLQuoting checks whether a raw YAML value that was expected to be a string was instead parsed as a map because YAML interpreted {field} placeholder syntax as a flow mapping. Returns a diagnostic message if the conflict is detected, empty string otherwise.

func Fields

func Fields(text string) []string

Fields returns the field names referenced by {field} placeholders in text. Escaped braces {{ are ignored. For nested paths like {a.b}, returns "a.b".

func Interpolate

func Interpolate(text string, data map[string]any) string

Interpolate replaces {field} placeholders in text with values resolved from data using CUE path semantics. Supports nested access ({a.b}) and quoted keys ({"my-key"}). Missing keys resolve to empty string.

func ParseCUEPath

func ParseCUEPath(expr string) []string

ParseCUEPath parses a CUE path expression into unquoted label segments using cue.ParsePath. Non-identifier keys (hyphens, dots, spaces) must be quoted: "my-key". Returns nil for malformed expressions.

func ResolvePath

func ResolvePath(data map[string]any, path []string) (string, error)

ResolvePath walks data using the given path segments and returns the string value at the resolved location.

func SplitOnFields

func SplitOnFields(text string) []string

SplitOnFields splits text on {field} placeholders and returns the literal parts between them. Escaped braces are treated as literals. For "{id}: {name}" it returns ["", ": ", ""].

func Stringify

func Stringify(v any) string

Stringify converts a scalar value to a string representation. Maps and slices return empty string to avoid nondeterministic output.

func Validate

func Validate(text string) error

Validate checks that text has valid placeholder syntax. It returns an error if there are unclosed braces, stray closing braces, or invalid CUE paths. Non-identifier keys must be quoted: {"my-key"} not {my-key}.

Types

This section is empty.

Jump to

Keyboard shortcuts

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