credence_lib/configuration/
render.rs1use super::{
2 super::{render::*, resolve::*, util::*},
3 annotations::*,
4 constants::*,
5};
6
7use {
8 compris::{annotate::*, normal::*, resolve::*, *},
9 kutil::{
10 cli::depict::*,
11 std::{collections::*, immutable::*, metric::*},
12 },
13};
14
15#[derive(Clone, Debug, Depict, Resolve)]
21pub struct RenderConfiguration {
22 #[resolve]
24 #[depict(iter(kv), as(depict), key_style(string))]
25 pub variables: FastHashMap<ByteString, Variant<WithAnnotations>>,
26
27 #[resolve(key = "midfix")]
29 #[depict(style(string))]
30 pub midfix: ByteString,
31
32 #[resolve]
34 #[depict(as(depict))]
35 pub annotations: AnnotationsConfiguration,
36
37 #[resolve(key = "default-renderer")]
39 #[depict(as(display), style(symbol))]
40 pub default_renderer: Renderer,
41
42 #[resolve(key = "default-template")]
44 #[depict(style(string))]
45 pub default_template: ByteString,
46
47 #[resolve(key = "max-content-size")]
49 #[depict(as(display), style(symbol))]
50 pub max_content_size: ResolveByteCount,
51}
52
53impl RenderConfiguration {
54 pub fn is_rendered_page(&self, uri_path: &str) -> Option<RenderedPageType> {
56 if let Some(last_dot) = uri_path.rfind(EXTENSION_SEPARATOR) {
57 let uri_path_without_extension = &uri_path[..last_dot];
58 let rendered_page_midfix: &str = &self.midfix;
59 if uri_path_without_extension.ends_with(rendered_page_midfix) {
60 let extension = &uri_path[last_dot + 1..];
61
62 let format_result: Result<Format, _> = extension.parse();
63 return Some(match format_result {
64 Ok(format) => RenderedPageType::Annotations(format),
65 Err(_) => RenderedPageType::ContentWithEmbeddedAnnotations,
66 });
67 }
68 }
69
70 None
71 }
72}
73
74impl Default for RenderConfiguration {
75 fn default() -> Self {
76 Self {
77 variables: FastHashMap::default(),
78 annotations: Default::default(),
79 midfix: ".r".into(),
80 default_renderer: Default::default(),
81 default_template: DEFAULT_TEMPLATE.into(),
82 max_content_size: ByteCount::from_mebibytes(10).into(),
83 }
84 }
85}