1use std::path::PathBuf;
4
5use once_cell::sync::Lazy;
6
7pub static CRATE_ROOT: Lazy<PathBuf> = Lazy::new(|| env!("CARGO_MANIFEST_DIR").into());
9
10pub static HOME: Lazy<PathBuf> = Lazy::new(|| {
15 let path = std::env::var_os("HOME").expect("could not determine home directory");
16 PathBuf::from(path)
17});
18
19pub const DATE_FORMAT_SLUG: &str = "%Y-%m-%d-%H%M%S";
21
22pub const DATE_FORMAT_TEMPLATE: &str = "%Y-%m-%d";
24
25#[allow(clippy::doc_markdown)]
32pub static UNICODE_TO_ASCII_SYMBOLS: Lazy<Vec<(char, &str)>> = Lazy::new(|| {
33 [
34 ('‘', "'"),
35 ('’', "'"),
36 ('“', "\""),
37 ('”', "\""),
38 ('»', "<<"),
39 ('«', ">>"),
40 ('…', "..."),
41 ('–', "--"),
42 ('—', "---"),
43 ]
44 .into_iter()
45 .collect()
46});
47
48#[cfg(test)]
49pub(crate) mod test {
50
51 use super::*;
52
53 pub static EXAMPLE_TEMPLATES: Lazy<PathBuf> = Lazy::new(|| {
55 let mut path = CRATE_ROOT.to_owned();
56 path.push("templates");
57 path
58 });
59
60 pub static TEST_TEMPLATES: Lazy<PathBuf> = Lazy::new(|| {
64 let mut path = CRATE_ROOT.to_owned();
65 path.extend(["data", "templates"].iter());
66 path
67 });
68
69 #[derive(Debug, Copy, Clone)]
71 #[allow(missing_docs)]
72 pub enum TemplatesDirectory {
73 ValidConfig,
74 ValidContext,
75 ValidFilter,
76 ValidSyntax,
77 InvalidConfig,
78 InvalidContext,
79 InvalidFilter,
80 InvalidSyntax,
81 }
82
83 impl std::fmt::Display for TemplatesDirectory {
84 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
85 match self {
86 Self::ValidConfig => write!(f, "valid-config"),
87 Self::ValidContext => write!(f, "valid-context"),
88 Self::ValidFilter => write!(f, "valid-filter"),
89 Self::ValidSyntax => write!(f, "valid-syntax"),
90 Self::InvalidConfig => write!(f, "invalid-config"),
91 Self::InvalidContext => write!(f, "invalid-context"),
92 Self::InvalidFilter => write!(f, "invalid-filter"),
93 Self::InvalidSyntax => write!(f, "invalid-syntax"),
94 }
95 }
96 }
97
98 impl From<TemplatesDirectory> for PathBuf {
99 fn from(directory: TemplatesDirectory) -> Self {
100 TEST_TEMPLATES.join(directory.to_string())
101 }
102 }
103}