Make responsibility for converting a theme to a css class to the theme module
This commit is contained in:
parent
d4e8277f2a
commit
c1dcb1de64
2 changed files with 22 additions and 1 deletions
21
src/theme.rs
21
src/theme.rs
|
@ -38,6 +38,22 @@ pub fn theme_from_str(x: &str) -> Theme {
|
||||||
THEMES[choice]
|
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)]
|
#[cfg(test)]
|
||||||
mod test {
|
mod test {
|
||||||
use super::*;
|
use super::*;
|
||||||
|
@ -74,4 +90,9 @@ mod test {
|
||||||
fn from_str() {
|
fn from_str() {
|
||||||
assert_eq!(theme_from_str("Bartefjes"), Theme::Orange);
|
assert_eq!(theme_from_str("Bartefjes"), Theme::Orange);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn css_class_display() {
|
||||||
|
assert_eq!(&Theme::Red.css_class().to_string(), "theme-red");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,7 +9,7 @@
|
||||||
<link href="_assets/{{style_css()}}" rel="stylesheet">
|
<link href="_assets/{{style_css()}}" rel="stylesheet">
|
||||||
<meta name="generator" content="{{project_name()}} {{version()}}" />
|
<meta name="generator" content="{{project_name()}} {{version()}}" />
|
||||||
</head>
|
</head>
|
||||||
<body class="theme-{{theme()}}">
|
<body class="{{#theme().}}{{.css_class()}}{{/theme()}}">
|
||||||
{{>search_input.html}}
|
{{>search_input.html}}
|
||||||
{{{body}}}
|
{{{body}}}
|
||||||
</body>
|
</body>
|
||||||
|
|
Loading…
Reference in a new issue