@@ -10,148 +10,11 @@ use ladfile::{
10
10
use mdbook:: book:: Chapter ;
11
11
use std:: { borrow:: Cow , collections:: HashSet } ;
12
12
13
- // pub(crate) fn section_to_chapter(
14
- // section: SectionAndChildren,
15
- // original_chapter: Option<&Chapter>,
16
- // parent_names: Vec<String>,
17
- // number: Option<SectionNumber>,
18
- // root_path: Option<PathBuf>,
19
- // root_source_path: Option<PathBuf>,
20
- // ) -> Chapter {
21
- // let mut parent_builder = MarkdownBuilder::new();
22
- // section.section.to_markdown(&mut parent_builder);
23
-
24
- // // important to reset the extension of the parent, since when we're nesting
25
- // // we add the filename with .md, but if the parent is being emitted as markdown, then when
26
- // // we create the child, we will create the `parent.md` file as a folder, then when we emit
27
- // // the parent itself, the file (directory) will already exist
28
- // let new_path = root_path
29
- // .unwrap_or_default()
30
- // .with_extension("")
31
- // .join(section.section.file_name());
32
-
33
- // let new_source_path = root_source_path
34
- // .unwrap_or_default()
35
- // .with_extension("")
36
- // .join(section.section.file_name());
37
-
38
- // let current_number = number.clone().unwrap_or_default();
39
-
40
- // let children_chapters = section
41
- // .children
42
- // .into_iter()
43
- // .enumerate()
44
- // .map(|(index, child)| {
45
- // let mut new_number = current_number.clone();
46
- // new_number.push(index as u32);
47
- // section_to_chapter(
48
- // child,
49
- // None,
50
- // vec![section.section.title()],
51
- // Some(new_number),
52
- // Some(new_path.clone()),
53
- // Some(new_source_path.clone()),
54
- // )
55
- // })
56
- // .map(mdbook::BookItem::Chapter)
57
- // .collect();
58
-
59
- // if let Some(original) = original_chapter {
60
- // // override content only
61
- // log::debug!(
62
- // "Setting .md extension for chapter paths: {:?}, {:?}.",
63
- // original.path,
64
- // original.source_path
65
- // );
66
-
67
- // Chapter {
68
- // content: parent_builder.build(),
69
- // sub_items: children_chapters,
70
- // path: original.path.as_ref().map(|p| p.with_extension("md")),
71
- // source_path: original
72
- // .source_path
73
- // .as_ref()
74
- // .map(|p| p.with_extension("md")),
75
- // ..original.clone()
76
- // }
77
- // } else {
78
- // Chapter {
79
- // name: section.section.title(),
80
- // content: parent_builder.build(),
81
- // number,
82
- // sub_items: children_chapters,
83
- // path: Some(new_path),
84
- // source_path: Some(new_source_path),
85
- // parent_names,
86
- // }
87
- // }
88
- // }
89
-
90
- // fn section_to_section_and_children(section: Section<'_>) -> SectionAndChildren<'_> {
91
- // let children = section
92
- // .children()
93
- // .into_iter()
94
- // .map(section_to_section_and_children)
95
- // .collect();
96
-
97
- // SectionAndChildren { children, section }
98
- // }
99
-
100
- // pub(crate) fn lad_file_to_sections(
101
- // ladfile: &ladfile::LadFile,
102
- // title: Option<String>,
103
- // ) -> SectionAndChildren<'_> {
104
- // section_to_section_and_children(Section::Summary { ladfile, title })
105
- // build a hierarchy as follows:
106
- // - Summary
107
- // - Instances
108
- // - Functions
109
- // - Global Function Detail 1
110
- // - Types
111
- // - Type1
112
- // - Type detail 1
113
- // - Function detail 1
114
- // - Function detail 2
115
- // let mut types_children = ladfile
116
- // .types
117
- // .iter()
118
- // .map(|(_, lad_type)| (lad_type, Section::TypeDetail { lad_type, ladfile }))
119
- // .map(|(lad_type, section)| SectionAndChildren {
120
- // section,
121
- // children: lad_type
122
- // .associated_functions
123
- // .iter()
124
- // .filter_map(|f| {
125
- // let function = ladfile.functions.get(f)?;
126
- // Some(SectionAndChildren {
127
- // section: Section::FunctionDetail { function, ladfile },
128
- // children: vec![],
129
- // })
130
- // })
131
- // .collect(),
132
- // })
133
- // .collect();
134
-
135
- // // now add a `functions` subsection before all types, for global functions
136
-
137
- // SectionAndChildren {
138
- // section: summary,
139
- // children: vec![
140
- // SectionAndChildren {
141
- // section: Section::TypeSummary { ladfile },
142
- // children: types_children,
143
- // },
144
- // SectionAndChildren {
145
- // section: Section::FunctionSummary { ladfile },
146
- // children: vec![],
147
- // },
148
- // ],
149
- // }
150
- // }
151
- // pub(crate) struct SectionAndChildren<'a> {
152
- // section: Section<'a>,
153
- // children: Vec<SectionAndChildren<'a>>,
154
- // }
13
+ fn print_type ( ladfile : & LadFile , type_ : & LadTypeId ) -> String {
14
+ let mut visitor = MarkdownArgumentVisitor :: new ( ladfile) ;
15
+ visitor. visit_lad_type_id ( type_) ;
16
+ visitor. build ( )
17
+ }
155
18
156
19
/// Sections which convert to single markdown files
157
20
pub ( crate ) enum Section < ' a > {
@@ -240,11 +103,7 @@ impl<'a> Section<'a> {
240
103
ladfile,
241
104
lad_type_id,
242
105
..
243
- } => {
244
- let mut visitor = MarkdownArgumentVisitor :: new ( ladfile) ;
245
- visitor. visit_lad_type_id ( lad_type_id) ;
246
- visitor. build ( )
247
- }
106
+ } => print_type ( ladfile, lad_type_id) ,
248
107
Section :: FunctionDetail { function, .. } => function. identifier . to_string ( ) ,
249
108
}
250
109
}
@@ -349,10 +208,11 @@ impl<'a> Section<'a> {
349
208
vec ! [ SectionItem :: InstancesSummary { instances } ]
350
209
}
351
210
Section :: TypeSummary { ladfile } => {
352
- let types = ladfile. types . values ( ) . collect :: < Vec < _ > > ( ) ;
211
+ let types = ladfile. types . keys ( ) . collect :: < Vec < _ > > ( ) ;
353
212
vec ! [ SectionItem :: TypesSummary {
354
213
types,
355
214
types_directory: linkify_filename( self . title( ) ) ,
215
+ ladfile,
356
216
} ]
357
217
}
358
218
Section :: FunctionSummary { ladfile } => {
@@ -432,8 +292,9 @@ pub enum SectionItem<'a> {
432
292
ladfile : & ' a ladfile:: LadFile ,
433
293
} ,
434
294
TypesSummary {
435
- types : Vec < & ' a LadType > ,
295
+ types : Vec < & ' a LadTypeId > ,
436
296
types_directory : String ,
297
+ ladfile : & ' a ladfile:: LadFile ,
437
298
} ,
438
299
InstancesSummary {
439
300
instances : Vec < ( & ' a Cow < ' static , str > , & ' a LadInstance ) > ,
@@ -529,7 +390,7 @@ impl IntoMarkdown for SectionItem<'_> {
529
390
builder. row ( markdown_vec ! [
530
391
Markdown :: new_paragraph( first_col) . code( ) ,
531
392
Markdown :: Link {
532
- text: second_col. to_owned( ) ,
393
+ text: second_col. to_owned( ) . replace ( " \n " , " " ) ,
533
394
url: format!( "./{}/{}.md" , functions_path, function. identifier) ,
534
395
anchor: false
535
396
}
@@ -540,36 +401,30 @@ impl IntoMarkdown for SectionItem<'_> {
540
401
SectionItem :: TypesSummary {
541
402
types,
542
403
types_directory,
404
+ ladfile,
543
405
} => {
544
406
builder. heading ( 2 , "Types" ) ;
545
407
546
408
// make a table of types as a quick reference, make them link to type details sub-sections
547
409
builder. table ( |builder| {
548
410
builder. headers ( vec ! [ "Type" , "Summary" ] ) ;
549
411
for type_ in types. iter ( ) {
550
- let first_col = type_. identifier . to_string ( ) ;
412
+ let printed_type = print_type ( ladfile, type_) ;
413
+
414
+ let documentation = ladfile. get_type_documentation ( type_) ;
551
415
552
416
// first line with content from documentation trimmed to 100 chars
553
- let second_col = type_
554
- . documentation
555
- . as_deref ( )
556
- . map ( |doc| {
557
- let doc = doc. trim ( ) ;
558
- if doc. len ( ) > 100 {
559
- format ! ( "{}..." , & doc[ ..100 ] )
560
- } else {
561
- doc. to_owned ( )
562
- }
563
- } )
564
- . unwrap_or_else ( || NO_DOCS_STRING . to_owned ( ) ) ;
417
+ let second_col = documentation
418
+ . map ( |doc| markdown_substring ( doc, 100 ) )
419
+ . unwrap_or_else ( || NO_DOCS_STRING ) ;
565
420
566
421
builder. row ( markdown_vec ! [
567
- Markdown :: new_paragraph( first_col ) . code( ) ,
422
+ Markdown :: new_paragraph( printed_type . clone ( ) ) . code( ) ,
568
423
Markdown :: Link {
569
- text: second_col,
424
+ text: second_col. to_owned ( ) . replace ( " \n " , " " ) ,
570
425
url: format!(
571
426
"./{types_directory}/{}.md" ,
572
- linkify_filename( & type_ . identifier )
427
+ linkify_filename( printed_type )
573
428
) ,
574
429
anchor: false
575
430
}
0 commit comments