]> git.proxmox.com Git - rustc.git/blob - src/librustdoc/passes/collapse_docs.rs
3c63302127c5eef17b7df6e4818d3851d1f9db0d
[rustc.git] / src / librustdoc / passes / collapse_docs.rs
1 // Copyright 2012-2014 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
4 //
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
10
11 use clean::{self, Item};
12 use plugins;
13 use fold;
14 use fold::DocFolder;
15
16 pub fn collapse_docs(krate: clean::Crate) -> plugins::PluginResult {
17 Collapser.fold_crate(krate)
18 }
19
20 struct Collapser;
21
22 impl fold::DocFolder for Collapser {
23 fn fold_item(&mut self, mut i: Item) -> Option<Item> {
24 i.attrs.collapse_doc_comments();
25 self.fold_item_recur(i)
26 }
27 }
28
29 impl clean::Attributes {
30 pub fn collapse_doc_comments(&mut self) {
31 let mut doc_string = self.doc_strings.join("\n");
32 if doc_string.is_empty() {
33 self.doc_strings = vec![];
34 } else {
35 // FIXME(eddyb) Is this still needed?
36 doc_string.push('\n');
37 self.doc_strings = vec![doc_string];
38 }
39 }
40 }