-
Notifications
You must be signed in to change notification settings - Fork 73
Expand file tree
/
Copy pathmod.rs
More file actions
98 lines (85 loc) · 2.94 KB
/
mod.rs
File metadata and controls
98 lines (85 loc) · 2.94 KB
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
mod gen;
mod init_tl;
mod markdown_types;
mod mixin_copy;
mod render;
use std::path::PathBuf;
use emmylua_code_analysis::EmmyLuaAnalysis;
use gen::{
generate_global_markdown, generate_index, generate_module_markdown, generate_type_markdown,
};
use markdown_types::MkdocsIndex;
pub fn generate_markdown(
analysis: &mut EmmyLuaAnalysis,
output: PathBuf,
override_template: Option<PathBuf>,
site_name: Option<String>,
mixin: Option<PathBuf>,
) -> Result<(), Box<dyn std::error::Error>> {
let docs_dir = output.join("docs");
let types_out = docs_dir.join("types");
if !types_out.exists() {
eprintln!("Creating types directory: {:?}", types_out);
std::fs::create_dir_all(&types_out)?;
} else {
eprintln!("Clearing types directory: {:?}", types_out);
std::fs::remove_dir_all(&types_out)?;
std::fs::create_dir_all(&types_out)?;
}
let module_out = docs_dir.join("modules");
if !module_out.exists() {
eprintln!("Creating modules directory: {:?}", module_out);
std::fs::create_dir_all(&module_out)?;
} else {
eprintln!("Clearing modules directory: {:?}", module_out);
std::fs::remove_dir_all(&module_out)?;
std::fs::create_dir_all(&module_out)?;
}
let global_out = docs_dir.join("globals");
if !global_out.exists() {
eprintln!("Creating globals directory: {:?}", global_out);
std::fs::create_dir_all(&global_out)?;
} else {
eprintln!("Clearing globals directory: {:?}", global_out);
std::fs::remove_dir_all(&global_out)?;
std::fs::create_dir_all(&global_out)?;
}
let tl = init_tl::init_tl(override_template).ok_or("Failed to initialize TL")?;
let mut mkdocs_index = MkdocsIndex::default();
if let Some(site_name) = site_name {
mkdocs_index.site_name = site_name;
}
let db = analysis.compilation.get_db();
let type_index = db.get_type_index();
let types = type_index.get_all_types();
for type_decl in types {
generate_type_markdown(db, &tl, type_decl, &types_out, &mut mkdocs_index);
}
let module_index = db.get_module_index();
let modules = module_index.get_module_infos();
for module in modules {
generate_module_markdown(db, &tl, module, &module_out, &mut mkdocs_index);
}
let global_index = db.get_global_index();
let globals = global_index.get_all_global_decl_ids();
for global_decl_id in globals {
generate_global_markdown(db, &tl, &global_decl_id, &global_out, &mut mkdocs_index);
}
generate_index(&tl, &mut mkdocs_index, &output);
if let Some(mixin) = mixin {
mixin_copy::mixin_copy(&output, mixin);
}
Ok(())
}
fn escape_type_name(name: &str) -> String {
name.chars()
.map(|c| {
// Windows Invalid Characters
if "<>:\"/\\|?*".contains(c) {
'_'
} else {
c
}
})
.collect()
}