diff options
author | Minijackson <minijackson@riseup.net> | 2019-12-18 20:56:53 +0100 |
---|---|---|
committer | Minijackson <minijackson@riseup.net> | 2019-12-18 20:56:53 +0100 |
commit | de896baff7e97fac4dde79078c9a2fa1c652576b (patch) | |
tree | 512b67b91d64e51d63f7ac5ff925a5c96d9aaf3c /src/generator/config.rs | |
parent | 860b73f1644ecd6548ae403ec483625fb7b625ea (diff) | |
download | poseidoc-de896baff7e97fac4dde79078c9a2fa1c652576b.tar.gz poseidoc-de896baff7e97fac4dde79078c9a2fa1c652576b.zip |
Big refactoring
- entities should be more coherent when parsing multiple files
- well defined, language agnostic entity tree
- each module has its own configuration
- less dead code
Diffstat (limited to 'src/generator/config.rs')
-rw-r--r-- | src/generator/config.rs | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/src/generator/config.rs b/src/generator/config.rs new file mode 100644 index 0000000..43fee60 --- /dev/null +++ b/src/generator/config.rs | |||
@@ -0,0 +1,53 @@ | |||
1 | use serde_derive::{Deserialize, Serialize}; | ||
2 | use structopt::StructOpt; | ||
3 | |||
4 | use std::collections::{HashMap, HashSet}; | ||
5 | |||
6 | #[derive(Debug, Clone, Serialize)] | ||
7 | pub(crate) struct Config { | ||
8 | /// Tells us in which language, which entity types should inline which children entity type in | ||
9 | /// their documentation. | ||
10 | /// | ||
11 | /// e.g. in C++, classes should inline their children methods documentation. | ||
12 | pub(crate) inlines: HashMap<String, HashMap<String, HashSet<String>>>, | ||
13 | } | ||
14 | |||
15 | impl Config { | ||
16 | pub(crate) fn from_merge(_cli: ProvidedConfig, conf: ProvidedConfig) -> Self { | ||
17 | Self { | ||
18 | inlines: conf.inlines.unwrap_or_else(default_inlines), | ||
19 | } | ||
20 | } | ||
21 | } | ||
22 | |||
23 | fn default_inlines() -> HashMap<String, HashMap<String, HashSet<String>>> { | ||
24 | let mut clang = HashMap::new(); | ||
25 | let mut clang_inline_children = HashSet::new(); | ||
26 | // TODO: this is not great: no differences between variable/field for children, but differences | ||
27 | // as a parent... | ||
28 | clang_inline_children.insert(String::from("variable")); | ||
29 | //classes.insert(String::from("field")); | ||
30 | clang_inline_children.insert(String::from("function")); | ||
31 | //classes.insert(String::from("method")); | ||
32 | clang.insert(String::from("struct"), clang_inline_children.clone()); | ||
33 | clang.insert(String::from("class"), clang_inline_children.clone()); | ||
34 | clang.insert(String::from("namespace"), clang_inline_children); | ||
35 | |||
36 | let mut inlines = HashMap::new(); | ||
37 | inlines.insert(String::from("clang"), clang); | ||
38 | |||
39 | inlines | ||
40 | } | ||
41 | |||
42 | impl Default for Config { | ||
43 | fn default() -> Self { | ||
44 | Config::from_merge(ProvidedConfig::default(), ProvidedConfig::default()) | ||
45 | } | ||
46 | } | ||
47 | |||
48 | #[derive(Debug, Clone, Default, StructOpt, Deserialize, Serialize)] | ||
49 | #[serde(rename_all = "kebab-case")] | ||
50 | pub(crate) struct ProvidedConfig { | ||
51 | #[structopt(skip)] | ||
52 | pub(crate) inlines: Option<HashMap<String, HashMap<String, HashSet<String>>>>, | ||
53 | } | ||