1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67
use super::*; pub const FUNCTION_LENGTH_THRESHOLD: usize = 120; #[derive(Clone, Debug)] pub struct Function { pub name: String, pub generic: RcList<Typing>, pub version: String, pub class: Rc<Class>, pub parameters: Parameter, pub is_multiline: Option<bool>, } impl SignatureContainer for Function { fn get_signature(&self) -> Html { let head = Html::from("def"); let name = html! {<span class="function">{&self.name}</span>}; let generic = self.generic.render(); let arg_newline = match self.is_multiline { Some(s) => s, None => self.name.len() + self.parameters.length() > FUNCTION_LENGTH_THRESHOLD, }; let left = match arg_newline { true => html! {<>{"("}<br/>{IndentHtml}</>}, false => html! {"("}, }; let right = match arg_newline { true => html! {<><br/>{")"}</>}, false => html! {")"}, }; let comma: Html = match arg_newline { true => html! {<>{","}<br/>{IndentHtml}</>}, false => html! {", "}, }; let items: Html = vec![left] .into_iter() .chain(self.parameters.clone().into_vec().into_iter().intersperse(comma)) .chain(vec![right].into_iter()) .collect(); html! {<code class="signature">{head}{" "}{name}{generic}{items}</code>} } fn get_id(&self) -> String { format!("function.{}", self.name) } fn get_class(&self) -> String { format!("def-function") } fn get_children(&self) -> Option<Html> { Some(html! { <p> {"Returns the match associated with the capture group at index"} <code>{"P"}</code>{"."} {"If i does not correspond to a capture group, or if the capture group did not participate in the match, then"}<code>{"None"}</code>{"is returned."} <br/> {"中文测试中文测试中文怎么样"} <br/> {"ab ab ab ab ab ab ab ab ab"} </p> }) } }