From 6217317325263c62f9725a30e6abd2b52f42bee4 Mon Sep 17 00:00:00 2001 From: HJfod <60038575+HJfod@users.noreply.github.com> Date: Fri, 24 Feb 2023 10:48:46 +0200 Subject: [PATCH] add base classes --- src/builder/shared.rs | 38 +++++++++++++++++++++++++++++++++----- src/main.rs | 1 + templates/class.html | 2 ++ templates/content.css | 4 +++- templates/function.html | 2 +- templates/struct.html | 2 ++ 6 files changed, 42 insertions(+), 7 deletions(-) diff --git a/src/builder/shared.rs b/src/builder/shared.rs index b252e83..05eb0be 100644 --- a/src/builder/shared.rs +++ b/src/builder/shared.rs @@ -324,12 +324,40 @@ pub fn fmt_header_link(entity: &Entity, config: Arc) -> Html { } } -pub fn fmt_base_classes<'e, T: ASTEntry<'e>>(entry: &T, kw: &str, config: Arc) -> Html { +pub fn fmt_base_classes<'e, T: ASTEntry<'e>>(entry: &T, kw: &str, builder: &Builder) -> Html { + let bases = entry.entity().get_children() + .into_iter() + .filter(|p| p.get_kind() == EntityKind::BaseSpecifier) + .collect::>(); + HtmlElement::new("div") - .with_class("entity-desc") + .with_classes(&["entity", "class"]) .with_child(Html::span(&["keyword", "space-after"], kw)) - .with_child(Html::span(&["identifier", "space-after"], entry.name().as_str())) - .with_child(HtmlText::new(";")) + .with_child(Html::span(&["name"], entry.name().as_str())) + .with_child_opt((!bases.is_empty()).then_some( + Html::span(&["space-before", "space-after"], ":") + )) + .with_children(bases.into_iter() + .map(|base| HtmlList::new([ + base.get_accessibility().map(|a| + Html::span( + &["keyword", "space-after"], + match a { + Accessibility::Public => "public", + Accessibility::Private => "private", + Accessibility::Protected => "protected", + } + ) + ), + base.is_virtual_base().then_some( + Html::span(&["keyword", "space-after"], "virtual") + ), + base.get_type().map(|ty| fmt_type(&ty, builder)) + ].into_iter().flatten().collect()).into()) + .intersperse_with(|| Html::span(&["space-after"], ",").into()) + .collect() + ) + .with_child(Html::span(&["space-before"], "{ ... }")) .into() } @@ -379,7 +407,7 @@ pub fn output_classlike<'e, T: ASTEntry<'e>>( ent.extend(vec![ ( "base_classes", - fmt_base_classes(entry, entry.category(), builder.config.clone()) + fmt_base_classes(entry, entry.category(), builder) ), ( "public_static_functions", diff --git a/src/main.rs b/src/main.rs index fa46dc1..d363b80 100644 --- a/src/main.rs +++ b/src/main.rs @@ -2,6 +2,7 @@ #![feature(is_some_and)] #![feature(result_option_inspect)] #![feature(iter_advance_by)] +#![feature(iter_intersperse)] use crate::{analyze::create_docs, url::UrlPath, normalize::Normalize}; use clap::Parser; diff --git a/templates/class.html b/templates/class.html index 5f48a0a..efc2be9 100644 --- a/templates/class.html +++ b/templates/class.html @@ -6,6 +6,8 @@

Class Function
{description} - {examples}
+ {examples}
diff --git a/templates/struct.html b/templates/struct.html index 94ac9ff..38d5f41 100644 --- a/templates/struct.html +++ b/templates/struct.html @@ -5,6 +5,8 @@

Struct <
{description} +
+
{public_members} {examples} {public_static_functions}