Crate rusty_handlebars_parser

Source
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 implementation
  • block.rs: Block helper implementations
  • expression.rs: Expression parsing and evaluation
  • expression_tokenizer.rs: Tokenization of expressions
  • error.rs: Error types and handling
  • build_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
ParseError
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§

ExpressionType
Types of Handlebars expressions
Local
Local variable declaration in a block
TokenType
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
BlockFactory
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

Type Aliases§

BlockMap
Map of block helper names to factories
Result
Result type for template parsing operations