mas_templates/context/
branding.rs
1use std::sync::Arc;
8
9use minijinja::{
10 Value,
11 value::{Enumerator, Object},
12};
13
14#[derive(Debug, Clone, PartialEq, Eq)]
16pub struct SiteBranding {
17 server_name: Arc<str>,
18 policy_uri: Option<Arc<str>>,
19 tos_uri: Option<Arc<str>>,
20 imprint: Option<Arc<str>>,
21}
22
23impl SiteBranding {
24 #[must_use]
26 pub fn new(server_name: impl Into<Arc<str>>) -> Self {
27 Self {
28 server_name: server_name.into(),
29 policy_uri: None,
30 tos_uri: None,
31 imprint: None,
32 }
33 }
34
35 #[must_use]
37 pub fn with_policy_uri(mut self, policy_uri: impl Into<Arc<str>>) -> Self {
38 self.policy_uri = Some(policy_uri.into());
39 self
40 }
41
42 #[must_use]
44 pub fn with_tos_uri(mut self, tos_uri: impl Into<Arc<str>>) -> Self {
45 self.tos_uri = Some(tos_uri.into());
46 self
47 }
48
49 #[must_use]
51 pub fn with_imprint(mut self, imprint: impl Into<Arc<str>>) -> Self {
52 self.imprint = Some(imprint.into());
53 self
54 }
55}
56
57impl Object for SiteBranding {
58 fn get_value(self: &Arc<Self>, name: &Value) -> Option<Value> {
59 match name.as_str()? {
60 "server_name" => Some(self.server_name.clone().into()),
61 "policy_uri" => self.policy_uri.clone().map(Value::from),
62 "tos_uri" => self.tos_uri.clone().map(Value::from),
63 "imprint" => self.imprint.clone().map(Value::from),
64 _ => None,
65 }
66 }
67
68 fn enumerate(self: &Arc<Self>) -> Enumerator {
69 Enumerator::Str(&["server_name", "policy_uri", "tos_uri", "imprint"])
70 }
71}