1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
//! # SnapFire
//!
//! An ergonomic Tera templating engine with live-reload, featuring first-class
//! support for Actix Web.
//!
//! ## Features
//!
//! - **Simple API:** A clean builder pattern for easy setup.
//! - **Full Context Control:** Pass a `tera::Context` directly to the render method.
//! - **Global Variables:** Define site-wide variables available to all templates.
//! - **Live Reload (Dev Mode):** Changes to templates or static files (like CSS) are
//! automatically streamed to the browser without a full page refresh.
//! - **Production Optimized:** All development features are completely compiled out
//! in release builds for zero overhead.
//!
//! ## Quickstart
//!
//! This example demonstrates how to set up a simple Actix Web server with `snapfire`.
//!
//! ```rust,no_run
//! use actix_web::{web, App, HttpServer, Responder};
//! use snapfire::{TeraWeb, Template};
//! use tera::Context;
//!
//! // An Actix handler that renders a template.
//! async fn index(app_state: web::Data<TeraWeb>) -> impl Responder {
//! let mut context = Context::new();
//! context.insert("page_title", "Welcome");
//! // The `render` method returns a `Template` struct which is a Responder.
//! app_state.render("index.html", context)
//! }
//!
//! #[actix_web::main]
//! async fn main() -> std::io::Result<()> {
//! // Build the SnapFire app state.
//! let app_state = TeraWeb::builder("templates/**/*.html")
//! .add_global("site_name", "My Awesome Site")
//! // In dev mode, also watch the static directory for CSS changes.
//! .watch_static("static")
//! .build()
//! .expect("Failed to build TeraWeb app");
//!
//! HttpServer::new(move || {
//! App::new()
//! .app_data(web::Data::new(app_state.clone()))
//! // The middleware injects the reload script in dev mode.
//! .wrap(snapfire::actix::dev::InjectSnapFireScript::default())
//! .route("/", web::get().to(index))
//! // The configure method adds the WebSocket route in dev mode.
//! .configure(|cfg| app_state.configure_routes(cfg))
//! })
//! .bind(("127.0.0.1", 3000))?
//! .run()
//! .await
//! }
//! ```
//!
//! ### Production Builds
//!
//! To build your application for production
//!
//! ```sh
//! cargo build --release
//! ```
pub use crate;
pub use crate;