//! The Askama entry point for `quasi_basics::carousel`. //! //! The widget left for `quasi-basics` once three real pages had proved it, and //! this is the part that stayed: glue between a template's own frame type and //! the widget's. Called from `partials/carousel.html`, so all three call sites //! keep the macro they already have. //! //! Why the island wraps the region rather than being it: a custom element is //! what the browser re-upgrades after an htmx swap, which is the whole reason //! islands are custom elements, and the description emits a plain `
` //! because it has no idea this host prefixes its tags with `mnw-`. The template //! puts one around the other and both halves stay honest. use quasi_basics::Frame; use quasi_router::Node; /// The markup, for an Askama template to drop in. #[must_use] pub fn html(id: &str, items: &[crate::templates::CarouselFrame]) -> String { use quasi_axum::Serves as _; let node = Node::Region(quasi_basics::carousel( id, items.iter().map(|frame| { let mut built = Frame::new(&frame.image, &frame.alt); if let Some((w, h)) = frame.intrinsic { built = built.intrinsic(w, h); } match &frame.caption { Some(caption) => built.caption(caption), None => built, } }), )); // No shell: this is a fragment landing inside a document Askama already // built, which is exactly what `fragment` is for. quasi_webview::Webview::new().fragment(&node) } #[cfg(test)] mod tests { use crate::templates::CarouselFrame; /// What the widget guarantees is `quasi-basics`' to test, and it does. /// What is MNW's is that this conversion loses nothing on the way through, /// because it is the one place a template's frame becomes a widget's. #[test] fn a_template_frame_arrives_whole() { let html = super::html( "landing-shots", &[ CarouselFrame { image: "/a.png".into(), alt: "The library, mid-import".into(), caption: Some("Library".into()), intrinsic: Some((5120, 3412)), }, CarouselFrame { image: "/b.png".into(), alt: "A project page".into(), caption: None, intrinsic: None, }, ], ); assert!(html.contains(r#"data-widget="carousel""#), "{html}"); assert!(html.contains(r#"id="landing-shots""#), "{html}"); assert!(html.contains(r#"alt="The library, mid-import""#), "{html}"); assert!(html.contains("Library"), "{html}"); assert!(html.contains(r#"width="5120" height="3412""#), "{html}"); assert!(html.contains("/b.png"), "{html}"); } }