about.rs (2031B)
1 use crate::common::Export; 2 use crate::sections::{Section, SectionMetadata}; 3 use serde::Deserialize; 4 5 #[derive(Deserialize, Clone)] 6 pub struct About { 7 /// Variant of about to use 8 pub variant: String, 9 /// Heading of about section 10 pub heading: String, 11 /// Paragraph text 12 pub paragraph: String, 13 } 14 15 impl Section for About { 16 fn export(&self, metadata: &SectionMetadata) -> Export { 17 let mut html = "".to_string(); 18 let mut css = "".to_string(); 19 20 match self.variant.as_str() { 21 "basic" => { 22 css = format!( 23 r#".htoml_about{{ 24 margin-top: 0; 25 padding: 2em; 26 color: {}; 27 }}"#, 28 metadata.tertiary_color 29 ); 30 31 html = format!( 32 r#" 33 <section class='htoml_about'> 34 <h3>{}<h3> 35 <p>{}</p> 36 </section>"#, 37 self.heading, self.paragraph 38 ); 39 } 40 "frosh" => { 41 css = format!( 42 r#".htoml_about{{ 43 margin-top: 0; 44 padding: 2em; 45 color: {}; 46 }} 47 48 .htoml_about p{{ 49 font-size: 1.7em; 50 }} 51 "#, 52 metadata.secondary_color 53 ); 54 html = format!( 55 r#" 56 <section class='htoml_about'> 57 <h3>{}</h3> 58 <p>{}</p> 59 </section>"#, 60 self.heading, self.paragraph 61 ); 62 } 63 _ => panic!("Invalid About variant"), 64 } 65 Export { html, css } 66 } 67 } 68 69 #[cfg(test)] 70 mod tests { 71 #[test] 72 fn it_works() { 73 let result = 2 + 2; 74 assert_eq!(result, 4); 75 } 76 }