rustapi_view/lib.rs
1//! # rustapi-view
2//!
3//! Template rendering support for the RustAPI framework using Tera templates.
4//!
5//! This crate provides server-side HTML rendering with type-safe template contexts,
6//! layout inheritance, and development-friendly features like auto-reload.
7//!
8//! ## Features
9//!
10//! - **Tera Templates**: Full Tera template engine support with filters, macros, and inheritance
11//! - **Type-Safe Context**: Build template context from Rust structs via serde
12//! - **Auto-Reload**: Development mode can auto-reload templates on change
13//! - **Response Types**: `View<T>` response type for rendering templates
14//! - **Layout Support**: Template inheritance with blocks
15//!
16//! ## Quick Start
17//!
18//! ```rust,ignore
19//! use rustapi_rs::prelude::*;
20//! use rustapi_view::{View, Templates};
21//! use serde::Serialize;
22//!
23//! #[derive(Serialize)]
24//! struct HomeContext {
25//! title: String,
26//! user: Option<String>,
27//! }
28//!
29//! async fn home(templates: State<Templates>) -> View<HomeContext> {
30//! View::render(&templates, "home.html", HomeContext {
31//! title: "Welcome".to_string(),
32//! user: Some("Alice".to_string()),
33//! })
34//! }
35//!
36//! #[tokio::main]
37//! async fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
38//! let templates = Templates::new("templates/**/*.html")?;
39//!
40//! RustApi::new()
41//! .state(templates)
42//! .route("/", get(home))
43//! .run("127.0.0.1:8080")
44//! .await
45//! }
46//! ```
47
48#![warn(missing_docs)]
49#![warn(rustdoc::missing_crate_level_docs)]
50
51mod error;
52mod templates;
53mod view;
54mod context;
55
56pub use error::ViewError;
57pub use templates::{Templates, TemplatesConfig};
58pub use view::View;
59pub use context::ContextBuilder;
60
61// Re-export tera types that users might need
62pub use tera::Context;
63
64/// Prelude module for convenient imports
65pub mod prelude {
66 pub use crate::{
67 Context,
68 ContextBuilder,
69 Templates,
70 TemplatesConfig,
71 View,
72 ViewError,
73 };
74}