| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
use quasi_basics::{Frame, Gallery}; |
| 15 |
use quasi_declare::declare; |
| 16 |
|
| 17 |
use crate::templates::CarouselFrame; |
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
fn frame(source: &CarouselFrame) -> Frame { |
| 26 |
let sized = match source.intrinsic { |
| 27 |
Some((width, height)) => Frame::new(&source.image, &source.alt).intrinsic(width, height), |
| 28 |
None => Frame::new(&source.image, &source.alt), |
| 29 |
}; |
| 30 |
match &source.caption { |
| 31 |
Some(caption) => sized.caption(caption), |
| 32 |
None => sized, |
| 33 |
} |
| 34 |
} |
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
fn gallery(items: &[CarouselFrame]) -> Gallery { |
| 41 |
items.iter().map(frame).collect() |
| 42 |
} |
| 43 |
|
| 44 |
declare! { |
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
#[must_use] |
| 51 |
pub shape region(id: &str, items: &[CarouselFrame]) -> Node; |
| 52 |
|
| 53 |
include quasi_basics::carousel(id, &gallery(items)); |
| 54 |
} |
| 55 |
|
| 56 |
|
| 57 |
#[must_use] |
| 58 |
pub fn html(id: &str, items: &[CarouselFrame]) -> String { |
| 59 |
use quasi_axum::Serves as _; |
| 60 |
|
| 61 |
let node = region(id, items); |
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
quasi_webview::Webview::new().fragment(&node) |
| 66 |
} |
| 67 |
|
| 68 |
#[cfg(test)] |
| 69 |
mod tests { |
| 70 |
use crate::templates::CarouselFrame; |
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
|
| 75 |
#[test] |
| 76 |
fn a_template_frame_arrives_whole() { |
| 77 |
let html = super::html( |
| 78 |
"landing-shots", |
| 79 |
&[ |
| 80 |
CarouselFrame { |
| 81 |
image: "/a.png".into(), |
| 82 |
alt: "The library, mid-import".into(), |
| 83 |
caption: Some("Library".into()), |
| 84 |
intrinsic: Some((5120, 3412)), |
| 85 |
}, |
| 86 |
CarouselFrame { |
| 87 |
image: "/b.png".into(), |
| 88 |
alt: "A project page".into(), |
| 89 |
caption: None, |
| 90 |
intrinsic: None, |
| 91 |
}, |
| 92 |
], |
| 93 |
); |
| 94 |
|
| 95 |
assert!(html.contains(r#"data-widget="carousel""#), "{html}"); |
| 96 |
assert!(html.contains(r#"id="landing-shots""#), "{html}"); |
| 97 |
assert!(html.contains(r#"alt="The library, mid-import""#), "{html}"); |
| 98 |
assert!(html.contains("Library</figcaption>"), "{html}"); |
| 99 |
assert!(html.contains(r#"width="5120" height="3412""#), "{html}"); |
| 100 |
assert!(html.contains("/b.png"), "{html}"); |
| 101 |
} |
| 102 |
} |
| 103 |
|