pub mod ext; pub mod init; pub mod run; /// Add the template file at the given path to the given [`minijinja::Environment`]. #[macro_export] macro_rules! add_minijinja_template { ($mj:ident, $path:literal) => { log::trace!("Adding template to minijinja Environment: {:?} ← {:#?}", $mj, $path); $mj.add_template($path, include_str!($path)) .expect(concat!("Invalid Minijinja template: ", $path)); log::trace!("Added template to minijinja Environment: {:?} ← {:#?}", $mj, $path); }; } /// Add the given route to the [`axum::Router`]. #[macro_export] macro_rules! add_axum_route { ($router:ident, $path:literal, $route:expr) => { log::trace!("Adding route to axum Router: {:?} ← {:#?}", $router, $path); let $router = $router.route($path, $route); log::trace!("Added route to axum Router: {:?} ← {:#?}", $router, $path); }; } #[macro_export] macro_rules! web_server { ( on: $socket_addr:expr, templates: [ $( $template_path:literal ),+ ], routes: { $( $path:literal => $route:expr ),+ } ) => { $crate::init::init_logging(); let listener = $crate::init::init_listener($socket_addr).await; let mut mj = $crate::init::init_minijinja(); $( $crate::add_minijinja_template!(mj, $template_path); )+ let router = $crate::init::init_router(mj); $( $crate::add_axum_route!(router, $path, $route); )+ $crate::run::run_server(listener, router).await }; }