feat(build): add concise lower helper
Generate lower(html) as the short static/prototype fragment lowering helper while keeping lower_html(html) as the compatibility alias, then move the v0 page assembly to the leaner path. req: dx/006 req: component/003
This commit is contained in:
+1
-1
@@ -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”.
|
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
|
### 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
|
### 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.
|
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.
|
||||||
|
|||||||
@@ -181,12 +181,12 @@ fn registry(state: Arc<ExampleState>) -> HandlerRegistry {
|
|||||||
|
|
||||||
fn all_examples() -> String {
|
fn all_examples() -> String {
|
||||||
[
|
[
|
||||||
counter::lower_html(include_str!("../templates/counter.heml")),
|
counter::lower(include_str!("../templates/counter.heml")),
|
||||||
todos::lower_html(include_str!("../templates/todos.heml")),
|
todos::lower(include_str!("../templates/todos.heml")),
|
||||||
wizard::lower_html(include_str!("../templates/wizard.heml")),
|
wizard::lower(include_str!("../templates/wizard.heml")),
|
||||||
auth::lower_html(include_str!("../templates/auth.heml")),
|
auth::lower(include_str!("../templates/auth.heml")),
|
||||||
render_page_swap("Welcome", "Welcome"),
|
render_page_swap("Welcome", "Welcome"),
|
||||||
notifications::lower_html(include_str!("../templates/notifications.heml")),
|
notifications::lower(include_str!("../templates/notifications.heml")),
|
||||||
]
|
]
|
||||||
.join("\n")
|
.join("\n")
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -517,17 +517,18 @@ impl Resources {
|
|||||||
Some(component) => format!("__SLHX_LOWERING_TABLE_{}", component.to_ascii_uppercase()),
|
Some(component) => format!("__SLHX_LOWERING_TABLE_{}", component.to_ascii_uppercase()),
|
||||||
None => "__SLHX_LOWERING_TABLE".to_string(),
|
None => "__SLHX_LOWERING_TABLE".to_string(),
|
||||||
};
|
};
|
||||||
out.push_str(&format!("\n{pad}pub fn lower_html(html: impl ::std::convert::AsRef<str>) -> ::std::string::String {{\n"));
|
out.push_str(&format!("\n{pad}pub fn lower(html: impl ::std::convert::AsRef<str>) -> ::std::string::String {{\n"));
|
||||||
out.push_str(&format!("{pad} "));
|
out.push_str(&format!("{pad} "));
|
||||||
if component.is_some() {
|
if component.is_some() {
|
||||||
out.push_str("super::");
|
out.push_str("super::");
|
||||||
}
|
}
|
||||||
out.push_str(&format!("__slhx_lower_html(html.as_ref(), &{table_name})\n"));
|
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}}}\n\n"));
|
||||||
|
out.push_str(&format!("{pad}pub fn lower_html(html: impl ::std::convert::AsRef<str>) -> ::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}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} 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} ::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}}}\n\n"));
|
||||||
out.push_str(&format!("{pad}pub fn render_html(view: &impl ::hemplate::Hemplate) -> ::slhx::SafeHtml {{ render(view) }}\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);
|
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 const new_todo"));
|
||||||
assert!(generated.contains("pub mod todo"));
|
assert!(generated.contains("pub mod todo"));
|
||||||
assert!(generated.contains("pub const ALL_IDS"));
|
assert!(generated.contains("pub const ALL_IDS"));
|
||||||
|
assert!(generated.contains("pub fn lower(html: impl ::std::convert::AsRef<str>) -> ::std::string::String"));
|
||||||
assert!(generated.contains("pub fn lower_html"));
|
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(view: &impl ::hemplate::Hemplate) -> ::slhx::SafeHtml"));
|
||||||
assert!(generated.contains("pub fn render_html(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();
|
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 components"));
|
||||||
assert!(!generated.contains("\n#[allow(non_upper_case_globals)]\npub mod slots"));
|
assert!(!generated.contains("\n#[allow(non_upper_case_globals)]\npub mod slots"));
|
||||||
|
assert!(generated.contains("\npub fn lower(html: impl ::std::convert::AsRef<str>) -> ::std::string::String"));
|
||||||
assert!(generated.contains("\npub fn lower_html"));
|
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(view: &impl ::hemplate::Hemplate) -> ::slhx::SafeHtml"));
|
||||||
assert!(generated.contains("\npub fn render_html(view: &impl ::hemplate::Hemplate) -> ::slhx::SafeHtml"));
|
assert!(generated.contains("\npub fn render_html(view: &impl ::hemplate::Hemplate) -> ::slhx::SafeHtml"));
|
||||||
|
|||||||
Reference in New Issue
Block a user