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