@@ -54,6 +54,9 @@ use std::rc::Rc;
54
54
55
55
use externalfiles:: ExternalHtml ;
56
56
57
+ use errors;
58
+ use getopts;
59
+
57
60
use serialize:: json:: { ToJson , Json , as_json} ;
58
61
use syntax:: ast;
59
62
use syntax:: ext:: base:: MacroKind ;
@@ -106,6 +109,8 @@ struct Context {
106
109
/// The map used to ensure all generated 'id=' attributes are unique.
107
110
id_map : Rc < RefCell < IdMap > > ,
108
111
pub shared : Arc < SharedContext > ,
112
+ pub enable_index_page : bool ,
113
+ pub index_page : Option < PathBuf > ,
109
114
}
110
115
111
116
struct SharedContext {
@@ -501,7 +506,12 @@ pub fn run(mut krate: clean::Crate,
501
506
sort_modules_alphabetically : bool ,
502
507
themes : Vec < PathBuf > ,
503
508
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 > {
505
515
let src_root = match krate. src {
506
516
FileName :: Real ( ref p) => match p. parent ( ) {
507
517
Some ( p) => p. to_path_buf ( ) ,
@@ -572,6 +582,8 @@ pub fn run(mut krate: clean::Crate,
572
582
codes : ErrorCodes :: from ( UnstableFeatures :: from_environment ( ) . is_nightly_build ( ) ) ,
573
583
id_map : Rc :: new ( RefCell :: new ( id_map) ) ,
574
584
shared : Arc :: new ( scx) ,
585
+ enable_index_page,
586
+ index_page,
575
587
} ;
576
588
577
589
// Crawl the crate to build various caches used for the output
@@ -666,7 +678,7 @@ pub fn run(mut krate: clean::Crate,
666
678
CACHE_KEY . with ( |v| * v. borrow_mut ( ) = cache. clone ( ) ) ;
667
679
CURRENT_LOCATION_KEY . with ( |s| s. borrow_mut ( ) . clear ( ) ) ;
668
680
669
- write_shared ( & cx, & krate, & * cache, index, enable_minification) ?;
681
+ write_shared ( & cx, & krate, & * cache, index, enable_minification, matches , diag ) ?;
670
682
671
683
// And finally render the whole crate's documentation
672
684
cx. krate ( krate)
@@ -742,11 +754,15 @@ fn build_index(krate: &clean::Crate, cache: &mut Cache) -> String {
742
754
Json :: Object ( crate_data) )
743
755
}
744
756
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 > {
750
766
// Write out the shared files. Note that these are shared among all rustdoc
751
767
// docs placed in the output directory, so this needs to be a synchronized
752
768
// operation with respect to all other rustdocs running around.
@@ -902,8 +918,9 @@ themePicker.onblur = handleThemeButtonsBlur;
902
918
write ( cx. dst . join ( "COPYRIGHT.txt" ) ,
903
919
include_bytes ! ( "static/COPYRIGHT.txt" ) ) ?;
904
920
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 > ) > {
906
922
let mut ret = Vec :: new ( ) ;
923
+ let mut krates = Vec :: new ( ) ;
907
924
if path. exists ( ) {
908
925
for line in BufReader :: new ( File :: open ( path) ?) . lines ( ) {
909
926
let line = line?;
@@ -914,9 +931,13 @@ themePicker.onblur = handleThemeButtonsBlur;
914
931
continue ;
915
932
}
916
933
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 ( ) ) ) ;
917
938
}
918
939
}
919
- Ok ( ret)
940
+ Ok ( ( ret, krates ) )
920
941
}
921
942
922
943
fn show_item ( item : & IndexItem , krate : & str ) -> String {
@@ -931,7 +952,7 @@ themePicker.onblur = handleThemeButtonsBlur;
931
952
932
953
let dst = cx. dst . join ( "aliases.js" ) ;
933
954
{
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) ;
935
956
let mut w = try_err ! ( File :: create( & dst) , & dst) ;
936
957
let mut output = String :: with_capacity ( 100 ) ;
937
958
for ( alias, items) in & cache. aliases {
@@ -955,7 +976,7 @@ themePicker.onblur = handleThemeButtonsBlur;
955
976
956
977
// Update the search index
957
978
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) ;
959
980
all_indexes. push ( search_index) ;
960
981
// Sort the indexes by crate so the file will be generated identically even
961
982
// with rustdoc running in parallel.
@@ -969,6 +990,46 @@ themePicker.onblur = handleThemeButtonsBlur;
969
990
}
970
991
try_err ! ( writeln!( & mut w, "initSearch(searchIndex);" ) , & dst) ;
971
992
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
+
972
1033
// Update the list of all implementors for traits
973
1034
let dst = cx. dst . join ( "implementors" ) ;
974
1035
for ( & did, imps) in & cache. implementors {
@@ -1022,7 +1083,8 @@ themePicker.onblur = handleThemeButtonsBlur;
1022
1083
remote_item_type. css_class( ) ,
1023
1084
remote_path[ remote_path. len( ) - 1 ] ) ) ;
1024
1085
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) ;
1026
1088
all_implementors. push ( implementors) ;
1027
1089
// Sort the implementors by crate so the file will be generated
1028
1090
// identically even with rustdoc running in parallel.
0 commit comments