Merge pull request #1512 from rtfeldman/docs-exposed-values-in-sidebar

Sidebar only shows exposed values
This commit is contained in:
Richard Feldman 2021-08-01 22:02:15 -04:00 committed by GitHub
commit 9fb0a7946e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -54,12 +54,17 @@ pub fn generate(filenames: Vec<PathBuf>, std_lib: StdLib, build_dir: &Path) {
let template_html = include_str!("./static/index.html").replace( let template_html = include_str!("./static/index.html").replace(
"<!-- Module links -->", "<!-- Module links -->",
render_sidebar( render_sidebar(package.modules.iter().flat_map(|loaded_module| {
package loaded_module.documentation.values().map(move |d| {
.modules let exposed_values = loaded_module
.iter() .exposed_values
.flat_map(|loaded_module| loaded_module.documentation.values()), .iter()
) .map(|symbol| symbol.ident_string(&loaded_module.interns).to_string())
.collect::<Vec<String>>();
(exposed_values, d)
})
}))
.as_str(), .as_str(),
); );
@ -269,10 +274,12 @@ fn render_name_and_version(name: &str, version: &str) -> String {
buf buf
} }
fn render_sidebar<'a, I: Iterator<Item = &'a ModuleDocumentation>>(modules: I) -> String { fn render_sidebar<'a, I: Iterator<Item = (Vec<String>, &'a ModuleDocumentation)>>(
modules: I,
) -> String {
let mut buf = String::new(); let mut buf = String::new();
for module in modules { for (exposed_values, module) in modules {
let mut sidebar_entry_content = String::new(); let mut sidebar_entry_content = String::new();
let name = module.name.as_str(); let name = module.name.as_str();
@ -298,20 +305,22 @@ fn render_sidebar<'a, I: Iterator<Item = &'a ModuleDocumentation>>(modules: I) -
for entry in &module.entries { for entry in &module.entries {
if let DocEntry::DocDef(doc_def) = entry { if let DocEntry::DocDef(doc_def) = entry {
let mut entry_href = String::new(); if exposed_values.contains(&doc_def.name) {
let mut entry_href = String::new();
entry_href.push_str(href.as_str()); entry_href.push_str(href.as_str());
entry_href.push('#'); entry_href.push('#');
entry_href.push_str(doc_def.name.as_str()); entry_href.push_str(doc_def.name.as_str());
entries_buf.push_str( entries_buf.push_str(
html_node( html_node(
"a", "a",
vec![("href", entry_href.as_str())], vec![("href", entry_href.as_str())],
doc_def.name.as_str(), doc_def.name.as_str(),
) )
.as_str(), .as_str(),
); );
}
} }
} }