Skip to main content

Crate somni_template

Crate somni_template 

Source
Expand description

§somni-template

A small, configurable templating engine built on top of somni-expr.

Templates are transpiled into a Somni program and then executed. Literal text is emitted verbatim; interpolations and directive expressions are evaluated by Somni.

Language guide: _template_book.

§Example

use somni_template::{Env, Iter, Syntax, Template};

let tmpl = Template::compile(
    "#for n in nums\n{{ str(n) }},\n#endfor\n",
    &Syntax::lines(),
)
.unwrap();

let mut env = Env::new();
env.value("nums", Iter(vec![1u64, 2, 3]));

assert_eq!(tmpl.render(env).unwrap(), "1,\n2,\n3,\n");

See Env for supplying data, IntoValue/Iter for values and loop sources, and TemplateError for diagnostics (which always point into the original template).

Re-exports§

pub use error::TemplateError;
pub use syntax::BlockStyle;
pub use syntax::Syntax;
pub use syntax::resolve_syntax;
pub use syntax::split_frontmatter;

Modules§

_template_book
End-user guide to the somni-template language.
error
Template errors.
syntax
Configuration of the template surface syntax.

Structs§

Env
The data supplied to a single template render.
Iter
Wraps an iterable so it becomes a loop source (a Somni iterator value).
SomniIterator
A live iterator value, backed by a reference-counted Rust iterator.
SomniStruct
A struct value: a struct name plus its fields, keyed by field name.
Template
A compiled template.

Enums§

TypedValue
Represents any value in the expression language.

Traits§

IntoValue
A Rust value that can be registered on an Env.

Type Aliases§

TemplateTypes
The Somni type set used by the templating engine.