Rustelo/info/template_system_with_tera.md
Jesús Pérex 2f0f807331 feat: add dark mode functionality and improve navigation system
- Add complete dark mode system with theme context and toggle
- Implement dark mode toggle component in navigation menu
- Add client-side routing with SSR-safe signal handling
- Fix language selector styling for better dark mode compatibility
- Add documentation system with mdBook integration
- Improve navigation menu with proper external/internal link handling
- Add comprehensive project documentation and configuration
- Enhance theme system with localStorage persistence
- Fix arena panic issues during server-side rendering
- Add proper TypeScript configuration and build optimizations

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-07-11 20:53:20 +01:00

2.6 KiB

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:

# 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.