1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
use super::*;
use yaml_peg::serde::Stringify;
#[derive(serde::Deserialize)]
#[serde(untagged)]
pub enum Background {
Color(String),
Img(ImgBackground),
}
impl Default for Background {
fn default() -> Self {
Self::Img(ImgBackground::default())
}
}
impl ToHtml for Background {
fn to_html(self, _ctx: &Ctx) -> String {
match self {
Background::Color(color) => color.wrap(" data-background-color=\"", "\""),
Background::Img(img) => img.to_html(_ctx),
}
}
}
#[derive(Default, serde::Deserialize)]
#[serde(default)]
pub struct ImgBackground {
pub src: String,
pub size: Stringify,
pub position: String,
pub repeat: String,
pub opacity: Stringify,
}
impl ToHtml for ImgBackground {
fn to_html(self, _ctx: &Ctx) -> String {
let Self { src, size, position, repeat, opacity } = self;
if src.is_empty() {
String::new()
} else {
format!(" data-background=\"{}\"", src)
+ &size.to_string().wrap(" data-background-size=\"", "\"")
+ &position.wrap(" data-background-position=\"", "\"")
+ &repeat.wrap(" data-background-repeat=\"", "\"")
+ &opacity
.to_string()
.wrap(" data-background-opacity=\"", "\"")
}
}
}