From 0b4b0dc58eed8489a66d030d1dc6f9f0f1bd77fd Mon Sep 17 00:00:00 2001 From: crowlkats Date: Wed, 25 Oct 2023 08:36:32 +0200 Subject: [PATCH] implement variable & type alias --- src/html/mod.rs | 8 ++++++-- src/html/type_alias.rs | 23 +++++++++++++++++++++++ src/html/variable.rs | 27 +++++++++++++++++++++++++++ 3 files changed, 56 insertions(+), 2 deletions(-) diff --git a/src/html/mod.rs b/src/html/mod.rs index e0101ab6..c4d74866 100644 --- a/src/html/mod.rs +++ b/src/html/mod.rs @@ -128,11 +128,15 @@ fn doc_block(doc_nodes: &[crate::DocNode], name: &str) -> String { match doc_node.kind { DocNodeKind::ModuleDoc => {} DocNodeKind::Function => functions.push(doc_node), - DocNodeKind::Variable => {} + DocNodeKind::Variable => { + content.push_str(&variable::render_variable(doc_node)) + } DocNodeKind::Class => {} DocNodeKind::Enum => content.push_str(&r#enum::render_enum(doc_node)), DocNodeKind::Interface => {} - DocNodeKind::TypeAlias => {} + DocNodeKind::TypeAlias => { + content.push_str(&type_alias::render_type_alias(doc_node)) + } DocNodeKind::Namespace => {} DocNodeKind::Import => {} }; diff --git a/src/html/type_alias.rs b/src/html/type_alias.rs index 8b137891..1dc4c377 100644 --- a/src/html/type_alias.rs +++ b/src/html/type_alias.rs @@ -1 +1,24 @@ +use crate::html::r#type::render_type_def; +use crate::html::util::*; +pub fn render_type_alias(doc_node: &crate::DocNode) -> String { + let type_alias_def = doc_node.type_alias_def.as_ref().unwrap(); + + let id = name_to_id("typeAlias", &doc_node.name); + + // TODO: tags, examples, TypeParamsDoc + + format!( + r#"
{}
"#, + section( + "type", + &doc_entry( + &id, + "definition", + &format!(": {}", render_type_def(&type_alias_def.ts_type)), + ) + ) + ) +} + +// TODO: classes: docBlockItems diff --git a/src/html/variable.rs b/src/html/variable.rs index 8b137891..d2d2a169 100644 --- a/src/html/variable.rs +++ b/src/html/variable.rs @@ -1 +1,28 @@ +use crate::html::r#type::render_type_def; +use crate::html::util::*; +pub fn render_variable(doc_node: &crate::DocNode) -> String { + let variable_def = doc_node.variable_def.as_ref().unwrap(); + + if variable_def.ts_type.is_none() { + return String::new(); + } + + let id = name_to_id("variable", &doc_node.name); + + // TODO: examples + + format!( + r#"
{}
"#, + section( + "type", + &doc_entry( + &id, + "", + &render_type_def(variable_def.ts_type.as_ref().unwrap()) + ) + ) + ) +} + +// TODO: classes: docBlockItems