1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
//! Temple is a small language for shaping data: an input value goes in, a
//! value of the shape you asked for comes out.
//!
//! ```text
//! let total = input.items.map(i -> i.price * i.qty).sum()
//!
//! {
//! "customer": {{ input.customer.name }},
//! "total": {{ total }},
//! "vip": {{ total > 1000 }}
//! }
//! ```
//!
//! # Rendering a template
//!
//! [`Template::compile`] parses and checks the source once; render it as
//! many times as you like, into a [`Value`] or straight into your own type.
//!
//! ```
//! use serde::Deserialize;
//! use temple_dsl::{Template, Value};
//!
//! #[derive(Deserialize)]
//! struct Greeting {
//! text: String,
//! }
//!
//! let template = Template::compile(r#"{ "text": {{ concat("hi ", input.name) }} }"#).unwrap();
//! let greeting: Greeting = template.render(Value::obj([("name", "Ada")])).unwrap();
//! assert_eq!(greeting.text, "hi Ada");
//! ```
//!
//! # Embedding temple in another language
//!
//! A host parses one expression or value at a time inside its own syntax
//! ([`ExprUnit::parse_at`], [`TemplateUnit::parse_at`]), checks it against
//! the [`Names`] it will bind, and evaluates it with an [`Env`] under a
//! [`Budget`].
//!
//! ```
//! use temple_dsl::{Budget, Env, ExprUnit, Names, Value};
//!
//! let names = Names::new().var("limit");
//! let unit = ExprUnit::compile("input.age >= limit", &names).unwrap();
//! let env = Env::new().set("limit", 18);
//! let out = unit
//! .eval(&Value::obj([("age", Value::Int(21))]), &env, &Budget::new(1_000))
//! .unwrap();
//! assert_eq!(out, Value::Bool(true));
//! ```
pub use ;
pub use Value;
pub use ;
pub use Budget;
pub use BLOB_VERSION;
pub use Template;
/// This crate's version, for hosts that record it next to stored blobs.
pub const VERSION: &str = env!;
/// Whether `name` is reserved (`input`, `this`, `let`, …) and so can't name a
/// variable or function.
/// Whether `name` is a built-in function, and so can't name a host function.