🔷 Tron
A powerful, composable template system for Rust
Tron is a modern template engine that brings composability and type safety to code generation. Build and compose templates with confidence, execute them with rust-script, and generate Rust code dynamically.
✨ Features
- 🧩 Composable Templates - Nest and combine templates seamlessly
- 🎯 Type-Safe - Catch template errors at compile time
- 🔌 rust-script Integration - Execute generated code directly
- 📦 Dependency Management - Handle external crate dependencies gracefully
- 🛠 Rich Tooling - Comprehensive error handling and debugging
🚀 Quick Start
Add Tron to your project:
[]
= "0.1.0"
[]
= []
= ["tempfile", "which"] # Optional: For rust-script support
Create your first template:
use ;
// Create a template
let mut template = new?;
let mut template_ref = new;
// Set values
template_ref.set?;
template_ref.set?;
// Render
let code = template_ref.render?;
🎭 Template Composition
Tron shines when composing templates:
// Create a module template
let mut module = new?;
// Create a function template
let mut function = new?;
// Compose them
let mut module_ref = new;
let mut function_ref = new;
function_ref.set?;
function_ref.set?;
module_ref.set?;
module_ref.set_ref?;
// Renders:
// mod generated {
// fn example() {
// println!("Composed!");
// }
// }
🎯 Key Concepts
Templates
Templates are the building blocks of Tron. They use a simple @[placeholder]@ syntax:
let template = new?;
Template References
TronRef wraps templates with additional capabilities:
let template_ref = new
.with_dependency;
Template Assembly
Combine multiple templates with TronAssembler:
let mut assembler = new;
assembler.add_template;
assembler.add_template;
assembler.add_template;
let combined = assembler.render_all?;
📚 Documentation
Visit our documentation for:
- Detailed API reference
- Advanced usage examples
- Best practices
- Tutorial guides
🔧 VSCode Extension
Tron includes a VSCode extension for enhanced template editing:
Features
- Syntax Highlighting - Full support for
.tronand.tplfiles - Smart Autocompletion - Placeholder suggestions and snippets
- Template Validation - Real-time error detection and linting
- Live Preview - See rendered templates instantly
Installation
The extension is located in the tron_vscode/ directory. To install:
Configuration
The extension provides several configuration options:
Note: Trailing whitespace checking is disabled by default to prevent false positives. Enable it only if needed for your specific use case.
🤝 Contributing
We welcome contributions! Check out our Contributing Guide to get started.
- Fork the repository
- Create a feature branch
- Submit a pull request
📝 License
Tron is MIT licensed. See LICENSE for details.