This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
MiniJinja is a powerful Jinja2-compatible template engine for Rust with minimal dependencies. The project is organized as a Cargo workspace with multiple crates:
- minijinja - Core template engine library
- minijinja-cli - Command-line interface for template rendering
- minijinja-contrib - Additional filters and functions
- minijinja-autoreload - Auto-reloading functionality for development
- minijinja-py - Python bindings (requires Python development libraries)
- minijinja-js - JavaScript/WASM bindings
- examples/ - Various usage examples and demos
- benchmarks/ - Performance benchmarks
It's quite likely that this project is checked out as minijinja. Do not confuse minijinja with minijinja/minijinja in that case.
# Build entire workspace
make build
# Run comprehensive test suite (slow)
make test
# Run tests for core library only (always test all features!)
cargo test -p minijinja --all-features# Format code
make format
# Run linting with clippy
make lint
# Check various feature combinations
make check# Build and run CLI
cd minijinja-cli
cargo run -- template.j2 data.json
# Example usage
cargo run -- examples/hello.j2 examples/hello.json
echo "Hello {{ name }}" | cargo run -- - -Dname=World- compiler/ - Lexer, parser, AST, and bytecode generation
lexer.rs- Tokenizes template source codeparser.rs- Builds AST from tokenscodegen.rs- Generates bytecode from AST
- vm/ - Virtual machine for executing compiled templates
state.rs- Execution state and context management*_object.rs- Runtime objects (loops, macros, etc.)
- value/ - Value system and type conversions
mod.rs- Core Value enum and operationsobject.rs- Dynamic object trait for custom typesserialize.rs/deserialize.rs- Serde integration
- environment.rs - Main API entry point for template loading
- template.rs - Compiled template representation
- filters.rs, functions.rs, tests.rs - Built-in functionality
- Lexing - Source code → tokens
- Parsing - Tokens → AST
- Compilation - AST → bytecode instructions
- Execution - VM interprets bytecode with runtime context
- Feature-gated compilation - Different features can be enabled/disabled via Cargo features
- Zero-copy where possible - Uses
Cow<str>and borrowed data structures - Serde integration - All value types work with serde serialization
- Error handling - Rich error messages with source location tracking
/minijinja/tests/- Integration tests with snapshot testing/minijinja/tests/inputs/- Template files for testing/minijinja/tests/snapshots/- Expected outputs (insta snapshots)- Unit tests are embedded in source files
The project extensively tests different feature combinations:
# Test minimal feature set
cd minijinja && cargo test --no-default-features --features=debug
# Test with performance optimizations
cd minijinja && cargo test --no-default-features --features=speedups
# Test specific feature combinations
cd minijinja && cargo test --features=json,urlencode,custom_syntaxUses the insta crate for snapshot testing. When tests fail due to output changes:
cargo insta test --accept # accept changes
cargo insta test --reject # reject changesThe project uses extensive feature gating. Key features:
builtins,macros,multi_template- Core functionalityjson,urlencode- Additional filtersloader- Template loading from filesystemcustom_syntax- Custom delimitersspeedups- Performance optimizationsdebug- Debug functionality
Currently Rust 1.70+. The CI tests against this version.
The CLI supports multiple data formats:
- JSON (.json, .json5)
- YAML (.yaml, .yml)
- TOML (.toml)
- Query strings (.qs)
- INI files (.ini)
- CBOR (.cbor)
- Standard Rust targets
- WebAssembly (WASI)
- Python bindings (via PyO3)
- JavaScript/Node.js bindings (via wasm-bindgen)
- Add implementation in
filters.rsorfunctions.rs - Add tests in the same file
- Update documentation
- Add snapshot tests if needed
- Update lexer tokens if needed (
compiler/tokens.rs) - Modify parser for new syntax (
compiler/parser.rs) - Update AST definitions (
compiler/ast.rs) - Add bytecode generation (
compiler/codegen.rs) - Implement VM execution (
vm/mod.rs)
# Run specific test files
cd minijinja && cargo test --test test_filters
cd minijinja && cargo test --test test_templates
# Run specific test by name
cd minijinja && cargo test test_function_name -- --nocapture- Follow conventional commit format
- Always run
make lintandmake formatbefore committing - Ensure tests pass with
make test
- Make sure the next release is mentioned in CHANGELOG.md
- Use
scripts/bump-version.sh VERSIONto update all references to the next version - Create a commit for that release and push the tags
- Workflow Recommendations:
- Please do not use
cargo insta review. it fucks you up because it prompts.
- Please do not use