lib-humus 0.5.0

Helps creating configurable frontends for humans and computers using axum, Tera and toml.
use tera::Context;

use crate::HumusFormat;

/// Provides context from the query for use in the [HumusEngine].
///
/// Its main job is the provide the requested [HumusFormat]
/// so that the Engine knows which output to produce.
///
/// Example implementation:
/// ```
/// use lib_humus::HumusQuerySettings;
/// use lib_humus::HtmlTextJsonFormat;
///
/// // Reuse the HtmlTextJsonFormat for now.
/// pub type ExampleResponseFormat = HtmlTextJsonFormat;
///
/// #[derive(Clone)]
/// pub struct ExampleQuerySettings {
/// 	pub response_format: ExampleResponseFormat,
/// }
///
/// impl HumusQuerySettings<ExampleResponseFormat> for ExampleQuerySettings {
/// 	fn get_format(&self) -> ExampleResponseFormat {
/// 		return self.response_format.clone();
/// 	}
/// }
/// ```
///
/// [HumusEngine]: ./struct.HumusEngine.html
/// [HumusFormat]: ./trait.HumusFormat.html
pub trait HumusQuerySettings<F>: Clone
where
    F: HumusFormat,
{
    /// Called before rendering a template to initalize it with
    /// values that come from the query itself.
    ///
    /// 📖 Remember to document which values you set here in a place someone who
    /// wants to do something with templating is able to find it.
    ///
    /// The default implementation does nothing.
    fn initalize_template_context(&self, _context: &mut Context) {}

    /// Returns the requested output format.
    fn get_format(&self) -> F;
}