move formatting to shared lib

This commit is contained in:
mbecker20
2024-06-15 17:15:05 -07:00
parent 207ea52b95
commit f956e12e28
13 changed files with 35 additions and 28 deletions

10
lib/formatting/Cargo.toml Normal file
View File

@@ -0,0 +1,10 @@
[package]
name = "formatting"
version.workspace = true
edition.workspace = true
authors.workspace = true
license.workspace = true
repository.workspace = true
homepage.workspace = true
[dependencies]

32
lib/formatting/src/lib.rs Normal file
View File

@@ -0,0 +1,32 @@
pub fn muted(content: impl std::fmt::Display) -> String {
format!("<span class=\"text-muted-foreground\">{content}</span>")
}
pub fn bold(content: impl std::fmt::Display) -> String {
format!("<span class=\"font-bold\">{content}</span>")
}
pub fn colored(
content: impl std::fmt::Display,
color: Color,
) -> String {
format!("<span class=\"{color}\">{content}</span>")
}
pub enum Color {
Red,
Green,
Blue,
}
impl std::fmt::Display for Color {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Color::Red => f.write_str("text-red-700 dark:text-red-400"),
Color::Green => {
f.write_str("text-green-700 dark:text-green-400")
}
Color::Blue => f.write_str("text-blue-700 dark:text-blue-400"),
}
}
}