From 58e96162d4d7a0f4d34269fa05cbb420b556687d Mon Sep 17 00:00:00 2001 From: slhx agent Date: Mon, 25 May 2026 21:54:04 +0200 Subject: [PATCH] refactor(v0): render shell with hemplate Move the v0 page shell from a Rust format! raw HTML string into a hemplate AppShell view and cover the rendered document structure with scraper. req: html_safety/002 req: view/001 req: test/005 --- examples/v0/src/main.rs | 48 +++++++++++++++------------- examples/v0/templates/app_shell.heml | 20 ++++++++++++ 2 files changed, 46 insertions(+), 22 deletions(-) create mode 100644 examples/v0/templates/app_shell.heml 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#" - - - - - slhx v0 examples - - - - -

slhx v0 browser examples

-

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::()), + Some("slhx v0 examples".to_owned()) + ); + assert_eq!(document.select(&selector("script[src=\"/slhx.js\"]")).count(), 1); + assert_eq!(document.select(&selector("main[data-slhx-root=\"docs\"]")).count(), 1); + assert!(!html.contains("{+=")); + } + // req: html_safety/002 req: view/001 req: test/005 #[test] fn docs_content_payload_is_rendered_by_a_hemplate_view() { diff --git a/examples/v0/templates/app_shell.heml b/examples/v0/templates/app_shell.heml new file mode 100644 index 0000000..dadb28b --- /dev/null +++ b/examples/v0/templates/app_shell.heml @@ -0,0 +1,20 @@ + + + + + + slhx v0 examples + + + + +

slhx v0 browser examples

+

Try the counter, todo form, wizard, login, page swap, and live SSE notifications.

+ {+= self.body =+} + +