diff --git a/stdlib/src/web.rs b/stdlib/src/web.rs index 500b9235..d4578845 100644 --- a/stdlib/src/web.rs +++ b/stdlib/src/web.rs @@ -98,9 +98,7 @@ static PAGE_CONTENT: Mutex = Mutex::new(String::new()); fn render_children(html: &mut String, dsl: &techscript_runtime::value::DslBlockValue) { for child in &dsl.children { - html.push_str(&dsl_to_html( - &techscript_runtime::value::RuntimeValue::DslBlock(std::rc::Rc::new(child.clone())), - )); + html.push_str(&dsl_block_to_html(child)); } } @@ -234,129 +232,131 @@ fn render_card(html: &mut String, dsl: &techscript_runtime::value::DslBlockValue /// Convert a DslBlockValue tree to HTML string. fn dsl_to_html(val: &RuntimeValue) -> String { match val { - RuntimeValue::DslBlock(dsl) => { - let mut html = String::new(); - match dsl.kind.as_str() { - "website" => { - render_website(&mut html, dsl); - } - "page" => { - render_page(&mut html, dsl); - } - "hero" => { - render_hero(&mut html, dsl); - } - "section" => { - render_section(&mut html, dsl); - } - "card" => { - render_card(&mut html, dsl); - } - "button" => { - let label = dsl - .properties - .iter() - .find(|p| p.name == "label") - .and_then(|p| p.value.as_ref()) - .map(|v| v.to_string()) - .unwrap_or_else(|| "Button".to_string()); - let _ = write!(html, "", label); - } - "link" => { - let label = dsl - .properties - .iter() - .find(|p| p.name == "label") - .and_then(|p| p.value.as_ref()) - .map(|v| v.to_string()) - .unwrap_or_else(|| "Link".to_string()); - let url = dsl - .properties - .iter() - .find(|p| p.name == "url") - .and_then(|p| p.value.as_ref()) - .map(|v| v.to_string()); - if let Some(u) = url { - let _ = write!(html, "{}", u, label); - } else { - let _ = write!(html, "{}", label); - } - } - "nav" => { - html.push_str(""); - } - "header" => { - html.push_str("
"); - for prop in &dsl.properties { - if prop.name == "title" { - if let Some(RuntimeValue::Str(t)) = &prop.value { - let _ = write!(html, "

{}

", t); - } - } - } - render_children(&mut html, dsl); - html.push_str("
"); - } - "footer" => { - html.push_str(""); } - "input" => { - let placeholder = dsl - .properties - .iter() - .find(|p| p.name == "placeholder") - .and_then(|p| p.value.as_ref()) - .map(|v| v.to_string()); - if let Some(p) = placeholder { - let _ = write!(html, "", p); - } else { - html.push_str(""); + } + render_children(&mut html, dsl); + html.push_str(""); + } + "footer" => { + html.push_str(""); + } + "input" => { + let placeholder = dsl + .properties + .iter() + .find(|p| p.name == "placeholder") + .and_then(|p| p.value.as_ref()) + .map(|v| v.to_string()); + if let Some(p) = placeholder { + let _ = write!(html, "", p); + } else { + html.push_str(""); + } + } + "form" => { + html.push_str("
"); + render_children(&mut html, dsl); + html.push_str("
"); + } + "main" => { + html.push_str("
"); + render_children(&mut html, dsl); + html.push_str("
"); + } + "aside" => { + html.push_str(""); + } + "start" => { + let label = dsl + .properties + .iter() + .find(|p| p.name == "label") + .and_then(|p| p.value.as_ref()) + .map(|v| v.to_string()) + .unwrap_or_else(|| "Get Started".to_string()); + let _ = write!(html, "{}", label); + } + _ => { + let _ = write!(html, "", dsl.kind); } - _ => String::new(), } + html } impl StdlibRegistry {