use crate::expr::Expr;
use rustlavel_core::Error;
use std::collections::BTreeMap;
#[derive(Debug, Clone, PartialEq)]
pub enum Node {
Text(String),
Echo { expr: Expr, escaped: bool },
If { branches: Vec<Branch>, otherwise: Option<Vec<Node>> },
Foreach { subject: Expr, binding: String, body: Vec<Node> },
Yield { section: String, default: Option<Expr> },
Include(TemplateRef),
}
#[derive(Debug, Clone, PartialEq)]
pub struct Branch {
pub condition: Expr,
pub body: Vec<Node>,
}
#[derive(Debug, Clone, PartialEq)]
pub struct TemplateRef {
pub name: String,
pub file: String,
pub line: usize,
pub column: usize,
}
impl TemplateRef {
pub fn error(&self, message: impl Into<String>) -> Error {
Error::Template {
file: self.file.clone(),
line: self.line,
column: self.column,
message: message.into(),
}
}
}
#[derive(Debug, Clone, PartialEq)]
pub struct Template {
pub name: String,
pub nodes: Vec<Node>,
pub extends: Option<TemplateRef>,
pub sections: BTreeMap<String, Vec<Node>>,
}