simple_list/
simple_list.rs1use html_export::{
2 composed::list::{from_iterator, AsList, ListType},
3 export_to_file,
4 head::Head,
5 li,
6};
7
8use html_export::elem;
9use html_export::element::*;
10use html_export::tags::*;
11
12pub struct Person {
13 name: String,
14 age: u8,
15 country: String,
16}
17
18impl Person {
19 pub fn new(name: String, age: u8, country: String) -> Self {
20 Self { name, age, country }
21 }
22}
23
24impl AsList for Person {
25 fn to_list_item(
26 &self,
27 mode: &html_export::composed::list::ListType,
28 ) -> Option<html_export::element::Element> {
29 match mode {
30 ListType::Ordered | ListType::Unordered => Some(
31 li!()
32 + Element::Text(format!(
33 "Name: {}, Age: {}, Country: {}",
34 self.name, self.age, self.country
35 )),
36 ),
37 ListType::TermDefinition => None,
38 }
39 }
40
41 fn to_definition_list_item(&self) -> Option<(Element, Element)> {
42 None
43 }
44}
45
46fn main() {
47 let persons = vec![
48 Person::new("Johns James".to_string(), 20, "France".to_string()),
49 Person::new("Smith Jennifer".to_string(), 30, "England".to_string()),
50 Person::new("Brown Robert".to_string(), 40, "Australia".to_string()),
51 Person::new("Taylor Mary".to_string(), 50, "South Africa".to_string()),
52 ];
53 let ul_list = from_iterator(
54 &persons,
55 &ListType::Unordered,
56 HtmlElementConfig::new_empty(),
57 )
58 .unwrap();
59
60 let ol_list =
61 from_iterator(&persons, &ListType::Ordered, HtmlElementConfig::new_empty()).unwrap();
62 let head = Head::new().with_title("Simple list".to_string());
63 export_to_file(
64 "examples_output".to_string(),
65 "simple_list.html".to_string(),
66 head,
67 vec![ul_list, ol_list],
68 )
69 .unwrap();
70}