Expand description
Handlebars template parser and compiler
This crate provides the core functionality for parsing and compiling Handlebars templates
into Rust code. It’s used internally by the rusty-handlebars
crate to process templates
at compile time.
§Features
- Handlebars template parsing
- Template compilation to Rust code
- Support for all standard Handlebars features:
- Variables and expressions
- Block helpers (if, unless, each, with)
- Partials
- Comments
- HTML escaping
- Whitespace control
- Subexpressions
- Lookup helpers
§Example
use rusty_handlebars_parser::{Compiler, Options, BlockMap};
use rusty_handlebars_parser::block::add_builtins;
let mut factories = BlockMap::new();
add_builtins(&mut factories);
let compiler = Compiler::new(Options {
write_var_name: "f",
root_var_name: Some("self")
}, factories);
let template = "Hello {{name}}!";
let rust_code = compiler.compile(template).unwrap();
§Module Structure
compiler.rs
: Main compiler implementationblock.rs
: Block helper implementationsexpression.rs
: Expression parsing and evaluationexpression_tokenizer.rs
: Tokenization of expressionserror.rs
: Error types and handlingbuild_helper.rs
: Helper functions for template building
Modules§
- build_
helper - HTML minification configuration
Structs§
- Compile
- Compiler state
- Compiler
- Main compiler implementation
- Expression
- Represents a parsed Handlebars expression
- Options
- Compiler options
- Parse
Error - Error type for template parsing failures
- Rust
- Rust code generation state
- Scope
- A scope in the template
- Token
- A token parsed from an expression
- Uses
- Helper for formatting use statements
Enums§
- Expression
Type - Types of Handlebars expressions
- Local
- Local variable declaration in a block
- Token
Type - Types of tokens that can be parsed from an expression
Statics§
- USE_
AS_ DISPLAY - Trait for HTML escaping
- USE_
AS_ DISPLAY_ HTML - Trait for raw HTML output
Traits§
- Block
- Trait for block helpers
- Block
Factory - Trait for block helper factories
Functions§
- add_
builtins - Adds built-in block helpers to the block map
- append_
with_ depth - Appends a depth suffix to a variable name