Make responsibility for converting a theme to a css class to the theme module

This commit is contained in:
Magnus Hovland Hoff 2018-09-18 19:43:33 +02:00
parent d4e8277f2a
commit c1dcb1de64
2 changed files with 22 additions and 1 deletions

View file

@ -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");
}
}

View file

@ -9,7 +9,7 @@
<link href="_assets/{{style_css()}}" rel="stylesheet">
<meta name="generator" content="{{project_name()}} {{version()}}" />
</head>
<body class="theme-{{theme()}}">
<body class="{{#theme().}}{{.css_class()}}{{/theme()}}">
{{>search_input.html}}
{{{body}}}
</body>