reactive_graph_generator_documentation/generator/
variables_container.rs

1use crate::generator::TypedMarkdownDocumentation;
2use crate::markdown::table::MarkdownTableExt;
3use crate::types::config::PropertiesDocumentationConfig;
4use crate::types::config::SubTypesGenerationMode;
5use documented::DocumentedVariants;
6use markdown_builder::List;
7use reactive_graph_graph::VariablesContainer;
8use tabled::Table;
9
10impl<TY> TypedMarkdownDocumentation<TY>
11where
12    TY: VariablesContainer,
13{
14    pub fn variables(self, config: &PropertiesDocumentationConfig) -> Self {
15        let variables = self.ty.get_own_variables_cloned();
16        if variables.is_empty() {
17            return self;
18        }
19        {
20            let mut document = self.document.write().unwrap();
21            if config.header {
22                document.header2("Variables");
23            }
24            match config.mode {
25                SubTypesGenerationMode::None => {}
26                SubTypesGenerationMode::Short => {
27                    let mut list = List::unordered();
28                    for property_type in variables.iter() {
29                        list.items.push(property_type.name.clone().into());
30                    }
31                    document.list(list);
32                }
33                SubTypesGenerationMode::Table => {
34                    let table = Table::new(&mut variables.to_vec().into_iter()).to_owned();
35                    document.table(table);
36                }
37            }
38
39            for variable in variables.iter() {
40                document.header3(format!("Variable `{}`", variable.name));
41                if !variable.description.is_empty() {
42                    document.paragraph(variable.description.clone());
43                }
44                document.header4("Data Type");
45                document.paragraph(format!(
46                    "<details><summary><code>{}</code></summary>{}</details>",
47                    variable.data_type,
48                    variable.data_type.get_variant_docs()
49                ));
50                document.header4("Socket Type");
51                document.paragraph(format!(
52                    "<details><summary><code>{}</code></summary>{}</details>",
53                    variable.socket_type,
54                    variable.socket_type.get_variant_docs()
55                ));
56                document.header4("Mutability");
57                document.paragraph(format!(
58                    "<details><summary><code>{}</code></summary>{}</details>",
59                    variable.mutability,
60                    variable.mutability.get_variant_docs()
61                ));
62                if !variable.extensions.is_empty() {
63                    document.header4("Extensions (TODO)");
64                }
65            }
66        }
67
68        self
69    }
70}