Skip to content

Commit

Permalink
generate HTML header tags
Browse files Browse the repository at this point in the history
  • Loading branch information
Chriscbr committed Aug 30, 2024
1 parent ec07d22 commit 220a8b3
Showing 1 changed file with 22 additions and 28 deletions.
50 changes: 22 additions & 28 deletions libs/wingc/src/generate_docs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ fn generate_docs_helper(types: &Types, project_dir: &Utf8Path) -> Result<String,
SymbolEnvOrNamespace::Error(diag) => panic!("Error in root env: {}", diag),
};

docs.push_str("## API Reference\n\n");
docs.push_str("<h2>API Reference</h2>\n\n");

let mut public_types = vec![];
let namespaces = find_documentable_namespaces_recursive(&ns);
Expand Down Expand Up @@ -220,7 +220,7 @@ fn simplified_fqn(typ: &TypeRef) -> String {
}

fn print_table_of_contents(types: &[TypeRef], docs: &mut String) {
docs.push_str("### Table of Contents\n\n");
docs.push_str("<h3>Table of Contents</h3>\n\n");

let mut classes = vec![];
let mut interfaces = vec![];
Expand Down Expand Up @@ -287,13 +287,13 @@ fn print_table_of_contents(types: &[TypeRef], docs: &mut String) {
fn print_classes(types: &[TypeRef], docs: &mut String) {
for typ in types {
if let Type::Class(ref class) = **typ {
docs.push_str("### ");
docs.push_str("<h3 id=\"");
docs.push_str(&typ.fqn().expect("Type has no FQN"));
docs.push_str("\">");
docs.push_str(&simplified_fqn(typ));
docs.push_str(" (");
docs.push_str(&class.phase.to_string());
docs.push_str(" class) <a id=\"");
docs.push_str(&typ.fqn().expect("Type has no FQN"));
docs.push_str("\"></a>\n\n");
docs.push_str(" class)</h3>\n\n");

let docstring = class.docs.render();
if !docstring.is_empty() {
Expand All @@ -311,13 +311,11 @@ fn print_classes(types: &[TypeRef], docs: &mut String) {
fn print_interfaces(types: &[TypeRef], docs: &mut String) {
for typ in types {
if let Type::Interface(ref interface) = **typ {
docs.push_str("### ");
docs.push_str(&simplified_fqn(typ));
docs.push_str(" (interface) <a name=");
docs.push_str(&simplified_fqn(typ));
docs.push_str(" id=\"");
docs.push_str("<h3 id=\"");
docs.push_str(&typ.fqn().expect("Type has no FQN"));
docs.push_str("\"></a>\n\n");
docs.push_str("\">");
docs.push_str(&simplified_fqn(typ));
docs.push_str(" (interface)</h3>\n\n");

let docstring = interface.docs.render();
if !docstring.is_empty() {
Expand All @@ -334,13 +332,11 @@ fn print_interfaces(types: &[TypeRef], docs: &mut String) {
fn print_structs(types: &[TypeRef], docs: &mut String) {
for typ in types {
if let Type::Struct(ref struct_) = **typ {
docs.push_str("### ");
docs.push_str(&simplified_fqn(typ));
docs.push_str(" (struct) <a name=");
docs.push_str(&simplified_fqn(typ));
docs.push_str(" id=\"");
docs.push_str("<h3 id=\"");
docs.push_str(&typ.fqn().expect("Type has no FQN"));
docs.push_str("\"></a>\n\n");
docs.push_str("\">");
docs.push_str(&simplified_fqn(typ));
docs.push_str(" (struct)</h3>\n\n");

let docstring = struct_.docs.render();
if !docstring.is_empty() {
Expand All @@ -356,21 +352,19 @@ fn print_structs(types: &[TypeRef], docs: &mut String) {
fn print_enums(types: &[TypeRef], docs: &mut String) {
for typ in types {
if let Type::Enum(ref enum_) = **typ {
docs.push_str("### ");
docs.push_str(&simplified_fqn(typ));
docs.push_str(" (enum) <a name=");
docs.push_str(&simplified_fqn(typ));
docs.push_str(" id=\"");
docs.push_str("<h3 id=\"");
docs.push_str(&typ.fqn().expect("Type has no FQN"));
docs.push_str("\"></a>\n\n");
docs.push_str("\">");
docs.push_str(&simplified_fqn(typ));
docs.push_str(" (enum)</h3>\n\n");

let docstring = enum_.docs.render();
if !docstring.is_empty() {
docs.push_str(&docstring);
docs.push_str("\n\n");
}

docs.push_str("#### Values\n\n");
docs.push_str("<h4>Values</h4>\n\n");
docs.push_str("| **Name** | **Description** |\n");
docs.push_str("| --- | --- |\n");
for (name, description) in enum_.values.iter() {
Expand All @@ -391,7 +385,7 @@ fn print_enums(types: &[TypeRef], docs: &mut String) {
}

fn print_constructors(docs: &mut String, class: &impl ClassLike) {
docs.push_str("#### Constructor\n\n");
docs.push_str("<h4>Constructor</h4>\n\n");

let mut constructors = class.constructors(true).collect::<Vec<_>>();
constructors.retain(|(_, constructor_info)| constructor_info.access == AccessModifier::Public);
Expand All @@ -417,7 +411,7 @@ fn print_constructors(docs: &mut String, class: &impl ClassLike) {
}

fn print_properties(docs: &mut String, class: &impl ClassLike) {
docs.push_str("#### Properties\n\n");
docs.push_str("<h4>Properties</h4>\n\n");

let mut fields = class.fields(true).collect::<Vec<_>>();
fields.retain(|(_, field_info)| field_info.access == AccessModifier::Public);
Expand Down Expand Up @@ -447,7 +441,7 @@ fn print_properties(docs: &mut String, class: &impl ClassLike) {
}

fn print_methods(docs: &mut String, class: &impl ClassLike) {
docs.push_str("#### Methods\n\n");
docs.push_str("<h4>Methods</h4>\n\n");

let mut methods = class.methods(true).collect::<Vec<_>>();
methods.retain(|(_, method_info)| method_info.access == AccessModifier::Public);
Expand Down

0 comments on commit 220a8b3

Please sign in to comment.