@@ -101,6 +101,8 @@ pub struct Context {
101101 /// real location of an item. This is used to allow external links to
102102 /// publicly reused items to redirect to the right location.
103103 pub render_redirect_pages : bool ,
104+ /// All the passes that were run on this crate.
105+ pub passes : HashSet < String > ,
104106}
105107
106108/// Indicates where an external crate can be found.
@@ -190,6 +192,7 @@ pub struct Cache {
190192 parent_stack : Vec < ast:: DefId > ,
191193 search_index : Vec < IndexItem > ,
192194 privmod : bool ,
195+ remove_priv : bool ,
193196 public_items : NodeSet ,
194197
195198 // In rare case where a structure is defined in one module but implemented
@@ -236,9 +239,13 @@ local_data_key!(pub cache_key: Arc<Cache>)
236239local_data_key ! ( pub current_location_key: Vec <String > )
237240
238241/// Generates the documentation for `crate` into the directory `dst`
239- pub fn run ( mut krate : clean:: Crate , external_html : & ExternalHtml , dst : Path ) -> io:: IoResult < ( ) > {
242+ pub fn run ( mut krate : clean:: Crate ,
243+ external_html : & ExternalHtml ,
244+ dst : Path ,
245+ passes : HashSet < String > ) -> io:: IoResult < ( ) > {
240246 let mut cx = Context {
241247 dst : dst,
248+ passes : passes,
242249 current : Vec :: new ( ) ,
243250 root_path : String :: new ( ) ,
244251 sidebar : HashMap :: new ( ) ,
@@ -320,6 +327,7 @@ pub fn run(mut krate: clean::Crate, external_html: &ExternalHtml, dst: Path) ->
320327 search_index : Vec :: new ( ) ,
321328 extern_locations : HashMap :: new ( ) ,
322329 primitive_locations : HashMap :: new ( ) ,
330+ remove_priv : cx. passes . contains ( "strip-private" ) ,
323331 privmod : false ,
324332 public_items : public_items,
325333 orphan_methods : Vec :: new ( ) ,
@@ -767,7 +775,7 @@ impl DocFolder for Cache {
767775 let orig_privmod = match item. inner {
768776 clean:: ModuleItem ( ..) => {
769777 let prev = self . privmod ;
770- self . privmod = prev || item. visibility != Some ( ast:: Public ) ;
778+ self . privmod = prev || ( self . remove_priv && item. visibility != Some ( ast:: Public ) ) ;
771779 prev
772780 }
773781 _ => self . privmod ,
@@ -1192,7 +1200,7 @@ impl Context {
11921200 // these modules are recursed into, but not rendered normally (a
11931201 // flag on the context).
11941202 if !self . render_redirect_pages {
1195- self . render_redirect_pages = ignore_private_item ( & item) ;
1203+ self . render_redirect_pages = self . ignore_private_item ( & item) ;
11961204 }
11971205
11981206 match item. inner {
@@ -1211,7 +1219,7 @@ impl Context {
12111219 clean:: ModuleItem ( m) => m,
12121220 _ => unreachable ! ( )
12131221 } ;
1214- this. sidebar = build_sidebar ( & m) ;
1222+ this. sidebar = this . build_sidebar ( & m) ;
12151223 for item in m. items . into_iter ( ) {
12161224 f ( this, item) ;
12171225 }
@@ -1230,6 +1238,40 @@ impl Context {
12301238 _ => Ok ( ( ) )
12311239 }
12321240 }
1241+
1242+ fn build_sidebar ( & self , m : & clean:: Module ) -> HashMap < String , Vec < String > > {
1243+ let mut map = HashMap :: new ( ) ;
1244+ for item in m. items . iter ( ) {
1245+ if self . ignore_private_item ( item) { continue }
1246+
1247+ let short = shortty ( item) . to_static_str ( ) ;
1248+ let myname = match item. name {
1249+ None => continue ,
1250+ Some ( ref s) => s. to_string ( ) ,
1251+ } ;
1252+ let v = match map. entry ( short. to_string ( ) ) {
1253+ Vacant ( entry) => entry. set ( Vec :: with_capacity ( 1 ) ) ,
1254+ Occupied ( entry) => entry. into_mut ( ) ,
1255+ } ;
1256+ v. push ( myname) ;
1257+ }
1258+
1259+ for ( _, items) in map. iter_mut ( ) {
1260+ items. as_mut_slice ( ) . sort ( ) ;
1261+ }
1262+ return map;
1263+ }
1264+
1265+ fn ignore_private_item ( & self , it : & clean:: Item ) -> bool {
1266+ match it. inner {
1267+ clean:: ModuleItem ( ref m) => {
1268+ ( m. items . len ( ) == 0 && it. doc_value ( ) . is_none ( ) ) ||
1269+ ( self . passes . contains ( "strip-private" ) && it. visibility != Some ( ast:: Public ) )
1270+ }
1271+ clean:: PrimitiveItem ( ..) => it. visibility != Some ( ast:: Public ) ,
1272+ _ => false ,
1273+ }
1274+ }
12331275}
12341276
12351277impl < ' a > Item < ' a > {
@@ -1443,7 +1485,7 @@ fn item_module(w: &mut fmt::Formatter, cx: &Context,
14431485 try!( document ( w, item) ) ;
14441486
14451487 let mut indices = range ( 0 , items. len ( ) ) . filter ( |i| {
1446- !ignore_private_item ( & items[ * i] )
1488+ !cx . ignore_private_item ( & items[ * i] )
14471489 } ) . collect :: < Vec < uint > > ( ) ;
14481490
14491491 fn cmp ( i1 : & clean:: Item , i2 : & clean:: Item , idx1 : uint , idx2 : uint ) -> Ordering {
@@ -2157,29 +2199,6 @@ impl<'a> fmt::Show for Sidebar<'a> {
21572199 }
21582200}
21592201
2160- fn build_sidebar ( m : & clean:: Module ) -> HashMap < String , Vec < String > > {
2161- let mut map = HashMap :: new ( ) ;
2162- for item in m. items . iter ( ) {
2163- if ignore_private_item ( item) { continue }
2164-
2165- let short = shortty ( item) . to_static_str ( ) ;
2166- let myname = match item. name {
2167- None => continue ,
2168- Some ( ref s) => s. to_string ( ) ,
2169- } ;
2170- let v = match map. entry ( short. to_string ( ) ) {
2171- Vacant ( entry) => entry. set ( Vec :: with_capacity ( 1 ) ) ,
2172- Occupied ( entry) => entry. into_mut ( ) ,
2173- } ;
2174- v. push ( myname) ;
2175- }
2176-
2177- for ( _, items) in map. iter_mut ( ) {
2178- items. as_mut_slice ( ) . sort ( ) ;
2179- }
2180- return map;
2181- }
2182-
21832202impl < ' a > fmt:: Show for Source < ' a > {
21842203 fn fmt ( & self , fmt : & mut fmt:: Formatter ) -> fmt:: Result {
21852204 let Source ( s) = * self ;
@@ -2214,17 +2233,6 @@ fn item_primitive(w: &mut fmt::Formatter,
22142233 render_methods ( w, it)
22152234}
22162235
2217- fn ignore_private_item ( it : & clean:: Item ) -> bool {
2218- match it. inner {
2219- clean:: ModuleItem ( ref m) => {
2220- ( m. items . len ( ) == 0 && it. doc_value ( ) . is_none ( ) ) ||
2221- it. visibility != Some ( ast:: Public )
2222- }
2223- clean:: PrimitiveItem ( ..) => it. visibility != Some ( ast:: Public ) ,
2224- _ => false ,
2225- }
2226- }
2227-
22282236fn get_basic_keywords ( ) -> & ' static str {
22292237 "rust, rustlang, rust-lang"
22302238}
0 commit comments