Expand description
ยง๐ฎ Mystical-Runic - High-Performance Template Engine for Rust
Rust Compatibility: Requires Rust 1.74.0+ | Edition 2021 | Future Rust 2024 Ready
Mystical-Runic is a high-performance, zero-dependency templating engine for Rust that combines Mustache-inspired syntax with advanced features like template inheritance, macros, filters, enterprise-grade security, comprehensive developer tools, and ecosystem integration.
ยง๐ Key Features
- Zero Dependencies Core: No external dependencies for core functionality
- Enterprise Security: XSS protection, path traversal prevention, template injection security
- High Performance: Bytecode compilation, caching, parallel processing, memory mapping
- Developer Experience: Hot reload, debugging, IDE integration, intelligent error messages
- Ecosystem Integration: Async support, web framework integration, WASM compatibility, CLI tools
- Comprehensive Testing: 204+ tests with 100% coverage following strict TDD methodology
- Conventional & Mystical APIs: Choose your preferred naming style
ยง๐ Template Syntax Reference
| Feature | Syntax | Description |
|---|---|---|
| Variables | {{name}} | HTML-escaped variable output |
| Raw HTML | {{& html}} | Unescaped HTML output (use carefully) |
| Conditionals | {{if condition}}...{{/if}} | Conditional rendering with comparison operators |
| Loops | {{for item in items}}...{{/for}} | Iterate over arrays and nested structures |
| Deep Access | {{user.profile.name}} | Unlimited depth object property access |
| Includes | {{include "template.html"}} | Template composition and reuse |
| Comments | {{! comment }} | Template comments (not rendered) |
| Filters | {{value|upper|truncate:10}} | Transform output with filter chains |
| Macros | {{macro name(params)}}...{{/macro}} | Reusable template components |
| Inheritance | {{extend "layout.html"}} | Template inheritance system |
| Blocks | {{block content}}...{{/block}} | Replaceable content blocks |
| I18n | {{t "key" name=user}} | Internationalization with variables |
| Pluralization | {{plural count "item" "items"}} | Smart plural forms |
ยง๐ Quick Start Guide
๐ Documentation complรจte disponible :
- Documentation technique :
cargo doc --open --all-features- Guide utilisateur : Documentation HTML (franรงais)
- Rรฉfรฉrence en ligne : docs.rs/mystical-runic
Add to your Cargo.toml:
[dependencies]
mystical-runic = "0.5.2"
# Optional features for ecosystem integration
mystical-runic = { version = "0.5.2", features = ["async", "web-frameworks", "wasm", "cli"] }ยง๐ Optional Features
| Feature | Description | Dependencies |
|---|---|---|
async | Asynchronous template rendering with Tokio | tokio, futures |
axum-integration | Direct Axum framework support | axum, async |
warp-integration | Direct Warp framework support | warp, async |
actix-integration | Direct Actix-web framework support | actix-web, async |
web-frameworks | All web framework integrations | All above web features |
wasm | WebAssembly browser compatibility | wasm-bindgen, js-sys, web-sys |
cli | Command-line tools and utilities | clap, serde, serde_json, toml |
full | All ecosystem integration features | All optional features |
ยง๐งโโ๏ธ Usage Examples - Choose Your Style
ยงConventional Style
use mystical_runic::{TemplateEngine, TemplateContext, TemplateValue};
let mut engine = TemplateEngine::new("templates");
let mut context = TemplateContext::new();
context.set("user", TemplateValue::String("Developer".to_string()));
context.set("task", TemplateValue::String("Build Features".to_string()));
let result = engine.render_string(
"Hello {{user}}! Your mission: {{task}}",
&context
).unwrap();ยงMystical Style โจ
use mystical_runic::{RuneEngine, RuneScroll, RuneSymbol};
// Summon the ancient engine from the template realm
let mut engine = RuneEngine::new("sacred_scrolls");
let mut scroll = RuneScroll::new();
// Inscribe your desires upon the scroll
scroll.set("hero", RuneSymbol::String("Rust Developer".to_string()));
scroll.set("quest", RuneSymbol::String("Debug Production Issues".to_string()));
// Speak the incantation and witness the transformation
let result = engine.render_string(
"Behold! {{hero}} embarks upon {{quest}}! ๐ก๏ธ",
&scroll
).unwrap();ยง๐ Performance & Security
Performance Features:
- Template caching with smart invalidation
- Bytecode compilation for frequently-used templates
- Parallel template processing capabilities
- Memory-mapped file loading for large templates
- Optimized nested property traversal
Security Features:
- HTML escaping by default (XSS prevention)
- Path traversal protection (
../and absolute path blocking) - Template injection prevention
- Memory exhaustion protection
- Input validation and sanitization
ยง๐ ๏ธ Developer Experience
- Hot Reload: Automatic template recompilation during development
- Debug Mode: Variable tracking and execution analysis
- IDE Integration: LSP support with auto-completion and diagnostics
- Smart Suggestions: Intelligent template and variable suggestions
- Precise Errors: Line/column error reporting with context
- Performance Metrics: Built-in execution time measurement
ยง๐ Ecosystem Integration Examples
ยงAsync Template Rendering (requires async feature)
โ
use mystical_runic::{TemplateEngine, TemplateContext};
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let mut engine = TemplateEngine::new("templates");
let mut context = TemplateContext::new();
context.set_string("user", "Async Developer");
let result = engine.render_string_async(
"Hello {{user}}! Processing async request...",
&context
).await?;
println!("{}", result);
Ok(())
}ยงWeb Framework Integration (requires framework-specific features)
โ
// Axum Integration (requires `axum-integration` feature)
use axum::{response::Html, routing::get, Router};
use mystical_runic::{TemplateEngine, TemplateContext};
async fn render_page() -> Html<String> {
let mut engine = TemplateEngine::new("templates");
let mut context = TemplateContext::new();
context.set_string("title", "My Axum App");
let html = engine.render_string("<h1>{{title}}</h1>", &context).unwrap();
Html(html)
}ยงCLI Template Processing (requires cli feature)
โ
use mystical_runic::{process_template, batch_process};
fn main() -> Result<(), Box<dyn std::error::Error>> {
// Single template processing
let result = process_template("Hello {{name}}!", r#"{"name": "CLI User"}"#)?;
println!("{}", result);
// Batch processing multiple templates
let templates = vec!["template1.html", "template2.html"];
let context_json = r#"{"theme": "dark", "version": "0.5.2"}"#;
let results = batch_process(templates, context_json)?;
Ok(())
}Structsยง
- Browser
Rune Engine - WebAssembly rune engines (mystical aliases, requires
wasmfeature) JavaScript bindings for WASM - Cli
- Command-line tools and utilities (requires
clifeature) CLI command structure - CliConfig
- Command-line tools and utilities (requires
clifeature) CLI configuration structure - Completion
Item - Completion item for auto-completion
- Debug
Info - Debug information collected during template rendering
- Debug
Render Result - Result of template rendering with debug information
- Definition
Info - Definition location information
- Diagnostic
- Diagnostic information for error squiggles
- Ecosystem
Compatibility - Ecosystem compatibility information
- Execution
Step - Individual step in template execution
- Hover
Info - Hover information for variables
- LspParse
Result - LSP parsing result containing template analysis
- Performance
Metrics - Performance metrics for debugging
- Rune
Divination - Result of template rendering with debug information
- Rune
Engine - TemplateEngine - High-Performance Template Processing Engine
- Rune
Metrics - Performance metrics for debugging
- Rune
Response Error - Axum rune engine (mystical alias, requires
axum-integrationfeature) - Rune
Scroll - Template context containing variables for rendering
- Rune
Step - Individual step in template execution
- Rune
Trace - Debug information collected during template rendering
- Rune
Watcher - Command-line runic tools (mystical aliases, requires
clifeature) Template file watcher for auto-recompilation - Runic
Block - Template block information for LSP
- Runic
Cli - Command-line runic tools (mystical aliases, requires
clifeature) CLI command structure - Runic
Compatibility - Ecosystem compatibility information
- Runic
Completion - Completion item for auto-completion
- Runic
Config - Command-line runic tools (mystical aliases, requires
clifeature) CLI configuration structure - Runic
Diagnostic - Diagnostic information for error squiggles
- Runic
Lore - LSP parsing result containing template analysis
- Runic
Origin - Definition location information
- Runic
Token - Syntax highlighting token
- Runic
Wisdom - Hover information for variables
- Syntax
Token - Syntax highlighting token
- Template
Block - Template block information for LSP
- Template
Context - Template context containing variables for rendering
- Template
Engine - TemplateEngine - High-Performance Template Processing Engine
- Template
Response Error - Axum web framework integration (requires
axum-integrationfeature) - Template
Watcher - Command-line tools and utilities (requires
clifeature) Template file watcher for auto-recompilation - Wasm
Rune Engine - WebAssembly browser compatibility (requires
wasmfeature) JavaScript bindings for WASM
Enumsยง
- Commands
- Command-line tools and utilities (requires
clifeature) - Rune
Error - Template engine error type with enhanced developer experience
- Rune
Symbol - Template value types that can be used in templates
- Runic
Commands - Command-line runic tools (mystical aliases, requires
clifeature) - Template
Error - Template engine error type with enhanced developer experience
- Template
Value - Template value types that can be used in templates
Traitsยง
- Actix
Rune Engine - Actix rune engine (mystical alias, requires
actix-integrationfeature) Actix-web response extension for TemplateEngine - Actix
Template Engine - Actix-web framework integration (requires
actix-integrationfeature) Actix-web response extension for TemplateEngine - Async
Rune Engine - Async rune engine (mystical alias, requires
asyncfeature) Async extension trait for TemplateEngine - Async
Template Engine - Async template engine support (requires
asyncfeature) Async extension trait for TemplateEngine - Axum
Rune Engine - Axum rune engine (mystical alias, requires
axum-integrationfeature) Axum response extension for TemplateEngine - Axum
Template Engine - Axum web framework integration (requires
axum-integrationfeature) Axum response extension for TemplateEngine - Ecosystem
Rune Engine - Extension trait to add ecosystem compatibility to TemplateEngine
- Ecosystem
Template Engine - Extension trait to add ecosystem compatibility to TemplateEngine
- Warp
Rune Engine - Warp rune engine (mystical alias, requires
warp-integrationfeature) Warp response extension for TemplateEngine - Warp
Template Engine - Warp web framework integration (requires
warp-integrationfeature) Warp response extension for TemplateEngine - Wasm
Rune Engine Trait - WebAssembly rune engines (mystical aliases, requires
wasmfeature) WASM-specific template engine extensions - Wasm
Template Engine - WebAssembly browser compatibility (requires
wasmfeature) WASM-specific template engine extensions
Functionsยง
- batch_
process - Command-line tools and utilities (requires
clifeature) Batch process multiple templates - load_
config - Command-line tools and utilities (requires
clifeature) Load CLI configuration from TOML - process_
files - Command-line tools and utilities (requires
clifeature) Process template and data files - process_
template - Command-line tools and utilities (requires
clifeature) Process a template string with JSON data
Type Aliasesยง
- Ancient
Helper - Custom helper function type
- Filter
Function - Custom filter function type
- Helper
Function - Custom helper function type
- Mystic
Filter - Custom filter function type
- Rune
Result - Template engine result type
- Template
Result - Template engine result type