1.2 KiB · text History d76cd01
pub mod auth;
pub mod config;
pub mod entities;
pub mod handlers;
pub mod middleware;
pub mod render;

pub use config::{create_db_connection, Config};

use minijinja::Environment;
use std::sync::Arc;

/// Human-facing application name. Injected into every template as the
/// `app_name` global (see `build_environment`). Set at generation time from
/// the `app_title` cargo-generate prompt.
pub const APP_NAME: &str = "BISMUTH";

/// Shared, cheaply-clonable state handed to every axum handler.
#[derive(Clone)]
pub struct AppState {
    pub env: Environment<'static>,
    pub db: Arc<sea_orm::DatabaseConnection>,
    pub config: Arc<Config>,
}

/// Build the minijinja environment: embedded templates (baked in by build.rs)
/// plus, in debug builds, a path loader so edits under `templates/` show up
/// on the next request without a rebuild. `app_name` is exposed as a global
/// so templates can render the brand without every handler passing it.
pub fn build_environment() -> Environment<'static> {
    let mut env = Environment::new();
    minijinja_embed::load_templates!(&mut env);
    #[cfg(debug_assertions)]
    env.set_loader(minijinja::path_loader("templates"));
    env.add_global("app_name", APP_NAME);
    env
}