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