@@ -101,6 +101,8 @@ pub struct Context {
101
101
/// real location of an item. This is used to allow external links to
102
102
/// publicly reused items to redirect to the right location.
103
103
pub render_redirect_pages : bool ,
104
+ /// All the passes that were run on this crate.
105
+ pub passes : HashSet < String > ,
104
106
}
105
107
106
108
/// Indicates where an external crate can be found.
@@ -190,6 +192,7 @@ pub struct Cache {
190
192
parent_stack : Vec < ast:: DefId > ,
191
193
search_index : Vec < IndexItem > ,
192
194
privmod : bool ,
195
+ remove_priv : bool ,
193
196
public_items : NodeSet ,
194
197
195
198
// 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>)
236
239
local_data_key ! ( pub current_location_key: Vec <String > )
237
240
238
241
/// 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 < ( ) > {
240
246
let mut cx = Context {
241
247
dst : dst,
248
+ passes : passes,
242
249
current : Vec :: new ( ) ,
243
250
root_path : String :: new ( ) ,
244
251
sidebar : HashMap :: new ( ) ,
@@ -320,6 +327,7 @@ pub fn run(mut krate: clean::Crate, external_html: &ExternalHtml, dst: Path) ->
320
327
search_index : Vec :: new ( ) ,
321
328
extern_locations : HashMap :: new ( ) ,
322
329
primitive_locations : HashMap :: new ( ) ,
330
+ remove_priv : cx. passes . contains ( "strip-private" ) ,
323
331
privmod : false ,
324
332
public_items : public_items,
325
333
orphan_methods : Vec :: new ( ) ,
@@ -767,7 +775,7 @@ impl DocFolder for Cache {
767
775
let orig_privmod = match item. inner {
768
776
clean:: ModuleItem ( ..) => {
769
777
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 ) ) ;
771
779
prev
772
780
}
773
781
_ => self . privmod ,
@@ -1192,7 +1200,7 @@ impl Context {
1192
1200
// these modules are recursed into, but not rendered normally (a
1193
1201
// flag on the context).
1194
1202
if !self . render_redirect_pages {
1195
- self . render_redirect_pages = ignore_private_item ( & item) ;
1203
+ self . render_redirect_pages = self . ignore_private_item ( & item) ;
1196
1204
}
1197
1205
1198
1206
match item. inner {
@@ -1211,7 +1219,7 @@ impl Context {
1211
1219
clean:: ModuleItem ( m) => m,
1212
1220
_ => unreachable ! ( )
1213
1221
} ;
1214
- this. sidebar = build_sidebar ( & m) ;
1222
+ this. sidebar = this . build_sidebar ( & m) ;
1215
1223
for item in m. items . into_iter ( ) {
1216
1224
f ( this, item) ;
1217
1225
}
@@ -1230,6 +1238,40 @@ impl Context {
1230
1238
_ => Ok ( ( ) )
1231
1239
}
1232
1240
}
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
+ }
1233
1275
}
1234
1276
1235
1277
impl < ' a > Item < ' a > {
@@ -1443,7 +1485,7 @@ fn item_module(w: &mut fmt::Formatter, cx: &Context,
1443
1485
try!( document ( w, item) ) ;
1444
1486
1445
1487
let mut indices = range ( 0 , items. len ( ) ) . filter ( |i| {
1446
- !ignore_private_item ( & items[ * i] )
1488
+ !cx . ignore_private_item ( & items[ * i] )
1447
1489
} ) . collect :: < Vec < uint > > ( ) ;
1448
1490
1449
1491
fn cmp ( i1 : & clean:: Item , i2 : & clean:: Item , idx1 : uint , idx2 : uint ) -> Ordering {
@@ -2157,29 +2199,6 @@ impl<'a> fmt::Show for Sidebar<'a> {
2157
2199
}
2158
2200
}
2159
2201
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
-
2183
2202
impl < ' a > fmt:: Show for Source < ' a > {
2184
2203
fn fmt ( & self , fmt : & mut fmt:: Formatter ) -> fmt:: Result {
2185
2204
let Source ( s) = * self ;
@@ -2214,17 +2233,6 @@ fn item_primitive(w: &mut fmt::Formatter,
2214
2233
render_methods ( w, it)
2215
2234
}
2216
2235
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
-
2228
2236
fn get_basic_keywords ( ) -> & ' static str {
2229
2237
"rust, rustlang, rust-lang"
2230
2238
}
0 commit comments