Skip to main content

Crate teravars

Crate teravars 

Source
Expand description

Tera templating + smart [vars] handling for self-rendering TOML configs.

See README.md and ROADMAP.md for the design rationale and migration plan.

§Quickstart

use teravars::{Context, Engine, extract_vars, resolve, system_context};

let raw = r#"
# sample: greeting = "{{ vars.not_defined }}"   <- a comment, never rendered

[vars]
greeting = "hello"
who      = "{{ vars.greeting }} world"

[server]
banner = "{{ vars.who }} on {{ system.os }}"
"#;

let mut engine = Engine::new();

let mut vars = extract_vars(raw).unwrap();
resolve(&mut vars, &mut engine).unwrap();

let mut ctx: Context = system_context();
ctx.insert("vars", &vars);

// `render_toml`, not `render`: it strips the file's `#` comments first, so
// a commented-out sample line cannot fail the render.
let rendered = engine.render_toml(raw, &ctx).unwrap();
assert!(rendered.contains("hello world on "));
assert!(!rendered.contains("vars.not_defined"));

Structs§

Context
The struct that holds the context of a template rendering.
Engine
Kwargs
Re-exports of tera’s function/filter authoring types, so consumers can register custom helpers via Engine::register_function (or Engine::tera_mut) without taking a direct tera dependency.
State
Re-exports of tera’s function/filter authoring types, so consumers can register custom helpers via Engine::register_function (or Engine::tera_mut) without taking a direct tera dependency.
SystemInfo
TeraError
tera’s error type, re-exported under an aliased name so it doesn’t clash with teravars’ own Error. Use it to construct errors from custom functions/filters (TeraError::message("…")). The Error struct for Tera.
Value
Re-exports of tera’s function/filter authoring types, so consumers can register custom helpers via Engine::register_function (or Engine::tera_mut) without taking a direct tera dependency.

Enums§

Error
Number
Re-exports of tera’s function/filter authoring types, so consumers can register custom helpers via Engine::register_function (or Engine::tera_mut) without taking a direct tera dependency.

Traits§

ArgFromValue
Re-exports of tera’s function/filter authoring types, so consumers can register custom helpers via Engine::register_function (or Engine::tera_mut) without taking a direct tera dependency.
Filter
Re-exports of tera’s function/filter authoring types, so consumers can register custom helpers via Engine::register_function (or Engine::tera_mut) without taking a direct tera dependency.
Function
Re-exports of tera’s function/filter authoring types, so consumers can register custom helpers via Engine::register_function (or Engine::tera_mut) without taking a direct tera dependency.
FunctionResult
Re-exports of tera’s function/filter authoring types, so consumers can register custom helpers via Engine::register_function (or Engine::tera_mut) without taking a direct tera dependency.

Functions§

expand_value
extract_vars
Carve the [vars] table out of a raw TOML+Tera document.
resolve
resolve_in_context
Like resolve, but each rendering iteration is performed against a context that already contains the caller-supplied bindings. Use this when [vars] entries reference outside data such as system.* or any other values the caller has placed into the Context.
resolve_in_context_with_max_iter
resolve_with_max_iter
strip_toml_comments
Remove every TOML comment from text, keeping its line structure.
system_context

Type Aliases§

Map
Re-exports of tera’s function/filter authoring types, so consumers can register custom helpers via Engine::register_function (or Engine::tera_mut) without taking a direct tera dependency.
Result
TeraResult
Re-exports of tera’s function/filter authoring types, so consumers can register custom helpers via Engine::register_function (or Engine::tera_mut) without taking a direct tera dependency.