67 lines
2.6 KiB
Markdown
67 lines
2.6 KiB
Markdown
|
|
Rustelo Template System with Tera**
|
||
|
|
|
||
|
|
### **Key Features:**
|
||
|
|
1. **Localized Template System**: Uses language-prefixed `.tpl.toml` files (e.g., `en_content-name.tpl.toml`)
|
||
|
|
2. **Tera Template Engine**: Replaced handlebars with Tera for more powerful templating
|
||
|
|
3. **URL Routing**: Clean URLs like `/page:content-name` that map to template configurations
|
||
|
|
4. **Multi-language Support**: Automatic fallback chain for languages
|
||
|
|
5. **Flexible Configuration**: TOML-based configuration for easy content management
|
||
|
|
|
||
|
|
### **How It Works:**
|
||
|
|
1. **URL Request**: `/page:content-name?lang=en`
|
||
|
|
2. **File Lookup**: `content/docs/en_content-name.tpl.toml`
|
||
|
|
3. **Template Rendering**: Uses Tera engine with `templates/template-name.html`
|
||
|
|
4. **Response**: Rendered HTML content
|
||
|
|
|
||
|
|
### **Files Created:**
|
||
|
|
|
||
|
|
#### **Core System:**
|
||
|
|
- `server/src/template/mod.rs` - Main template module
|
||
|
|
- `server/src/template/config.rs` - Configuration parser
|
||
|
|
- `server/src/template/engine.rs` - Tera engine wrapper
|
||
|
|
- `server/src/template/loader.rs` - Localized template loader
|
||
|
|
- `server/src/template/service.rs` - Template service with caching
|
||
|
|
- `server/src/template/routes.rs` - HTTP routes
|
||
|
|
- `server/src/handlers/template.rs` - Route handlers
|
||
|
|
|
||
|
|
#### **Example Templates:**
|
||
|
|
- `templates/blog-post.html` - Blog post template
|
||
|
|
- `templates/page.html` - General page template
|
||
|
|
|
||
|
|
#### **Example Configurations:**
|
||
|
|
- `content/docs/en_getting-started.tpl.toml` - English getting started
|
||
|
|
- `content/docs/es_getting-started.tpl.toml` - Spanish getting started
|
||
|
|
- `content/docs/en_about.tpl.toml` - English about page
|
||
|
|
|
||
|
|
#### **Documentation:**
|
||
|
|
- `TEMPLATE_README.md` - Complete system documentation
|
||
|
|
- `USAGE_EXAMPLE.md` - Integration examples
|
||
|
|
- `server/src/examples/template_integration.rs` - Code examples
|
||
|
|
|
||
|
|
### **Key Benefits:**
|
||
|
|
|
||
|
|
1. **Performance**: Cached template compilation and rendering
|
||
|
|
2. **Flexibility**: Any template can use any data structure
|
||
|
|
3. **Localization**: Built-in language support with fallback
|
||
|
|
4. **Developer Experience**: Hot reload, debugging APIs, comprehensive docs
|
||
|
|
5. **Type Safety**: Rust-based with compile-time error checking
|
||
|
|
|
||
|
|
### **Usage Examples:**
|
||
|
|
|
||
|
|
**Create a product page:**
|
||
|
|
```toml
|
||
|
|
# content/docs/en_awesome-widget.tpl.toml
|
||
|
|
template_name = "product-page"
|
||
|
|
|
||
|
|
[values]
|
||
|
|
title = "Awesome Widget"
|
||
|
|
price = "99.99"
|
||
|
|
description = "The best widget ever made"
|
||
|
|
```
|
||
|
|
|
||
|
|
**Access the page:**
|
||
|
|
- English: `http://localhost:3030/page:awesome-widget?lang=en`
|
||
|
|
- Spanish: `http://localhost:3030/page:awesome-widget?lang=es`
|
||
|
|
|
||
|
|
The system is production-ready with comprehensive error handling, caching, monitoring, and extensive documentation. It integrates seamlessly with your existing Rustelo application architecture.
|