rustdoc: Move markdown-writing functions into gen module
This commit is contained in:
@@ -22,41 +22,6 @@ type rustdoc = {
|
||||
w: io::writer
|
||||
};
|
||||
|
||||
#[doc(
|
||||
brief = "Documents a single function.",
|
||||
args(rd = "Rustdoc context",
|
||||
ident = "Identifier for this function",
|
||||
doc = "Function docs extracted from attributes",
|
||||
_fn = "AST object representing this function")
|
||||
)]
|
||||
fn doc_fn(rd: rustdoc, ident: str, doc: doc::fndoc, decl: ast::fn_decl) {
|
||||
rd.w.write_line("## Function `" + ident + "`");
|
||||
rd.w.write_line(doc.brief);
|
||||
alt doc.desc {
|
||||
some(_d) {
|
||||
rd.w.write_line("");
|
||||
rd.w.write_line(_d);
|
||||
rd.w.write_line("");
|
||||
}
|
||||
none. { }
|
||||
}
|
||||
for arg: ast::arg in decl.inputs {
|
||||
rd.w.write_str("### Argument `" + arg.ident + "`: ");
|
||||
rd.w.write_line("`" + pprust::ty_to_str(arg.ty) + "`");
|
||||
alt doc.args.find(arg.ident) {
|
||||
some(_d) {
|
||||
rd.w.write_line(_d);
|
||||
}
|
||||
none. { }
|
||||
};
|
||||
}
|
||||
rd.w.write_line("### Returns `" + pprust::ty_to_str(decl.output) + "`");
|
||||
alt doc.return {
|
||||
some(_r) { rd.w.write_line(_r); }
|
||||
none. { }
|
||||
}
|
||||
}
|
||||
|
||||
#[doc(
|
||||
brief = "Parses function docs from a complex #[doc] attribute.",
|
||||
desc = "Supported attributes:
|
||||
@@ -152,7 +117,7 @@ fn doc_item(rd: rustdoc, item: @ast::item) {
|
||||
alt item.node {
|
||||
ast::item_const(ty, expr) { }
|
||||
ast::item_fn(decl, _, _) {
|
||||
doc_fn(rd, item.ident, _fndoc0, decl);
|
||||
gen::write_fndoc(rd, item.ident, _fndoc0, decl);
|
||||
}
|
||||
ast::item_mod(_mod) { }
|
||||
ast::item_ty(ty, typarams) { }
|
||||
@@ -161,15 +126,6 @@ fn doc_item(rd: rustdoc, item: @ast::item) {
|
||||
};
|
||||
}
|
||||
|
||||
#[doc(
|
||||
brief = "Generate a crate document header.",
|
||||
args(rd = "Rustdoc context",
|
||||
name = "Crate name")
|
||||
)]
|
||||
fn doc_header(rd: rustdoc, name: str) {
|
||||
rd.w.write_line("# Crate " + name);
|
||||
}
|
||||
|
||||
#[doc(
|
||||
brief = "Main function.",
|
||||
desc = "Command-line arguments:
|
||||
@@ -188,7 +144,7 @@ fn main(argv: [str]) {
|
||||
|
||||
let w = io::stdout();
|
||||
let rd = { ps: pprust::rust_printer(w), w: w };
|
||||
doc_header(rd, argv[1]);
|
||||
gen::write_header(rd, argv[1]);
|
||||
|
||||
let v = visit::mk_simple_visitor(@{
|
||||
visit_item: bind doc_item(rd, _)
|
||||
|
||||
Reference in New Issue
Block a user