Skip to content

Commit 4fd061c

Browse files
committed
Implement a web backend for rustdoc_ng
This large commit implements and `html` output option for rustdoc_ng. The executable has been altered to be invoked as "rustdoc_ng html <crate>" and it will dump everything into the local "doc" directory. JSON can still be generated by changing 'html' to 'json'. This also fixes a number of bugs in rustdoc_ng relating to comment stripping, along with some other various issues that I found along the way. The `make doc` command has been altered to generate the new documentation into the `doc/ng/$(CRATE)` directories.
1 parent a95604f commit 4fd061c

22 files changed

+3061
-133
lines changed

RELEASES.txt

+1
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,7 @@ Version 0.8 (October 2013)
142142
* The runtime uses jemalloc for allocations.
143143
* Segmented stacks are temporarily disabled as part of the transition to
144144
the new runtime. Stack overflows are possible!
145+
* A new documentation backend, rustdoc_ng, is available for use
145146

146147
Version 0.7 (July 2013)
147148
-----------------------

mk/docs.mk

+15
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,7 @@ else
213213

214214
# The rustdoc executable
215215
RUSTDOC = $(HBIN2_H_$(CFG_BUILD_TRIPLE))/rustdoc$(X_$(CFG_BUILD_TRIPLE))
216+
RUSTDOC_NG = $(HBIN2_H_$(CFG_BUILD_TRIPLE))/rustdoc_ng$(X_$(CFG_BUILD_TRIPLE))
216217

217218
# The library documenting macro
218219
# $(1) - The output directory
@@ -230,8 +231,22 @@ doc/$(1)/rust.css: rust.css
230231
DOCS += doc/$(1)/index.html
231232
endef
232233

234+
# The library documenting macro
235+
# $(1) - The output directory
236+
# $(2) - The crate file
237+
# $(3) - The crate soruce files
238+
define libdocng
239+
doc/ng/$(1)/index.html: $(2) $(3) $$(RUSTDOC_NG)
240+
@$$(call E, rustdoc_ng: $$@)
241+
$(Q)$(RUSTDOC_NG) html $(2) -o doc/ng
242+
243+
DOCS += doc/ng/$(1)/index.html
244+
endef
245+
233246
$(eval $(call libdoc,std,$(STDLIB_CRATE),$(STDLIB_INPUTS)))
234247
$(eval $(call libdoc,extra,$(EXTRALIB_CRATE),$(EXTRALIB_INPUTS)))
248+
$(eval $(call libdocng,std,$(STDLIB_CRATE),$(STDLIB_INPUTS)))
249+
$(eval $(call libdocng,extra,$(EXTRALIB_CRATE),$(EXTRALIB_INPUTS)))
235250
endif
236251

237252

src/libextra/extra.rs

+4
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@ Rust extras are part of the standard Rust distribution.
2525
uuid = "122bed0b-c19b-4b82-b0b7-7ae8aead7297",
2626
url = "https://github.com/mozilla/rust/tree/master/src/libextra")];
2727

28+
#[doc(html_logo_url = "http://www.rust-lang.org/logos/rust-logo-128x128-blk.png",
29+
html_favicon_url = "http://www.rust-lang.org/favicon.ico",
30+
passes = "strip-hidden")];
31+
2832
#[comment = "Rust extras"];
2933
#[license = "MIT/ASL2"];
3034
#[crate_type = "lib"];

src/libstd/macros.rs

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
// except according to those terms.
1010

1111
#[macro_escape];
12+
#[doc(hidden)];
1213

1314
macro_rules! rterrln (
1415
($( $arg:expr),+) => ( {

src/libstd/num/int_macros.rs

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
// FIXME(#4375): this shouldn't have to be a nested module named 'generated'
1212

1313
#[macro_escape];
14+
#[doc(hidden)];
1415

1516
macro_rules! int_module (($T:ty, $bits:expr) => (mod generated {
1617

src/libstd/num/uint_macros.rs

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
// FIXME(#4375): this shouldn't have to be a nested module named 'generated'
1212

1313
#[macro_escape];
14+
#[doc(hidden)];
1415

1516
macro_rules! uint_module (($T:ty, $T_SIGNED:ty, $bits:expr) => (mod generated {
1617

src/libstd/rt/mod.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,8 @@ Several modules in `core` are clients of `rt`:
5454
5555
*/
5656

57-
#[doc(hidden)];
57+
// XXX: this should not be here.
58+
#[allow(missing_doc)];
5859

5960
use cell::Cell;
6061
use clone::Clone;

src/libstd/std.rs

+4
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,10 @@ they contained the following prologue:
5757
#[license = "MIT/ASL2"];
5858
#[crate_type = "lib"];
5959

60+
#[doc(html_logo_url = "http://www.rust-lang.org/logos/rust-logo-128x128-blk.png",
61+
html_favicon_url = "http://www.rust-lang.org/favicon.ico",
62+
passes = "strip-hidden")];
63+
6064
// Don't link to std. We are std.
6165
#[no_std];
6266

src/libsyntax/ext/format.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ impl Context {
262262
let span = match self.names.find(&name) {
263263
Some(e) => e.span,
264264
None => {
265-
let msg = fmt!("There is no argument named `%s`", name);
265+
let msg = fmt!("there is no argument named `%s`", name);
266266
self.ecx.span_err(self.fmtsp, msg);
267267
return;
268268
}

src/libsyntax/parse/comments.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -107,9 +107,7 @@ pub fn strip_doc_comment_decoration(comment: &str) -> ~str {
107107
}
108108

109109
if comment.starts_with("//") {
110-
// FIXME #5475:
111-
// return comment.slice(3u, comment.len()).to_owned();
112-
let r = comment.slice(3u, comment.len()); return r.to_owned();
110+
return comment.slice(3u, comment.len()).to_owned();
113111
}
114112

115113
if comment.starts_with("/*") {

src/rustdoc_ng/clean.rs

+52-3
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ use its = syntax::parse::token::ident_to_str;
1515

1616
use syntax;
1717
use syntax::ast;
18+
use syntax::attr::AttributeMethods;
1819

1920
use std;
2021
use doctree;
@@ -90,6 +91,48 @@ pub struct Item {
9091
id: ast::NodeId,
9192
}
9293

94+
impl Item {
95+
/// Finds the `doc` attribute as a List and returns the list of attributes
96+
/// nested inside.
97+
pub fn doc_list<'a>(&'a self) -> Option<&'a [Attribute]> {
98+
for attr in self.attrs.iter() {
99+
match *attr {
100+
List(~"doc", ref list) => { return Some(list.as_slice()); }
101+
_ => {}
102+
}
103+
}
104+
return None;
105+
}
106+
107+
/// Finds the `doc` attribute as a NameValue and returns the corresponding
108+
/// value found.
109+
pub fn doc_value<'a>(&'a self) -> Option<&'a str> {
110+
for attr in self.attrs.iter() {
111+
match *attr {
112+
NameValue(~"doc", ref v) => { return Some(v.as_slice()); }
113+
_ => {}
114+
}
115+
}
116+
return None;
117+
}
118+
119+
pub fn is_mod(&self) -> bool {
120+
match self.inner { ModuleItem(*) => true, _ => false }
121+
}
122+
pub fn is_trait(&self) -> bool {
123+
match self.inner { TraitItem(*) => true, _ => false }
124+
}
125+
pub fn is_struct(&self) -> bool {
126+
match self.inner { StructItem(*) => true, _ => false }
127+
}
128+
pub fn is_enum(&self) -> bool {
129+
match self.inner { EnumItem(*) => true, _ => false }
130+
}
131+
pub fn is_fn(&self) -> bool {
132+
match self.inner { FunctionItem(*) => true, _ => false }
133+
}
134+
}
135+
93136
#[deriving(Clone, Encodable, Decodable)]
94137
pub enum ItemEnum {
95138
StructItem(Struct),
@@ -155,7 +198,7 @@ impl Clean<Attribute> for ast::MetaItem {
155198

156199
impl Clean<Attribute> for ast::Attribute {
157200
fn clean(&self) -> Attribute {
158-
self.node.value.clean()
201+
self.desugar_doc().node.value.clean()
159202
}
160203
}
161204

@@ -437,18 +480,24 @@ pub enum TraitMethod {
437480
}
438481

439482
impl TraitMethod {
440-
fn is_req(&self) -> bool {
483+
pub fn is_req(&self) -> bool {
441484
match self {
442485
&Required(*) => true,
443486
_ => false,
444487
}
445488
}
446-
fn is_def(&self) -> bool {
489+
pub fn is_def(&self) -> bool {
447490
match self {
448491
&Provided(*) => true,
449492
_ => false,
450493
}
451494
}
495+
pub fn item<'a>(&'a self) -> &'a Item {
496+
match *self {
497+
Required(ref item) => item,
498+
Provided(ref item) => item,
499+
}
500+
}
452501
}
453502

454503
impl Clean<TraitMethod> for ast::trait_method {

src/rustdoc_ng/fold.rs

+4-16
Original file line numberDiff line numberDiff line change
@@ -91,21 +91,9 @@ pub trait DocFolder {
9191
}
9292

9393
fn fold_crate(&mut self, mut c: Crate) -> Crate {
94-
let mut mod_ = None;
95-
std::util::swap(&mut mod_, &mut c.module);
96-
let mod_ = mod_.unwrap();
97-
c.module = self.fold_item(mod_);
98-
let Crate { name, module } = c;
99-
match module {
100-
Some(Item { inner: ModuleItem(m), name: name_, attrs: attrs_,
101-
source, visibility: vis, id }) => {
102-
return Crate { module: Some(Item { inner:
103-
ModuleItem(self.fold_mod(m)),
104-
name: name_, attrs: attrs_,
105-
source: source, id: id, visibility: vis }), name: name};
106-
},
107-
Some(_) => fail!("non-module item set as module of crate"),
108-
None => return Crate { module: None, name: name},
109-
}
94+
c.module = match std::util::replace(&mut c.module, None) {
95+
Some(module) => self.fold_item(module), None => None
96+
};
97+
return c;
11098
}
11199
}

0 commit comments

Comments
 (0)