htoml

HTML page templates described with a toml config
Log | Files | Refs | README

commit 59b6dffcb0fb5de2166b34de4dfcd3c819d58ef7
parent 39f592fac953e277fd9836344d57530c3fa3234c
Author: Jackson G. Kaindume <seestem@merely.tech>
Date:   Sat, 20 Aug 2022 23:46:41 +0200

add testimonial section

Diffstat:
Mexamples/frosh.toml | 14++++++++++++++
Msrc/sections/mod.rs | 9+++++++++
Asrc/sections/testimonial.rs | 57+++++++++++++++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 80 insertions(+), 0 deletions(-)

diff --git a/examples/frosh.toml b/examples/frosh.toml @@ -25,3 +25,17 @@ paragraph = "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiu [sections.gallery] variant = "frosh" entries = [{src="https://duckduckgo.com/assets/logo_homepage.alt.v108.svg"}, {src="https://duckduckgo.com/assets/logo_homepage.alt.v108.svg"}, {src="https://duckduckgo.com/assets/logo_homepage.alt.v108.svg"}, {src="https://duckduckgo.com/assets/logo_homepage.alt.v108.svg"}] + +[sections.testimonial] +variant = "frosh" +heading = "Testimonials" +entries = [ +{label = "A", image = "https://duckduckgo.com/assets/logo_homepage.alt.v108.svg"}, +{label = "B", image = "https://duckduckgo.com/assets/logo_homepage.alt.v108.svg"}, +{label = "C", image = "https://duckduckgo.com/assets/logo_homepage.alt.v108.svg"}, +{label = "D", image = "https://duckduckgo.com/assets/logo_homepage.alt.v108.svg"}, +{label = "E", image = "https://duckduckgo.com/assets/logo_homepage.alt.v108.svg"}, +{label = "F", image = "https://duckduckgo.com/assets/logo_homepage.alt.v108.svg"}, +{label = "G", image = "https://duckduckgo.com/assets/logo_homepage.alt.v108.svg"}, +{label = "H", image = "https://duckduckgo.com/assets/logo_homepage.alt.v108.svg"} +] diff --git a/src/sections/mod.rs b/src/sections/mod.rs @@ -5,6 +5,7 @@ pub mod about; pub mod gallery; pub mod hero; pub mod navbar; +pub mod testimonial; /// A section of an HTML webpage pub trait Section { @@ -33,6 +34,8 @@ pub struct Sections { pub about: Option<about::About>, /// Gallery Section pub gallery: Option<gallery::Gallery>, + /// Testimonial Section + pub testimonial: Option<testimonial::Testimonial>, } impl Sections { @@ -65,6 +68,12 @@ impl Sections { css = format!("{}{}", css, gallery_export.css); } + if let Some(testimonial) = &self.testimonial { + let testimonial_export = testimonial.export(metadata); + html = format!("{}{}", html, testimonial_export.html); + css = format!("{}{}", css, testimonial_export.css); + } + Export { html, css } } } diff --git a/src/sections/testimonial.rs b/src/sections/testimonial.rs @@ -0,0 +1,57 @@ +use crate::common::Export; +use crate::sections::{Section, SectionMetadata}; +use crate::slider::{Slide, Slider}; + +use serde::Deserialize; + +#[derive(Deserialize, Clone)] +pub struct Testimonial { + /// Variant of testimonial to use + pub variant: String, + /// Heading of about section + pub heading: String, + /// Testimonial entries + pub entries: Vec<Slide>, +} + +impl Section for Testimonial { + fn export(&self, metadata: &SectionMetadata) -> Export { + let mut html = "".to_string(); + let mut css = "".to_string(); + + match self.variant.as_str() { + "basic" => { + css = format!( + r#".htoml_testimonial{{ + padding: 2em; + color: {}; + }}"#, + metadata.tertiary_color + ); + + html = format!( + r#" + <section class='htoml_testimonial'> + <h3>{}<h3> + </section>"#, + self.heading, + ); + } + "frosh" => { + let slides = &self.entries; + return Slider::export(slides.to_vec()); + } + _ => panic!("Invalid Testimonial variant"), + } + Export { html, css } + } +} + +#[cfg(test)] +mod tests { + #[test] + fn it_works() { + let result = 2 + 2; + assert_eq!(result, 4); + } +}