-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathenums.rs
More file actions
45 lines (38 loc) · 1.18 KB
/
Copy pathenums.rs
File metadata and controls
45 lines (38 loc) · 1.18 KB
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
use anyhow::Context as _;
use serde::Serialize;
use tinytemplate::TinyTemplate;
use super::ToHtml;
const ENUM_TEMPLATE: &str = r#"
<div class="enum">
<div class="enum-name">{name}</div>
<div class="enum-variants">
{{ for variant in variants }}
<div class="enum-variant">
<div class="enum-variant-name">{variant.name}</div>
{{ if variant.data }}
<div class="enum-variant-data">{variant.data}</div>
{{ endif }}
</div>
{{ endfor }}
</div>
</div>
"#;
#[derive(Serialize)]
pub struct EnumContext {
pub name: String,
pub variants: Vec<EnumVariantContext>,
}
#[derive(Serialize)]
pub struct EnumVariantContext {
pub name: String,
pub data: Option<String>,
}
impl ToHtml for EnumContext {
fn to_html(&self) -> anyhow::Result<String> {
let mut tt = TinyTemplate::new();
tt.set_default_formatter(&tinytemplate::format_unescaped);
tt.add_template("enum", ENUM_TEMPLATE)
.context("Failed to add template")?;
tt.render("enum", self).context("Failed to render template")
}
}