diff --git a/examples/v0/src/main.rs b/examples/v0/src/main.rs index ee33c58..f86205f 100644 --- a/examples/v0/src/main.rs +++ b/examples/v0/src/main.rs @@ -43,6 +43,11 @@ struct PageSwap { title: &'static str, } +#[derive(Hemplate)] +struct AppShell { + body: SafeHtml, +} + #[derive(Hemplate)] #[hemplate = "partials"] struct DocsContent { @@ -180,28 +185,10 @@ fn all_examples() -> String { } fn shell(body: String) -> String { - format!( - r#" - -
- - -Try the counter, todo form, wizard, login, page swap, and live SSE notifications.
- {body} - -"# - ) + // req: html_safety/002 req: view/001 + render_template(&AppShell { + body: SafeHtml::trusted(body), + }) } fn render_todos(todos: &[Todo]) -> SafeHtml { @@ -247,6 +234,23 @@ mod tests { Selector::parse(value).expect("test selector parses") } + // req: html_safety/002 req: view/001 req: test/005 + #[test] + fn shell_is_rendered_by_a_hemplate_view() { + let html = shell(render_page_swap("Welcome", "Welcome")); + let document = Html::parse_document(&html); + assert_eq!( + document + .select(&selector("title")) + .next() + .map(|title| title.text().collect::Try the counter, todo form, wizard, login, page swap, and live SSE notifications.
+ {+= self.body =+} + +