Skip to content

Commit

Permalink
[documentation] Add support for descriptions for various entities [#95]
Browse files Browse the repository at this point in the history
  • Loading branch information
cipriancraciun committed Jun 26, 2018
1 parent 34e1c19 commit 3883040
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 17 deletions.
30 changes: 28 additions & 2 deletions sources/documentation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2170,8 +2170,34 @@ fn parse_object_with_attributes (input : Value, keyword : Option<&str>, identifi


#[ cfg_attr ( feature = "vonuvoli_inline", inline ) ]
fn parse_description (_input : StdVec<Value>) -> (Outcome<Description>) {
fail_unimplemented! (0x5ca7dcd4);
fn parse_description (input : StdVec<Value>) -> (Outcome<Description>) {

let input = try! (vec_explode_1 (input));
let input = try_as_string_ref! (&input);

let mut lines = vec_map! (input.string_as_str () .lines (), line, StdRc::new (StdString::from (line.trim_right ()) .into_boxed_str ()));

for _ in 0..2 {
loop {
let pop = if let Some (line) = lines.last () {
line.trim_left () .is_empty ()
} else {
break;
};
if pop {
lines.pop ();
} else {
break;
}
}
lines.reverse ();
}

let description = Description {
lines,
};

succeed! (description);
}

#[ cfg_attr ( feature = "vonuvoli_inline", inline ) ]
Expand Down
60 changes: 45 additions & 15 deletions sources/tools_documentation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,39 @@ pub fn dump_cmark (libraries : Libraries, stream : &mut dyn io::Write) -> (Outco
}


#[ cfg_attr ( feature = "vonuvoli_inline", inline ) ]
fn write_description (description : Option<&Description>, stream : &mut dyn io::Write) -> (Outcome<()>) {
let description = if let Some (description) = description {
description
} else {
succeed! (());
};
try_writeln! (stream);
try_writeln! (stream);
try_writeln! (stream, "#### Description");
try_writeln! (stream);
for line in description.lines () {
try_writeln! (stream, "> {}", line);
}
try_writeln! (stream);
succeed! (());
}

#[ cfg_attr ( feature = "vonuvoli_inline", inline ) ]
fn write_links (links : Option<&Links>, stream : &mut dyn io::Write) -> (Outcome<()>) {
let links = if let Some (links) = links {
links
} else {
succeed! (());
};
try_writeln! (stream);
try_writeln! (stream);
try_writeln! (stream, "#### Links");
try_writeln! (stream);
fail_unimplemented! (0x81cb5f76);
}


for library in libraries.libraries () {

let library_anchor = try! (generate_anchor (Some ("library"), Some (library.identifier ()), None));
Expand All @@ -412,6 +445,9 @@ pub fn dump_cmark (libraries : Libraries, stream : &mut dyn io::Write) -> (Outco
try_writeln! (stream, "# `{}`", library.identifier ());
}

try! (write_description (library.description (), stream));
try! (write_links (library.links (), stream));

try_writeln! (stream);
try_writeln! (stream, "Goto: [library](#{}), [categories](#{}), [types](#{}), [definitions](#{}).", &library_anchor, &categories_anchor, &value_kinds_anchor, &definitions_anchor);
try_writeln! (stream);
Expand Down Expand Up @@ -469,11 +505,6 @@ pub fn dump_cmark (libraries : Libraries, stream : &mut dyn io::Write) -> (Outco

try_writeln! (stream, "### Category `{}`", category.identifier ());

{
// ... description
// ... links
}

if let Some (super_category) = category.parent () {
let super_category_anchor = try! (generate_anchor (Some ("category"), Some (library.identifier ()), Some (super_category.identifier ())));
try_writeln! (stream);
Expand Down Expand Up @@ -506,6 +537,9 @@ pub fn dump_cmark (libraries : Libraries, stream : &mut dyn io::Write) -> (Outco
}
}

try! (write_description (category.description (), stream));
try! (write_links (category.links (), stream));

try_writeln! (stream);
try_writeln! (stream, "Goto: [library](#{}), [categories](#{}), [types](#{}), [definitions](#{}).", &library_anchor, &categories_anchor, &value_kinds_anchor, &definitions_anchor);
try_writeln! (stream);
Expand Down Expand Up @@ -565,11 +599,6 @@ pub fn dump_cmark (libraries : Libraries, stream : &mut dyn io::Write) -> (Outco

try_writeln! (stream, "### Type `{}`", value_kind.identifier ());

{
// ... description
// ... links
}

if value_kind.has_aliases () {
try_writeln! (stream);
try_writeln! (stream, "With the following aliases:");
Expand Down Expand Up @@ -618,6 +647,9 @@ pub fn dump_cmark (libraries : Libraries, stream : &mut dyn io::Write) -> (Outco
}
}

try! (write_description (value_kind.description (), stream));
try! (write_links (value_kind.links (), stream));

try_writeln! (stream);
try_writeln! (stream, "Goto: [library](#{}), [categories](#{}), [types](#{}), [definitions](#{}).", &library_anchor, &categories_anchor, &value_kinds_anchor, &definitions_anchor);
try_writeln! (stream);
Expand Down Expand Up @@ -659,11 +691,6 @@ pub fn dump_cmark (libraries : Libraries, stream : &mut dyn io::Write) -> (Outco

try_writeln! (stream, "### Definition `{}`", definition.identifier ());

{
// ... description
// ... links
}

{
try_writeln! (stream);
try_writeln! (stream, "Has the following kind: `{}`.", definition.kind () .identifier ());
Expand Down Expand Up @@ -695,6 +722,9 @@ pub fn dump_cmark (libraries : Libraries, stream : &mut dyn io::Write) -> (Outco
}
}

try! (write_description (definition.description (), stream));
try! (write_links (definition.links (), stream));

if let Some (procedure_signature) = definition.procedure_signature () {
try_writeln! (stream);
try_writeln! (stream, "#### Procedure signature");
Expand Down

0 comments on commit 3883040

Please sign in to comment.