diff --git a/contrib/src/templates/engine.rs b/contrib/src/templates/engine.rs index 0136c4b161..55f84a0218 100644 --- a/contrib/src/templates/engine.rs +++ b/contrib/src/templates/engine.rs @@ -15,9 +15,9 @@ pub trait Engine: Send + Sync + 'static { pub struct Engines { #[cfg(feature = "tera_templates")] - tera: Tera, + pub tera: Tera, #[cfg(feature = "handlebars_templates")] - handlebars: Handlebars, + pub handlebars: Handlebars, } impl Engines { diff --git a/contrib/src/templates/mod.rs b/contrib/src/templates/mod.rs index a2756ac515..89f0dac815 100644 --- a/contrib/src/templates/mod.rs +++ b/contrib/src/templates/mod.rs @@ -15,6 +15,7 @@ use self::glob::glob; use std::borrow::Cow; use std::path::{Path, PathBuf}; +use std::marker::{Send, Sync}; use rocket::State; use rocket::request::Request; @@ -158,7 +159,11 @@ impl Template { /// } /// ``` pub fn fairing() -> impl Fairing { - AdHoc::on_attach(|rocket| { + Template::fairing_with(|_context| ()) + } + + pub fn fairing_with(callback: F) -> impl Fairing where F: Fn(&mut Context) + Send + Sync + 'static { + AdHoc::on_attach(move |rocket| { let mut template_root = rocket.config() .root_relative(DEFAULT_TEMPLATE_DIR); @@ -172,7 +177,10 @@ impl Template { }; match Context::initialize(template_root) { - Some(ctxt) => Ok(rocket.manage(ctxt)), + Some(mut context) => { + callback(&mut context); + Ok(rocket.manage(context)) + }, None => Err(rocket) } })