@@ -54,6 +54,9 @@ use std::rc::Rc;
5454
5555use externalfiles:: ExternalHtml ;
5656
57+ use errors;
58+ use getopts;
59+
5760use serialize:: json:: { ToJson , Json , as_json} ;
5861use syntax:: ast;
5962use syntax:: ext:: base:: MacroKind ;
@@ -106,6 +109,8 @@ struct Context {
106109 /// The map used to ensure all generated 'id=' attributes are unique.
107110 id_map : Rc < RefCell < IdMap > > ,
108111 pub shared : Arc < SharedContext > ,
112+ pub enable_index_page : bool ,
113+ pub index_page : Option < PathBuf > ,
109114}
110115
111116struct SharedContext {
@@ -501,7 +506,12 @@ pub fn run(mut krate: clean::Crate,
501506 sort_modules_alphabetically : bool ,
502507 themes : Vec < PathBuf > ,
503508 enable_minification : bool ,
504- id_map : IdMap ) -> Result < ( ) , Error > {
509+ id_map : IdMap ,
510+ enable_index_page : bool ,
511+ index_page : Option < PathBuf > ,
512+ matches : & getopts:: Matches ,
513+ diag : & errors:: Handler ,
514+ ) -> Result < ( ) , Error > {
505515 let src_root = match krate. src {
506516 FileName :: Real ( ref p) => match p. parent ( ) {
507517 Some ( p) => p. to_path_buf ( ) ,
@@ -572,6 +582,8 @@ pub fn run(mut krate: clean::Crate,
572582 codes : ErrorCodes :: from ( UnstableFeatures :: from_environment ( ) . is_nightly_build ( ) ) ,
573583 id_map : Rc :: new ( RefCell :: new ( id_map) ) ,
574584 shared : Arc :: new ( scx) ,
585+ enable_index_page,
586+ index_page,
575587 } ;
576588
577589 // Crawl the crate to build various caches used for the output
@@ -666,7 +678,7 @@ pub fn run(mut krate: clean::Crate,
666678 CACHE_KEY . with ( |v| * v. borrow_mut ( ) = cache. clone ( ) ) ;
667679 CURRENT_LOCATION_KEY . with ( |s| s. borrow_mut ( ) . clear ( ) ) ;
668680
669- write_shared ( & cx, & krate, & * cache, index, enable_minification) ?;
681+ write_shared ( & cx, & krate, & * cache, index, enable_minification, matches , diag ) ?;
670682
671683 // And finally render the whole crate's documentation
672684 cx. krate ( krate)
@@ -742,11 +754,15 @@ fn build_index(krate: &clean::Crate, cache: &mut Cache) -> String {
742754 Json :: Object ( crate_data) )
743755}
744756
745- fn write_shared ( cx : & Context ,
746- krate : & clean:: Crate ,
747- cache : & Cache ,
748- search_index : String ,
749- enable_minification : bool ) -> Result < ( ) , Error > {
757+ fn write_shared (
758+ cx : & Context ,
759+ krate : & clean:: Crate ,
760+ cache : & Cache ,
761+ search_index : String ,
762+ enable_minification : bool ,
763+ matches : & getopts:: Matches ,
764+ diag : & errors:: Handler ,
765+ ) -> Result < ( ) , Error > {
750766 // Write out the shared files. Note that these are shared among all rustdoc
751767 // docs placed in the output directory, so this needs to be a synchronized
752768 // operation with respect to all other rustdocs running around.
@@ -902,8 +918,9 @@ themePicker.onblur = handleThemeButtonsBlur;
902918 write ( cx. dst . join ( "COPYRIGHT.txt" ) ,
903919 include_bytes ! ( "static/COPYRIGHT.txt" ) ) ?;
904920
905- fn collect ( path : & Path , krate : & str , key : & str ) -> io:: Result < Vec < String > > {
921+ fn collect ( path : & Path , krate : & str , key : & str ) -> io:: Result < ( Vec < String > , Vec < String > ) > {
906922 let mut ret = Vec :: new ( ) ;
923+ let mut krates = Vec :: new ( ) ;
907924 if path. exists ( ) {
908925 for line in BufReader :: new ( File :: open ( path) ?) . lines ( ) {
909926 let line = line?;
@@ -914,9 +931,13 @@ themePicker.onblur = handleThemeButtonsBlur;
914931 continue ;
915932 }
916933 ret. push ( line. to_string ( ) ) ;
934+ krates. push ( line[ key. len ( ) + 2 ..] . split ( '"' )
935+ . next ( )
936+ . map ( |s| s. to_owned ( ) )
937+ . unwrap_or_else ( || String :: new ( ) ) ) ;
917938 }
918939 }
919- Ok ( ret)
940+ Ok ( ( ret, krates ) )
920941 }
921942
922943 fn show_item ( item : & IndexItem , krate : & str ) -> String {
@@ -931,7 +952,7 @@ themePicker.onblur = handleThemeButtonsBlur;
931952
932953 let dst = cx. dst . join ( "aliases.js" ) ;
933954 {
934- let mut all_aliases = try_err ! ( collect( & dst, & krate. name, "ALIASES" ) , & dst) ;
955+ let ( mut all_aliases, _ ) = try_err ! ( collect( & dst, & krate. name, "ALIASES" ) , & dst) ;
935956 let mut w = try_err ! ( File :: create( & dst) , & dst) ;
936957 let mut output = String :: with_capacity ( 100 ) ;
937958 for ( alias, items) in & cache. aliases {
@@ -955,7 +976,7 @@ themePicker.onblur = handleThemeButtonsBlur;
955976
956977 // Update the search index
957978 let dst = cx. dst . join ( "search-index.js" ) ;
958- let mut all_indexes = try_err ! ( collect( & dst, & krate. name, "searchIndex" ) , & dst) ;
979+ let ( mut all_indexes, mut krates ) = try_err ! ( collect( & dst, & krate. name, "searchIndex" ) , & dst) ;
959980 all_indexes. push ( search_index) ;
960981 // Sort the indexes by crate so the file will be generated identically even
961982 // with rustdoc running in parallel.
@@ -969,6 +990,46 @@ themePicker.onblur = handleThemeButtonsBlur;
969990 }
970991 try_err ! ( writeln!( & mut w, "initSearch(searchIndex);" ) , & dst) ;
971992
993+ if cx. enable_index_page == true {
994+ if let Some ( ref index_page) = cx. index_page {
995+ :: markdown:: render ( index_page,
996+ cx. dst . clone ( ) ,
997+ & matches, & ( * cx. shared ) . layout . external_html ,
998+ !matches. opt_present ( "markdown-no-toc" ) ,
999+ diag) ;
1000+ } else {
1001+ let dst = cx. dst . join ( "index.html" ) ;
1002+ let mut w = BufWriter :: new ( try_err ! ( File :: create( & dst) , & dst) ) ;
1003+ let page = layout:: Page {
1004+ title : "Index of crates" ,
1005+ css_class : "mod" ,
1006+ root_path : "./" ,
1007+ description : "List of crates" ,
1008+ keywords : BASIC_KEYWORDS ,
1009+ resource_suffix : & cx. shared . resource_suffix ,
1010+ } ;
1011+ krates. push ( krate. name . clone ( ) ) ;
1012+ krates. sort ( ) ;
1013+ krates. dedup ( ) ;
1014+
1015+ let content = format ! (
1016+ "<h1 class='fqn'>\
1017+ <span class='in-band'>List of all crates</span>\
1018+ </h1><ul class='mod'>{}</ul>",
1019+ krates
1020+ . iter( )
1021+ . map( |s| {
1022+ format!( "<li><a href=\" {}/index.html\" >{}</li>" , s, s)
1023+ } )
1024+ . collect:: <String >( ) ) ;
1025+ try_err ! ( layout:: render( & mut w, & cx. shared. layout,
1026+ & page, & ( "" ) , & content,
1027+ cx. shared. css_file_extension. is_some( ) ,
1028+ & cx. shared. themes) , & dst) ;
1029+ try_err ! ( w. flush( ) , & dst) ;
1030+ }
1031+ }
1032+
9721033 // Update the list of all implementors for traits
9731034 let dst = cx. dst . join ( "implementors" ) ;
9741035 for ( & did, imps) in & cache. implementors {
@@ -1022,7 +1083,8 @@ themePicker.onblur = handleThemeButtonsBlur;
10221083 remote_item_type. css_class( ) ,
10231084 remote_path[ remote_path. len( ) - 1 ] ) ) ;
10241085
1025- let mut all_implementors = try_err ! ( collect( & mydst, & krate. name, "implementors" ) , & mydst) ;
1086+ let ( mut all_implementors, _) = try_err ! ( collect( & mydst, & krate. name, "implementors" ) ,
1087+ & mydst) ;
10261088 all_implementors. push ( implementors) ;
10271089 // Sort the implementors by crate so the file will be generated
10281090 // identically even with rustdoc running in parallel.
0 commit comments