diff --git a/REQUIREMENTS.md b/REQUIREMENTS.md index 97b80d8..0f11ed7 100644 --- a/REQUIREMENTS.md +++ b/REQUIREMENTS.md @@ -76,7 +76,7 @@ slhx competes with React by making frontend frameworks unnecessary for most apps 005 Error messages must explain fixes in author language, not internal language. Say “add `h-key="todo.id"` to this `h-for`”, not “missing ScopeKey for ResourceRef”. ### req: dx/006 -006 Generated resource methods are the preferred authoring API: `slots::todo_list.render(view)`, `slots::card.replace(key, view)`, `slots::count.text(42)`, `atoms::user.set(user)`. The public facade and generated view modules expose `render(view)` for trusted hemplate-to-`SafeHtml` page and fragment composition; `render_html(view)` remains as an explicit compatibility alias. These return `impl IntoEffect` or `SafeHtml` at the boundary. Raw `Effect` constructors, opcodes, and `EffectWriter` remain low-level. [north_star] +006 Generated resource methods are the preferred authoring API: `slots::todo_list.render(view)`, `slots::card.replace(key, view)`, `slots::count.text(42)`, `atoms::user.set(user)`. The public facade and generated view modules expose `render(view)` for trusted hemplate-to-`SafeHtml` page and fragment composition, plus `lower(html)` for prototype/static `.heml` fragments that need generated resource lowering; `render_html(view)` and `lower_html(html)` remain explicit compatibility aliases. These return `impl IntoEffect`, `SafeHtml`, or lowered HTML at the boundary. Raw `Effect` constructors, opcodes, and `EffectWriter` remain low-level. [north_star] ### req: dx/007 007 Tuple composition of `IntoEffect` is the canonical batch syntax: `(a, b, c)` implements `IntoEffect` up to arity 12. `Effect::batch((...))` is available but not required for the happy path. diff --git a/examples/v0/src/main.rs b/examples/v0/src/main.rs index 43cea4c..00dc685 100644 --- a/examples/v0/src/main.rs +++ b/examples/v0/src/main.rs @@ -181,12 +181,12 @@ fn registry(state: Arc) -> HandlerRegistry { fn all_examples() -> String { [ - counter::lower_html(include_str!("../templates/counter.heml")), - todos::lower_html(include_str!("../templates/todos.heml")), - wizard::lower_html(include_str!("../templates/wizard.heml")), - auth::lower_html(include_str!("../templates/auth.heml")), + counter::lower(include_str!("../templates/counter.heml")), + todos::lower(include_str!("../templates/todos.heml")), + wizard::lower(include_str!("../templates/wizard.heml")), + auth::lower(include_str!("../templates/auth.heml")), render_page_swap("Welcome", "Welcome"), - notifications::lower_html(include_str!("../templates/notifications.heml")), + notifications::lower(include_str!("../templates/notifications.heml")), ] .join("\n") } diff --git a/slhx-build/src/lib.rs b/slhx-build/src/lib.rs index 0e5bbb6..26bdd7c 100644 --- a/slhx-build/src/lib.rs +++ b/slhx-build/src/lib.rs @@ -517,17 +517,18 @@ impl Resources { Some(component) => format!("__SLHX_LOWERING_TABLE_{}", component.to_ascii_uppercase()), None => "__SLHX_LOWERING_TABLE".to_string(), }; - out.push_str(&format!("\n{pad}pub fn lower_html(html: impl ::std::convert::AsRef) -> ::std::string::String {{\n")); + out.push_str(&format!("\n{pad}pub fn lower(html: impl ::std::convert::AsRef) -> ::std::string::String {{\n")); out.push_str(&format!("{pad} ")); if component.is_some() { out.push_str("super::"); } 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 lower_html(html: impl ::std::convert::AsRef) -> ::std::string::String {{ lower(html) }}\n\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} ::slhx::SafeHtml::trusted(lower(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 const new_todo")); assert!(generated.contains("pub mod todo")); assert!(generated.contains("pub const ALL_IDS")); + assert!(generated.contains("pub fn lower(html: impl ::std::convert::AsRef) -> ::std::string::String")); 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")); @@ -1365,6 +1367,7 @@ mod tests { let generated = std::fs::read_to_string(out.join("slhx.generated.rs")).unwrap(); 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: impl ::std::convert::AsRef) -> ::std::string::String")); 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"));