Add MemberGroup struct for groups of members items
Previosuly, we stored the members as a vector of vectors, group by a string -- their title. This was very hard to read and also too simple: For example, there can be multiple blocks of methods in the documentation for a struct. Therefore we introduce a new type, MemberGroup, that represents a group of member items with an optional title.
This commit is contained in:
parent
f08490eeff
commit
958019449d
19
src/doc.rs
19
src/doc.rs
@ -71,7 +71,13 @@ pub struct Doc {
|
||||
pub ty: ItemType,
|
||||
pub description: Option<String>,
|
||||
pub definition: Option<String>,
|
||||
pub members: Vec<(String, Vec<Doc>)>,
|
||||
pub groups: Vec<(ItemType, Vec<MemberGroup>)>,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct MemberGroup {
|
||||
pub title: Option<String>,
|
||||
pub members: Vec<Doc>,
|
||||
}
|
||||
|
||||
impl Name {
|
||||
@ -425,7 +431,16 @@ impl Doc {
|
||||
ty,
|
||||
description: Default::default(),
|
||||
definition: Default::default(),
|
||||
members: Default::default(),
|
||||
groups: Default::default(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl MemberGroup {
|
||||
pub fn new() -> Self {
|
||||
MemberGroup {
|
||||
title: None,
|
||||
members: Vec::new(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -110,10 +110,10 @@ pub fn parse_module_doc(item: &doc::Item) -> anyhow::Result<doc::Doc> {
|
||||
let mut doc = doc::Doc::new(item.name.clone(), item.ty);
|
||||
doc.description = description.map(|n| get_html(n.as_node())).transpose()?;
|
||||
for item_type in MODULE_MEMBER_TYPES {
|
||||
let members = get_members(&document, item, *item_type)?;
|
||||
if !members.is_empty() {
|
||||
doc.members
|
||||
.push((item_type.group_name().to_string(), members));
|
||||
let mut group = doc::MemberGroup::new();
|
||||
group.members = get_members(&document, item, *item_type)?;
|
||||
if !group.members.is_empty() {
|
||||
doc.groups.push((*item_type, vec![group]));
|
||||
}
|
||||
}
|
||||
Ok(doc)
|
||||
|
@ -33,11 +33,17 @@ impl<P: Printer> TextViewer<P> {
|
||||
.print_heading(1, &format!("{} {}", doc.ty.name(), doc.name.as_ref()))?;
|
||||
self.print_opt(doc.definition.as_deref())?;
|
||||
self.print_opt(doc.description.as_deref())?;
|
||||
for (heading, items) in &doc.members {
|
||||
if !items.is_empty() {
|
||||
self.printer.println()?;
|
||||
self.printer.print_heading(2, heading)?;
|
||||
self.print_list(items.iter().map(|i| {
|
||||
for (ty, groups) in &doc.groups {
|
||||
self.printer.println()?;
|
||||
self.printer.print_heading(2, ty.group_name())?;
|
||||
|
||||
for group in groups {
|
||||
if let Some(title) = &group.title {
|
||||
self.printer.println()?;
|
||||
self.printer.print_heading(3, title)?;
|
||||
}
|
||||
|
||||
self.print_list(group.members.iter().map(|i| {
|
||||
if let Some(description) = &i.description {
|
||||
format!("{}<br/>{}", i.name.last(), description)
|
||||
} else {
|
||||
|
Loading…
Reference in New Issue
Block a user