Expand description
Pure Rust template engine core for Runjucks, a Nunjucks-oriented engine.
This crate is the lex → parse → render pipeline with no Node or NAPI dependencies. The published
runjucks npm package wraps it in a thin native addon; most
JavaScript callers use that API instead of linking this crate directly.
Pipeline:
lexer::tokenizesplits template source intolexer::Tokens.- For each
lexer::Token::Tag,tag_lex::tokenize_tag_bodycan split the inner string into keywords and identifiers. parser::parsebuilds anast::Nodetree;parser::parse_exprparses{{ }}bodies with Nunjucks-style precedence (seeparser::expr).renderer::renderwalks the AST with anEnvironment, optionalloader::TemplateLoader, and arenderer::CtxStackbuilt from the JSON context ({% include %},{% extends %}/{% block %},for/setframes, macros).
§Example
use runjucks_core::Environment;
use serde_json::json;
let env = Environment::default();
let out = env
.render_string("Hello, {{ name }}".into(), json!({ "name": "Ada" }))
.unwrap();
assert_eq!(out, "Hello, Ada");Re-exports§
pub use environment::CustomFilter;pub use environment::CustomGlobalFn;pub use environment::CustomTest;pub use environment::Environment;pub use errors::RunjucksError;pub use extension::CustomExtensionHandler;pub use extension::ExtensionTagMeta;pub use lexer::LexerOptions;pub use lexer::Tags;pub use loader::map_loader;pub use loader::FnLoader;pub use loader::TemplateLoader;
Modules§
- ast
- Abstract syntax tree for templates after
crate::parser::parse. - environment
Environmentholds render options and is the entry point forEnvironment::render_string.- errors
- User-facing render and parse failures as a simple string message.
- extension
- Custom tag extensions (Nunjucks-style [
Environment::register_extension] / JSaddExtension). - filters
- Output filters applied during render (e.g. HTML escaping when
crate::Environment::autoescapeis on). - globals
- Nunjucks-style default globals (
range,cycler,joiner) and marker values foris callable. - lexer
- Tokenization: splits template source into
Tokens forcrate::parser::parse. - loader
- Resolving template names to source strings for
crate::Environment::render_template. - parser
- Builds
crate::ast::Nodetrees fromcrate::lexer::Tokenstreams. - renderer
- Walks
crate::ast::Nodetrees and produces output strings using ancrate::Environmentand JSON context. - tag_lex
- Tokenization of the inside of a
{% … %}tag (after the template lexer producedcrate::lexer::Token::Tag). - value
- JSON
serde_json::Valueto display string for template output.