esi/config.rs
1/// This struct is used to configure optional behaviour within the ESI processor.
2///
3/// ## Usage Example
4/// ```rust,no_run
5/// let config = esi::Configuration::default()
6/// .with_namespace("app");
7/// ```
8#[allow(clippy::return_self_not_must_use)]
9#[derive(Clone, Debug)]
10pub struct Configuration {
11 /// The XML namespace to use when scanning for ESI tags. Defaults to `esi`.
12 pub namespace: String,
13 /// For working with non-HTML ESI templates, e.g. JSON files, this option allows you to disable the unescaping of URLs
14 pub is_escaped_content: bool,
15}
16
17impl Default for Configuration {
18 fn default() -> Self {
19 Self {
20 namespace: String::from("esi"),
21 is_escaped_content: true,
22 }
23 }
24}
25
26impl Configuration {
27 /// Sets an alternative ESI namespace, which is used to identify ESI instructions.
28 ///
29 /// For example, setting this to `test` would cause the processor to only match tags like `<test:include>`.
30 pub fn with_namespace(mut self, namespace: impl Into<String>) -> Self {
31 self.namespace = namespace.into();
32 self
33 }
34 /// For working with non-HTML ESI templates, eg JSON files, allows to disable URLs unescaping
35 pub fn with_escaped(mut self, is_escaped: impl Into<bool>) -> Self {
36 self.is_escaped_content = is_escaped.into();
37 self
38 }
39}