runjucks_core/
lib.rs

1#![deny(clippy::all)]
2//! Pure Rust template engine core for **Runjucks**, a [Nunjucks](https://mozilla.github.io/nunjucks/)-oriented engine.
3//!
4//! This crate is the **lex → parse → render** pipeline with no Node or NAPI dependencies. The published
5//! [`runjucks` npm package](https://www.npmjs.com/package/runjucks) wraps it in a thin native addon; most
6//! JavaScript callers use that API instead of linking this crate directly.
7//!
8//! Pipeline:
9//! 1. [`lexer::tokenize`] splits template source into [`lexer::Token`]s.
10//! 2. For each [`lexer::Token::Tag`], [`tag_lex::tokenize_tag_body`] can split the inner string into keywords and identifiers.
11//! 3. [`parser::parse`] builds an [`ast::Node`] tree; [`parser::parse_expr`] parses `{{ }}` bodies with Nunjucks-style precedence (see [`parser::expr`]).
12//! 4. [`renderer::render`] walks the AST with an [`Environment`], optional [`loader::TemplateLoader`], and a [`renderer::CtxStack`] built from the JSON context (`{% include %}`, `{% extends %}` / `{% block %}`, `for`/`set` frames, macros).
13//!
14//! # Example
15//!
16//! ```
17//! use runjucks_core::Environment;
18//! use serde_json::json;
19//!
20//! let env = Environment::default();
21//! let out = env
22//!     .render_string("Hello, {{ name }}".into(), json!({ "name": "Ada" }))
23//!     .unwrap();
24//! assert_eq!(out, "Hello, Ada");
25//! ```
26
27pub mod ast;
28pub mod environment;
29pub mod errors;
30pub mod extension;
31pub mod filters;
32pub mod globals;
33mod js_regex;
34pub mod lexer;
35pub mod loader;
36pub mod parser;
37pub mod render_common;
38pub mod renderer;
39#[cfg(feature = "async")]
40pub mod async_renderer;
41pub mod tag_lex;
42pub mod value;
43
44pub use environment::{CustomFilter, CustomGlobalFn, CustomTest, Environment};
45pub use errors::RunjucksError;
46pub use extension::{CustomExtensionHandler, ExtensionTagMeta};
47pub use lexer::{LexerOptions, Tags};
48pub use loader::{file_system_loader, map_loader, FileSystemLoader, FnLoader, TemplateLoader};
49#[cfg(feature = "async")]
50pub use environment::{AsyncCustomFilter, AsyncCustomGlobalFn};
51