refactor(v0): use generated render helpers
Switch v0 page and payload composition to generated render_html helpers, removing the local render_template bridge while keeping the explicit full-page SafeHtml shell boundary. req: component/003 req: view/001 req: html_safety/002
This commit is contained in:
+11
-17
@@ -186,10 +186,11 @@ fn all_examples() -> String {
|
|||||||
|
|
||||||
fn shell(body: String) -> String {
|
fn shell(body: String) -> String {
|
||||||
// Explicit full-page shell composition boundary for already-rendered hemplate fragments.
|
// Explicit full-page shell composition boundary for already-rendered hemplate fragments.
|
||||||
// req: html_safety/002 req: view/001
|
// req: html_safety/002 req: view/001 req: component/003
|
||||||
render_template(&AppShell {
|
ui::render_html(&AppShell {
|
||||||
body: SafeHtml::trusted(body),
|
body: SafeHtml::trusted(body),
|
||||||
})
|
})
|
||||||
|
.into_string()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn todos_view(todos: &[Todo]) -> TodoItems {
|
fn todos_view(todos: &[Todo]) -> TodoItems {
|
||||||
@@ -206,24 +207,17 @@ fn todos_view(todos: &[Todo]) -> TodoItems {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn render_page_swap(title: &'static str, message: &'static str) -> String {
|
fn render_page_swap(title: &'static str, message: &'static str) -> String {
|
||||||
// req: html_safety/002 req: view/001
|
// req: html_safety/002 req: view/001 req: component/003
|
||||||
ui::page_swap::lower_html(render_template(&PageSwap {
|
ui::page_swap::render_html(&PageSwap {
|
||||||
content: render_docs_content(message),
|
content: render_docs_content(message),
|
||||||
title,
|
title,
|
||||||
}))
|
})
|
||||||
|
.into_string()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn render_docs_content(message: &'static str) -> SafeHtml {
|
fn render_docs_content(message: &'static str) -> SafeHtml {
|
||||||
// req: html_safety/002 req: view/001
|
// req: html_safety/002 req: view/001 req: component/003
|
||||||
slhx::render_html(&DocsContent { message })
|
ui::render_html(&DocsContent { message })
|
||||||
}
|
|
||||||
|
|
||||||
fn render_template(template: &impl Hemplate) -> String {
|
|
||||||
let mut html = String::new();
|
|
||||||
template
|
|
||||||
.render_into(&mut html)
|
|
||||||
.expect("v0 hemplate view renders");
|
|
||||||
html
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
@@ -297,7 +291,7 @@ mod tests {
|
|||||||
fn todos_payload_is_rendered_by_a_hemplate_view() {
|
fn todos_payload_is_rendered_by_a_hemplate_view() {
|
||||||
let todos = vec![Todo { id: 7, title: "<b>Ship v0</b>".to_owned() }];
|
let todos = vec![Todo { id: 7, title: "<b>Ship v0</b>".to_owned() }];
|
||||||
|
|
||||||
let html = slhx::render_html(&todos_view(&todos));
|
let html = ui::render_html(&todos_view(&todos));
|
||||||
let document = Html::parse_fragment(html.as_str());
|
let document = Html::parse_fragment(html.as_str());
|
||||||
let rows = document.select(&selector("li[data-key]")).collect::<Vec<_>>();
|
let rows = document.select(&selector("li[data-key]")).collect::<Vec<_>>();
|
||||||
assert_eq!(rows.len(), 1);
|
assert_eq!(rows.len(), 1);
|
||||||
@@ -309,7 +303,7 @@ mod tests {
|
|||||||
// req: html_safety/002 req: view/001 req: test/005
|
// req: html_safety/002 req: view/001 req: test/005
|
||||||
#[test]
|
#[test]
|
||||||
fn empty_todos_payload_is_rendered_by_a_hemplate_view() {
|
fn empty_todos_payload_is_rendered_by_a_hemplate_view() {
|
||||||
let html = slhx::render_html(&todos_view(&[]));
|
let html = ui::render_html(&todos_view(&[]));
|
||||||
let document = Html::parse_fragment(html.as_str());
|
let document = Html::parse_fragment(html.as_str());
|
||||||
let rows = document.select(&selector("li")).collect::<Vec<_>>();
|
let rows = document.select(&selector("li")).collect::<Vec<_>>();
|
||||||
assert_eq!(rows.len(), 1);
|
assert_eq!(rows.len(), 1);
|
||||||
|
|||||||
Reference in New Issue
Block a user