rustdoc: Refactor markdown_pass
This commit is contained in:
parent
2dd5b3ace6
commit
2ac6dbc9ba
@ -3,6 +3,7 @@ import std::getopts;
|
||||
export output_format::{};
|
||||
export output_style::{};
|
||||
export config;
|
||||
export default_config;
|
||||
export parse_config;
|
||||
export usage;
|
||||
|
||||
|
@ -5,40 +5,19 @@ import std::io::writer_util;
|
||||
|
||||
export mk_pass;
|
||||
|
||||
fn mk_pass(config: config::config) -> pass {
|
||||
mk_pass_(config, {|f| f(std::io::stdout()) })
|
||||
}
|
||||
|
||||
// FIXME: This is a really convoluted interface to work around trying
|
||||
// to get a writer into a unique closure and then being able to test
|
||||
// what was written afterward
|
||||
fn mk_pass(
|
||||
fn mk_pass_(
|
||||
config: config::config,
|
||||
give_writer: fn~(fn(io::writer))
|
||||
) -> pass {
|
||||
let f = fn~(
|
||||
srv: astsrv::srv,
|
||||
doc: doc::cratedoc
|
||||
) -> doc::cratedoc {
|
||||
|
||||
fn mods_last(item1: doc::itemtag, item2: doc::itemtag) -> bool {
|
||||
fn is_mod(item: doc::itemtag) -> bool {
|
||||
alt item {
|
||||
doc::modtag(_) { true }
|
||||
_ { false }
|
||||
}
|
||||
}
|
||||
|
||||
let lteq = !is_mod(item1) || is_mod(item2);
|
||||
lteq
|
||||
}
|
||||
|
||||
give_writer {|writer|
|
||||
// Sort the items so mods come last. All mods will be
|
||||
// output at the same header level so sorting mods last
|
||||
// makes the headers come out nested correctly.
|
||||
let sorted_doc = sort_pass::mk_pass(
|
||||
"mods last", mods_last
|
||||
).f(srv, doc);
|
||||
|
||||
write_markdown(sorted_doc, writer);
|
||||
}
|
||||
doc
|
||||
let f = fn~(srv: astsrv::srv, doc: doc::cratedoc) -> doc::cratedoc {
|
||||
run(srv, doc, config, give_writer)
|
||||
};
|
||||
|
||||
{
|
||||
@ -47,6 +26,38 @@ fn mk_pass(
|
||||
}
|
||||
}
|
||||
|
||||
fn run(
|
||||
srv: astsrv::srv,
|
||||
doc: doc::cratedoc,
|
||||
_config: config::config,
|
||||
give_writer: fn~(fn(io::writer))
|
||||
) -> doc::cratedoc {
|
||||
|
||||
fn mods_last(item1: doc::itemtag, item2: doc::itemtag) -> bool {
|
||||
fn is_mod(item: doc::itemtag) -> bool {
|
||||
alt item {
|
||||
doc::modtag(_) { true }
|
||||
_ { false }
|
||||
}
|
||||
}
|
||||
|
||||
let lteq = !is_mod(item1) || is_mod(item2);
|
||||
lteq
|
||||
}
|
||||
|
||||
give_writer {|writer|
|
||||
// Sort the items so mods come last. All mods will be
|
||||
// output at the same header level so sorting mods last
|
||||
// makes the headers come out nested correctly.
|
||||
let sorted_doc = sort_pass::mk_pass(
|
||||
"mods last", mods_last
|
||||
).f(srv, doc);
|
||||
|
||||
write_markdown(sorted_doc, writer);
|
||||
}
|
||||
doc
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn should_write_modules_last() {
|
||||
/*
|
||||
@ -858,7 +869,7 @@ mod test {
|
||||
let port = comm::port();
|
||||
let chan = comm::chan(port);
|
||||
|
||||
let pass = mk_pass {|f|
|
||||
let pass = mk_pass_(config::default_config("")) {|f|
|
||||
let buffer = io::mk_mem_buffer();
|
||||
let writer = io::mem_buffer_writer(buffer);
|
||||
f(writer);
|
||||
|
@ -108,7 +108,7 @@ fn main(args: [str]) {
|
||||
}
|
||||
};
|
||||
|
||||
run(config.input_crate);
|
||||
run(config);
|
||||
}
|
||||
|
||||
fn time<T>(what: str, f: fn() -> T) -> T {
|
||||
@ -120,14 +120,15 @@ fn time<T>(what: str, f: fn() -> T) -> T {
|
||||
}
|
||||
|
||||
#[doc = "Runs rustdoc over the given file"]
|
||||
fn run(source_file: str) {
|
||||
fn run(config: config::config) {
|
||||
|
||||
let default_name = source_file;
|
||||
let source_file = config.input_crate;
|
||||
astsrv::from_file(source_file) {|srv|
|
||||
time("wait_ast") {||
|
||||
astsrv::exec(srv) {|_ctxt| () }
|
||||
};
|
||||
let doc = time("extract") {||
|
||||
let default_name = source_file;
|
||||
extract::from_srv(srv, default_name)
|
||||
};
|
||||
run_passes(srv, doc, [
|
||||
@ -144,7 +145,7 @@ fn run(source_file: str) {
|
||||
unindent_pass::mk_pass(),
|
||||
sort_item_name_pass::mk_pass(),
|
||||
sort_item_type_pass::mk_pass(),
|
||||
markdown_pass::mk_pass {|f| f(std::io:: stdout()) }
|
||||
markdown_pass::mk_pass(config)
|
||||
]);
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user