Skip to main content

actix_web_admin/
lib.rs

1//! # actix-admin
2//! 
3//! A powerful admin panel library for Actix-web 4 applications that automatically generates CRUD interfaces.
4//! 
5//! ## Quick Start
6//! 
7//! ```rust,no_run
8//! use actix_web_admin::{AdminRegistry, AdminSite, AdminResource, init_templates};
9//! use async_trait::async_trait;
10//! use std::collections::HashMap;
11//! use std::sync::{Arc, Mutex};
12//! 
13//! #[actix_web::main]
14//! async fn main() -> std::io::Result<()> {
15//!     let templates = init_templates();
16//!     let mut registry = AdminRegistry::new();
17//!     // Register your resources...
18//!     
19//!     HttpServer::new(move || {
20//!         App::new()
21//!             .app_data(web::Data::new(templates.clone()))
22//!             .configure(|cfg| {
23//!                 AdminSite::new("/admin").mount(cfg, registry)
24//!             })
25//!     })
26//!     .bind(("127.0.0.1", 8080))?
27//!     .run()
28//!     .await
29//! }
30//! ```
31
32pub mod resource;
33pub mod registry;
34pub mod site;
35pub mod types;
36pub mod handlers;
37
38pub use resource::AdminResource;
39pub use registry::AdminRegistry;
40pub use site::AdminSite;
41
42use tera::Tera;
43use std::sync::Arc;
44
45/// Helper to create a Tera instance with embedded templates.
46pub fn init_templates() -> Tera {
47    let mut tera = Tera::default();
48    
49    tera.add_raw_template("base.html", include_str!("templates/base.html")).unwrap();
50    tera.add_raw_template("login.html", include_str!("templates/login.html")).unwrap();
51    tera.add_raw_template("dashboard.html", include_str!("templates/dashboard.html")).unwrap();
52    tera.add_raw_template("list.html", include_str!("templates/list.html")).unwrap();
53    tera.add_raw_template("form.html", include_str!("templates/form.html")).unwrap();
54    
55    tera
56}
57
58pub type AdminTemplates = Arc<Tera>;