AkurAI Build
Menu

Public repository / 3a1d4dc0df9425a910df82402300a2aeb40318ae

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),
}