Skip to content

Commit

Permalink
chore(leptos_marco): enhancement of document generation (#1768)
Browse files Browse the repository at this point in the history
  • Loading branch information
fundon authored Sep 22, 2023
1 parent 3b864ac commit 1d39248
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions leptos_macro/src/component.rs
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ impl ToTokens for Model {
let prop_names = prop_names(props);

let builder_name_doc = LitStr::new(
&format!("Props for the [`{name}`] component."),
&format!(" Props for the [`{name}`] component."),
name.span(),
);

Expand Down Expand Up @@ -476,6 +476,7 @@ impl ToTokens for Model {
#[doc = #builder_name_doc]
#[doc = ""]
#docs
#[doc = ""]
#component_fn_prop_docs
#[derive(::leptos::typed_builder_macro::TypedBuilder #props_derive_serialize)]
//#[builder(doc)]
Expand Down Expand Up @@ -506,6 +507,7 @@ impl ToTokens for Model {
#into_view

#docs
#[doc = ""]
#component_fn_prop_docs
#[allow(non_snake_case, clippy::too_many_arguments)]
#tracing_instrument_attr
Expand Down Expand Up @@ -612,7 +614,8 @@ impl Docs {

// Seperated out of chain to allow rustfmt to work
let map = |(doc, span): (String, Span)| {
doc.lines()
doc.split('\n')
.map(str::trim_end)
.flat_map(|doc| {
let trimmed_doc = doc.trim_start();
let leading_ws = &doc[..doc.len() - trimmed_doc.len()];
Expand Down Expand Up @@ -932,7 +935,7 @@ fn generate_component_fn_prop_docs(props: &[Prop]) -> TokenStream {

let required_prop_docs = if !required_prop_docs.is_empty() {
quote! {
#[doc = "# Required Props"]
#[doc = " # Required Props"]
#required_prop_docs
}
} else {
Expand All @@ -941,7 +944,7 @@ fn generate_component_fn_prop_docs(props: &[Prop]) -> TokenStream {

let optional_prop_docs = if !optional_prop_docs.is_empty() {
quote! {
#[doc = "# Optional Props"]
#[doc = " # Optional Props"]
#optional_prop_docs
}
} else {
Expand Down Expand Up @@ -1043,10 +1046,10 @@ fn prop_to_doc(
PropDocStyle::List => {
let arg_ty_doc = LitStr::new(
&if !prop_opts.into {
format!("- **{}**: [`{pretty_ty}`]", quote!(#name))
format!(" - **{}**: [`{pretty_ty}`]", quote!(#name))
} else {
format!(
"- **{}**: [`impl Into<{pretty_ty}>`]({pretty_ty})",
" - **{}**: [`impl Into<{pretty_ty}>`]({pretty_ty})",
quote!(#name),
)
},
Expand Down

0 comments on commit 1d39248

Please sign in to comment.