lib_humus/
query_settings.rs

1
2use tera::Context;
3
4use crate::HumusFormat;
5
6/// Provides context from the query for use in the [HumusEngine].
7///
8/// Its main job is the provide the requested [HumusFormat]
9/// so that the Engine knows which output to produce.
10///
11/// Example implementation:
12/// ```
13/// use lib_humus::HumusQuerySettings;
14/// use lib_humus::HtmlTextJsonFormat;
15///
16/// // Reuse the HtmlTextJsonFormat for now.
17/// pub type ExampleResponseFormat = HtmlTextJsonFormat;
18/// 
19/// #[derive(Clone)]
20/// pub struct ExampleQuerySettings {
21/// 	pub response_format: ExampleResponseFormat,
22/// }
23/// 
24/// impl HumusQuerySettings<ExampleResponseFormat> for ExampleQuerySettings {
25/// 	fn get_format(&self) -> ExampleResponseFormat {
26/// 		return self.response_format.clone();
27/// 	}
28/// }
29/// ```
30/// 
31/// [HumusEngine]: ./struct.HumusEngine.html
32/// [HumusFormat]: ./trait.HumusFormat.html
33pub trait HumusQuerySettings<F>: Clone
34where F: HumusFormat {
35
36	/// Called before rendering a template to initalize it with
37	/// values that come from the query itself.
38	///
39	/// 📖 Remember to document which values you set here in a place someone who
40	/// wants to do something with templating is able to find it.
41	///
42	/// The default implementation does nothing.
43	fn initalize_template_context(&self, _context: &mut Context) {}
44
45	/// Returns the requested output format.
46	fn get_format(&self) -> F;
47
48}