Only render exposed values

This commit is contained in:
Chadtech 2021-06-27 20:24:05 -04:00
parent 80a1ca698f
commit 38ef2a915a
5 changed files with 80 additions and 74 deletions

View file

@ -63,23 +63,12 @@ pub fn generate(filenames: Vec<PathBuf>, std_lib: StdLib, build_dir: &Path) {
// Write each package's module docs html file
for loaded_module in package.modules.iter_mut() {
let mut exposed_values = loaded_module
.exposed_to_host
let exports = loaded_module
.exposed_values
.iter()
.map(|(symbol, _)| symbol.ident_string(&loaded_module.interns).to_string())
.map(|symbol| symbol.ident_string(&loaded_module.interns).to_string())
.collect::<Vec<String>>();
let mut exposed_aliases = loaded_module
.exposed_aliases
.iter()
.map(|(symbol, _)| symbol.ident_string(&loaded_module.interns).to_string())
.collect::<Vec<String>>();
let mut exports = Vec::new();
exports.append(&mut exposed_values);
exports.append(&mut exposed_aliases);
for module in loaded_module.documentation.values_mut() {
let module_dir = build_dir.join(module.name.replace(".", "/").as_str());
@ -122,61 +111,64 @@ fn render_main_content(
);
for entry in &module.entries {
let mut should_render_entry = true;
if let DocDef(def) = entry {
if !exposed_values.contains(&def.name) {
break;
}
// We dont want to render entries that arent exposed
should_render_entry = exposed_values.contains(&def.name);
}
match entry {
DocEntry::DocDef(doc_def) => {
let mut href = String::new();
href.push('#');
href.push_str(doc_def.name.as_str());
if should_render_entry {
match entry {
DocEntry::DocDef(doc_def) => {
let mut href = String::new();
href.push('#');
href.push_str(doc_def.name.as_str());
let name = doc_def.name.as_str();
let name = doc_def.name.as_str();
let mut content = String::new();
let mut content = String::new();
content.push_str(html_node("a", vec![("href", href.as_str())], name).as_str());
content.push_str(html_node("a", vec![("href", href.as_str())], name).as_str());
for type_var in &doc_def.type_vars {
content.push(' ');
content.push_str(type_var.as_str());
}
for type_var in &doc_def.type_vars {
content.push(' ');
content.push_str(type_var.as_str());
}
let type_ann = &doc_def.type_annotation;
let type_ann = &doc_def.type_annotation;
match type_ann {
TypeAnnotation::NoTypeAnn => {}
_ => {
content.push_str(" : ");
match type_ann {
TypeAnnotation::NoTypeAnn => {}
_ => {
content.push_str(" : ");
}
}
type_annotation_to_html(0, &mut content, &type_ann);
buf.push_str(
html_node(
"h3",
vec![("id", name), ("class", "entry-name")],
content.as_str(),
)
.as_str(),
);
if let Some(docs) = &doc_def.docs {
buf.push_str(
markdown_to_html(&mut module.scope, interns, docs.to_string()).as_str(),
);
}
}
type_annotation_to_html(0, &mut content, &type_ann);
buf.push_str(
html_node(
"h3",
vec![("id", name), ("class", "entry-name")],
content.as_str(),
)
.as_str(),
);
if let Some(docs) = &doc_def.docs {
DocEntry::DetachedDoc(docs) => {
buf.push_str(
markdown_to_html(&mut module.scope, interns, docs.to_string()).as_str(),
);
}
}
DocEntry::DetachedDoc(docs) => {
buf.push_str(
markdown_to_html(&mut module.scope, interns, docs.to_string()).as_str(),
);
}
};
};
}
}
buf