@@ -52,11 +52,7 @@ use std::str;
5252use std:: sync:: Arc ;
5353use std:: rc:: Rc ;
5454
55- use externalfiles:: ExternalHtml ;
56-
5755use errors;
58- use getopts;
59-
6056use serialize:: json:: { ToJson , Json , as_json} ;
6157use syntax:: ast;
6258use syntax:: ext:: base:: MacroKind ;
@@ -70,6 +66,7 @@ use rustc::util::nodemap::{FxHashMap, FxHashSet};
7066use rustc_data_structures:: flock;
7167
7268use clean:: { self , AttributesExt , GetDefId , SelfTy , Mutability } ;
69+ use config:: RenderOptions ;
7370use doctree;
7471use fold:: DocFolder ;
7572use html:: escape:: Escape ;
@@ -109,8 +106,6 @@ struct Context {
109106 /// The map used to ensure all generated 'id=' attributes are unique.
110107 id_map : Rc < RefCell < IdMap > > ,
111108 pub shared : Arc < SharedContext > ,
112- pub enable_index_page : bool ,
113- pub index_page : Option < PathBuf > ,
114109}
115110
116111struct SharedContext {
@@ -495,23 +490,25 @@ pub fn initial_ids() -> Vec<String> {
495490
496491/// Generates the documentation for `crate` into the directory `dst`
497492pub fn run ( mut krate : clean:: Crate ,
498- extern_urls : BTreeMap < String , String > ,
499- external_html : & ExternalHtml ,
500- playground_url : Option < String > ,
501- dst : PathBuf ,
502- resource_suffix : String ,
493+ options : RenderOptions ,
503494 passes : FxHashSet < String > ,
504- css_file_extension : Option < PathBuf > ,
505495 renderinfo : RenderInfo ,
506- sort_modules_alphabetically : bool ,
507- themes : Vec < PathBuf > ,
508- enable_minification : bool ,
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 > {
496+ diag : & errors:: Handler ) -> Result < ( ) , Error > {
497+ // need to save a copy of the options for rendering the index page
498+ let md_opts = options. clone ( ) ;
499+ let RenderOptions {
500+ output,
501+ external_html,
502+ id_map,
503+ playground_url,
504+ sort_modules_alphabetically,
505+ themes,
506+ extension_css,
507+ extern_html_root_urls,
508+ resource_suffix,
509+ ..
510+ } = options;
511+
515512 let src_root = match krate. src {
516513 FileName :: Real ( ref p) => match p. parent ( ) {
517514 Some ( p) => p. to_path_buf ( ) ,
@@ -528,10 +525,10 @@ pub fn run(mut krate: clean::Crate,
528525 layout : layout:: Layout {
529526 logo : String :: new ( ) ,
530527 favicon : String :: new ( ) ,
531- external_html : external_html . clone ( ) ,
528+ external_html,
532529 krate : krate. name . clone ( ) ,
533530 } ,
534- css_file_extension,
531+ css_file_extension : extension_css ,
535532 created_dirs : Default :: default ( ) ,
536533 sort_modules_alphabetically,
537534 themes,
@@ -573,6 +570,7 @@ pub fn run(mut krate: clean::Crate,
573570 }
574571 }
575572 }
573+ let dst = output;
576574 try_err ! ( fs:: create_dir_all( & dst) , & dst) ;
577575 krate = render_sources ( & dst, & mut scx, krate) ?;
578576 let cx = Context {
@@ -582,8 +580,6 @@ pub fn run(mut krate: clean::Crate,
582580 codes : ErrorCodes :: from ( UnstableFeatures :: from_environment ( ) . is_nightly_build ( ) ) ,
583581 id_map : Rc :: new ( RefCell :: new ( id_map) ) ,
584582 shared : Arc :: new ( scx) ,
585- enable_index_page,
586- index_page,
587583 } ;
588584
589585 // Crawl the crate to build various caches used for the output
@@ -637,7 +633,7 @@ pub fn run(mut krate: clean::Crate,
637633 } ,
638634 _ => PathBuf :: new ( ) ,
639635 } ;
640- let extern_url = extern_urls . get ( & e. name ) . map ( |u| & * * u) ;
636+ let extern_url = extern_html_root_urls . get ( & e. name ) . map ( |u| & * * u) ;
641637 cache. extern_locations . insert ( n, ( e. name . clone ( ) , src_root,
642638 extern_location ( e, extern_url, & cx. dst ) ) ) ;
643639
@@ -678,7 +674,7 @@ pub fn run(mut krate: clean::Crate,
678674 CACHE_KEY . with ( |v| * v. borrow_mut ( ) = cache. clone ( ) ) ;
679675 CURRENT_LOCATION_KEY . with ( |s| s. borrow_mut ( ) . clear ( ) ) ;
680676
681- write_shared ( & cx, & krate, & * cache, index, enable_minification , matches , diag) ?;
677+ write_shared ( & cx, & krate, & * cache, index, & md_opts , diag) ?;
682678
683679 // And finally render the whole crate's documentation
684680 cx. krate ( krate)
@@ -759,8 +755,7 @@ fn write_shared(
759755 krate : & clean:: Crate ,
760756 cache : & Cache ,
761757 search_index : String ,
762- enable_minification : bool ,
763- matches : & getopts:: Matches ,
758+ options : & RenderOptions ,
764759 diag : & errors:: Handler ,
765760) -> Result < ( ) , Error > {
766761 // Write out the shared files. Note that these are shared among all rustdoc
@@ -773,10 +768,10 @@ fn write_shared(
773768
774769 write_minify ( cx. dst . join ( & format ! ( "rustdoc{}.css" , cx. shared. resource_suffix) ) ,
775770 include_str ! ( "static/rustdoc.css" ) ,
776- enable_minification) ?;
771+ options . enable_minification ) ?;
777772 write_minify ( cx. dst . join ( & format ! ( "settings{}.css" , cx. shared. resource_suffix) ) ,
778773 include_str ! ( "static/settings.css" ) ,
779- enable_minification) ?;
774+ options . enable_minification ) ?;
780775
781776 // To avoid "light.css" to be overwritten, we'll first run over the received themes and only
782777 // then we'll run over the "official" styles.
@@ -800,11 +795,11 @@ fn write_shared(
800795 include_bytes ! ( "static/wheel.svg" ) ) ?;
801796 write_minify ( cx. dst . join ( & format ! ( "light{}.css" , cx. shared. resource_suffix) ) ,
802797 include_str ! ( "static/themes/light.css" ) ,
803- enable_minification) ?;
798+ options . enable_minification ) ?;
804799 themes. insert ( "light" . to_owned ( ) ) ;
805800 write_minify ( cx. dst . join ( & format ! ( "dark{}.css" , cx. shared. resource_suffix) ) ,
806801 include_str ! ( "static/themes/dark.css" ) ,
807- enable_minification) ?;
802+ options . enable_minification ) ?;
808803 themes. insert ( "dark" . to_owned ( ) ) ;
809804
810805 let mut themes: Vec < & String > = themes. iter ( ) . collect ( ) ;
@@ -860,35 +855,35 @@ themePicker.onblur = handleThemeButtonsBlur;
860855
861856 write_minify ( cx. dst . join ( & format ! ( "main{}.js" , cx. shared. resource_suffix) ) ,
862857 include_str ! ( "static/main.js" ) ,
863- enable_minification) ?;
858+ options . enable_minification ) ?;
864859 write_minify ( cx. dst . join ( & format ! ( "settings{}.js" , cx. shared. resource_suffix) ) ,
865860 include_str ! ( "static/settings.js" ) ,
866- enable_minification) ?;
861+ options . enable_minification ) ?;
867862
868863 {
869864 let mut data = format ! ( "var resourcesSuffix = \" {}\" ;\n " ,
870865 cx. shared. resource_suffix) ;
871866 data. push_str ( include_str ! ( "static/storage.js" ) ) ;
872867 write_minify ( cx. dst . join ( & format ! ( "storage{}.js" , cx. shared. resource_suffix) ) ,
873868 & data,
874- enable_minification) ?;
869+ options . enable_minification ) ?;
875870 }
876871
877872 if let Some ( ref css) = cx. shared . css_file_extension {
878873 let out = cx. dst . join ( & format ! ( "theme{}.css" , cx. shared. resource_suffix) ) ;
879- if !enable_minification {
874+ if !options . enable_minification {
880875 try_err ! ( fs:: copy( css, out) , css) ;
881876 } else {
882877 let mut f = try_err ! ( File :: open( css) , css) ;
883878 let mut buffer = String :: with_capacity ( 1000 ) ;
884879
885880 try_err ! ( f. read_to_string( & mut buffer) , css) ;
886- write_minify ( out, & buffer, enable_minification) ?;
881+ write_minify ( out, & buffer, options . enable_minification ) ?;
887882 }
888883 }
889884 write_minify ( cx. dst . join ( & format ! ( "normalize{}.css" , cx. shared. resource_suffix) ) ,
890885 include_str ! ( "static/normalize.css" ) ,
891- enable_minification) ?;
886+ options . enable_minification ) ?;
892887 write ( cx. dst . join ( "FiraSans-Regular.woff" ) ,
893888 include_bytes ! ( "static/FiraSans-Regular.woff" ) ) ?;
894889 write ( cx. dst . join ( "FiraSans-Medium.woff" ) ,
@@ -984,19 +979,19 @@ themePicker.onblur = handleThemeButtonsBlur;
984979 let mut w = try_err ! ( File :: create( & dst) , & dst) ;
985980 try_err ! ( writeln!( & mut w, "var N = null;var searchIndex = {{}};" ) , & dst) ;
986981 for index in & all_indexes {
987- try_err ! ( write_minify_replacer( & mut w, & * index, enable_minification,
982+ try_err ! ( write_minify_replacer( & mut w, & * index, options . enable_minification,
988983 & [ ( minifier:: js:: Keyword :: Null , "N" ) ] ) ,
989984 & dst) ;
990985 }
991986 try_err ! ( writeln!( & mut w, "initSearch(searchIndex);" ) , & dst) ;
992987
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) ;
988+ if options . enable_index_page {
989+ if let Some ( index_page) = options . index_page . clone ( ) {
990+ let mut md_opts = options . clone ( ) ;
991+ md_opts . output = cx. dst . clone ( ) ;
992+ md_opts . external_html = ( * cx. shared ) . layout . external_html . clone ( ) ;
993+
994+ :: markdown :: render ( index_page , md_opts , diag) ;
1000995 } else {
1001996 let dst = cx. dst . join ( "index.html" ) ;
1002997 let mut w = BufWriter :: new ( try_err ! ( File :: create( & dst) , & dst) ) ;
0 commit comments