From c1dcb1de647da473888b41811c813d31d0c706af Mon Sep 17 00:00:00 2001 From: Magnus Hovland Hoff Date: Tue, 18 Sep 2018 19:43:33 +0200 Subject: [PATCH] Make responsibility for converting a theme to a css class to the theme module --- src/theme.rs | 21 +++++++++++++++++++++ templates/layout.html | 2 +- 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/src/theme.rs b/src/theme.rs index 1f9e77d..847c143 100644 --- a/src/theme.rs +++ b/src/theme.rs @@ -38,6 +38,22 @@ pub fn theme_from_str(x: &str) -> Theme { THEMES[choice] } +pub struct CssClass(Theme); + +impl Theme { + pub fn css_class(self) -> CssClass { + CssClass(self) + } +} + +use std::fmt::{self, Display, Formatter}; + +impl Display for CssClass { + fn fmt(&self, fmt: &mut Formatter) -> fmt::Result { + write!(fmt, "theme-{}", self.0) + } +} + #[cfg(test)] mod test { use super::*; @@ -74,4 +90,9 @@ mod test { fn from_str() { assert_eq!(theme_from_str("Bartefjes"), Theme::Orange); } + + #[test] + fn css_class_display() { + assert_eq!(&Theme::Red.css_class().to_string(), "theme-red"); + } } diff --git a/templates/layout.html b/templates/layout.html index 2123814..e1c8ee3 100644 --- a/templates/layout.html +++ b/templates/layout.html @@ -9,7 +9,7 @@ - + {{>search_input.html}} {{{body}}}