feat(build): add concise render helper

Generate render(view) as the short page/fragment composition helper while keeping render_html(view) as an explicit compatibility alias, then move examples to the leaner happy path.

req: component/003

req: dx/006

req: view/001
This commit is contained in:
slhx agent
2026-06-01 23:09:34 +02:00
parent a8d4604da8
commit 0d4a643759
6 changed files with 28 additions and 25 deletions
+4 -1
View File
@@ -524,11 +524,12 @@ impl Resources {
}
out.push_str(&format!("__slhx_lower_html(html.as_ref(), &{table_name})\n"));
out.push_str(&format!("{pad}}}\n\n"));
out.push_str(&format!("{pad}pub fn render_html(view: &impl ::hemplate::Hemplate) -> ::slhx::SafeHtml {{\n"));
out.push_str(&format!("{pad}pub fn render(view: &impl ::hemplate::Hemplate) -> ::slhx::SafeHtml {{\n"));
out.push_str(&format!("{pad} let mut html = ::std::string::String::new();\n"));
out.push_str(&format!("{pad} ::hemplate::Hemplate::render_into(view, &mut html).expect(\"slhx hemplate view renders\");\n"));
out.push_str(&format!("{pad} ::slhx::SafeHtml::trusted(lower_html(html))\n"));
out.push_str(&format!("{pad}}}\n\n"));
out.push_str(&format!("{pad}pub fn render_html(view: &impl ::hemplate::Hemplate) -> ::slhx::SafeHtml {{ render(view) }}\n\n"));
self.push_lowering_table(out, component, indent, &table_name);
}
@@ -1298,6 +1299,7 @@ mod tests {
assert!(generated.contains("pub mod todo"));
assert!(generated.contains("pub const ALL_IDS"));
assert!(generated.contains("pub fn lower_html"));
assert!(generated.contains("pub fn render(view: &impl ::hemplate::Hemplate) -> ::slhx::SafeHtml"));
assert!(generated.contains("pub fn render_html(view: &impl ::hemplate::Hemplate) -> ::slhx::SafeHtml"));
assert!(generated.contains("data-slhx-slot"));
assert!(generated.contains("data-slhx-form"));
@@ -1364,6 +1366,7 @@ mod tests {
assert!(!generated.contains("\n#[allow(non_upper_case_globals)]\npub mod components"));
assert!(!generated.contains("\n#[allow(non_upper_case_globals)]\npub mod slots"));
assert!(generated.contains("\npub fn lower_html"));
assert!(generated.contains("\npub fn render(view: &impl ::hemplate::Hemplate) -> ::slhx::SafeHtml"));
assert!(generated.contains("\npub fn render_html(view: &impl ::hemplate::Hemplate) -> ::slhx::SafeHtml"));
assert!(generated.contains("pub mod todo"));
assert!(generated.contains(" pub const COMPONENT: ::slhx::ComponentRef = ::slhx::ComponentRef::new(\"todo\")"));