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
This commit is contained in:
slhx agent
2026-05-25 21:58:18 +02:00
parent 58e96162d4
commit 5bcae0a075
2 changed files with 20 additions and 3 deletions
+19 -3
View File
@@ -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!("<li>{}</li>", 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
@@ -0,0 +1 @@
<li>{+ self.title +}</li>