(children: &Element)
| 68 | } |
| 69 | |
| 70 | fn extract_single_text_node(children: &Element) -> Result<String, ExtractSingleTextNodeError<'_>> { |
| 71 | let vnode = match children { |
| 72 | Element::Ok(vnode) => vnode, |
| 73 | Element::Err(err) => { |
| 74 | return Err(ExtractSingleTextNodeError::RenderError(err)); |
| 75 | } |
| 76 | }; |
| 77 | // The title's children must be in one of two forms: |
| 78 | // 1. rsx! { "static text" } |
| 79 | // 2. rsx! { "title: {dynamic_text}" } |
| 80 | match vnode.template { |
| 81 | // rsx! { "static text" } |
| 82 | Template { |
| 83 | roots: &[TemplateNode::Text { text }], |
| 84 | node_paths: &[], |
| 85 | attr_paths: &[], |
| 86 | .. |
| 87 | } => Ok(text.to_string()), |
| 88 | // rsx! { "title: {dynamic_text}" } |
| 89 | Template { |
| 90 | roots: &[TemplateNode::Dynamic { id }], |
| 91 | node_paths: &[&[0]], |
| 92 | attr_paths: &[], |
| 93 | .. |
| 94 | } => { |
| 95 | let node = &vnode.dynamic_nodes[id]; |
| 96 | match node { |
| 97 | DynamicNode::Text(text) => Ok(text.value.clone()), |
| 98 | _ => Err(ExtractSingleTextNodeError::NonTextNode), |
| 99 | } |
| 100 | } |
| 101 | _ => Err(ExtractSingleTextNodeError::NonTemplate), |
| 102 | } |
| 103 | } |
| 104 | |
| 105 | fn get_or_insert_root_context<T: Default + Clone + 'static>() -> T { |
| 106 | let rt = Runtime::current(); |
no test coverage detected