Menu
Public repository / 9df51040bf1687e4dc8a91557f02df52e8d5cf3a
AkurAI-Framework / crates/template/src/ast.rs
Latest change efd5eb833824dca5c86104004c11bc6d39ff1a72 - feat(template): pure-std SSR template engine + component showcase by Ólafur Búi Ólafsson
//! The template AST: what a parsed template is made of.
/// A dotted lookup path into the context, e.g. `user.name` → `["user","name"]`.
pub type Path = Vec<String>;
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum Node {
/// Literal text, emitted verbatim.
Text(String),
/// `{{ path }}` (HTML-escaped) or `{{{ path }}}` (raw, `escape = false`).
Var { path: Path, escape: bool },
/// `{% if path %} body {% else %} else_body {% endif %}`.
If {
cond: Path,
body: Vec<Node>,
else_body: Vec<Node>,
},
/// `{% for var in path %} body {% endfor %}` over an array.
For {
var: String,
path: Path,
body: Vec<Node>,
},
/// `{% include "name" %}` — renders another registered template inline.
Include(String),
}