use std::path::PathBuf;
use once_cell::sync::Lazy;
pub static CRATE_ROOT: Lazy<PathBuf> = Lazy::new(|| env!("CARGO_MANIFEST_DIR").into());
pub static HOME: Lazy<PathBuf> = Lazy::new(|| {
let path = std::env::var_os("HOME").expect("could not determine home directory");
PathBuf::from(path)
});
pub const DATE_FORMAT_SLUG: &str = "%Y-%m-%d-%H%M%S";
pub const DATE_FORMAT_TEMPLATE: &str = "%Y-%m-%d";
#[allow(clippy::doc_markdown)]
pub static UNICODE_TO_ASCII_SYMBOLS: Lazy<Vec<(char, &str)>> = Lazy::new(|| {
[
('‘', "'"),
('’', "'"),
('“', "\""),
('”', "\""),
('»', "<<"),
('«', ">>"),
('…', "..."),
('–', "--"),
('—', "---"),
]
.into_iter()
.collect()
});
#[cfg(test)]
pub(crate) mod test {
use super::*;
pub static EXAMPLE_TEMPLATES: Lazy<PathBuf> = Lazy::new(|| {
let mut path = CRATE_ROOT.to_owned();
path.push("templates");
path
});
pub static TEST_TEMPLATES: Lazy<PathBuf> = Lazy::new(|| {
let mut path = CRATE_ROOT.to_owned();
path.extend(["data", "templates"].iter());
path
});
#[derive(Debug, Copy, Clone)]
#[allow(missing_docs)]
pub enum TemplatesDirectory {
ValidConfig,
ValidContext,
ValidFilter,
ValidSyntax,
InvalidConfig,
InvalidContext,
InvalidFilter,
InvalidSyntax,
}
impl std::fmt::Display for TemplatesDirectory {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Self::ValidConfig => write!(f, "valid-config"),
Self::ValidContext => write!(f, "valid-context"),
Self::ValidFilter => write!(f, "valid-filter"),
Self::ValidSyntax => write!(f, "valid-syntax"),
Self::InvalidConfig => write!(f, "invalid-config"),
Self::InvalidContext => write!(f, "invalid-context"),
Self::InvalidFilter => write!(f, "invalid-filter"),
Self::InvalidSyntax => write!(f, "invalid-syntax"),
}
}
}
impl From<TemplatesDirectory> for PathBuf {
fn from(directory: TemplatesDirectory) -> Self {
TEST_TEMPLATES.join(directory.to_string())
}
}
}