From 5bcae0a0758e13e89ab9d29e4286ae8bf67ef7b9 Mon Sep 17 00:00:00 2001 From: slhx agent Date: Mon, 25 May 2026 21:58:18 +0200 Subject: [PATCH] refactor(v0): render keyed row with hemplate Move the v0 keyed todo row effect payload from Rust format! HTML into a hemplate partial and require the generated slot append to carry an HTML payload. req: html_safety/002 req: view/001 --- examples/v0/src/lib.rs | 22 +++++++++++++++++--- examples/v0/templates/partials/todo_row.heml | 1 + 2 files changed, 20 insertions(+), 3 deletions(-) create mode 100644 examples/v0/templates/partials/todo_row.heml diff --git a/examples/v0/src/lib.rs b/examples/v0/src/lib.rs index 95f17e1..a126aad 100644 --- a/examples/v0/src/lib.rs +++ b/examples/v0/src/lib.rs @@ -4,7 +4,8 @@ pub mod ui {} #[cfg(test)] mod tests { use super::ui; - use slhx::{push, Effect, IntoEffect, NavigateMode}; + use hemplate::Hemplate; + use slhx::{push, Effect, IntoEffect, NavigateMode, Payload, SafeHtml}; use slhx_test::inspect; #[derive(Clone, Debug)] @@ -29,6 +30,12 @@ mod tests { password: String, } + #[derive(Hemplate)] + #[hemplate = "partials"] + struct TodoRow { + title: String, + } + // req: examples/001 req: ceremony/001 req: build/001 req: build/005 req: codegen/002 #[test] fn counter_updates_a_generated_slot() { @@ -47,13 +54,22 @@ mod tests { fn todos_append_keyed_rows_from_form_input() { fn add_todo(input: TodoInput) -> impl IntoEffect { let todo = Todo { id: 7, title: input.title }; - ui::slots::todo_row.append(todo.id.to_string(), format!("
  • {}
  • ", todo.title)) + ui::slots::todo_row.append_html(todo.id.to_string(), render_todo_row(&todo)) } let effect = inspect(add_todo(TodoInput { title: "Ship v0".into() })); assert!(effect.has_resource(ui::slots::todo_row.id())); - assert!(matches!(effect.ops(), [Effect::Insert { key, .. }] if key == "7")); + assert!(matches!(effect.ops(), [Effect::Insert { key, payload, .. }] if key == "7" && matches!(payload, Payload::Html(_)))); + } + + fn render_todo_row(todo: &Todo) -> SafeHtml { + // req: html_safety/002 req: view/001 + SafeHtml::trusted( + TodoRow { title: todo.title.clone() } + .render() + .expect("v0 todo row renders"), + ) } // req: examples/001 req: progressive_disclosure/001 req: build/001 req: build/005 req: codegen/004 diff --git a/examples/v0/templates/partials/todo_row.heml b/examples/v0/templates/partials/todo_row.heml new file mode 100644 index 0000000..94dda32 --- /dev/null +++ b/examples/v0/templates/partials/todo_row.heml @@ -0,0 +1 @@ +
  • {+ self.title +}