@@ -52,11 +52,7 @@ use std::str;
52
52
use std:: sync:: Arc ;
53
53
use std:: rc:: Rc ;
54
54
55
- use externalfiles:: ExternalHtml ;
56
-
57
55
use errors;
58
- use getopts;
59
-
60
56
use serialize:: json:: { ToJson , Json , as_json} ;
61
57
use syntax:: ast;
62
58
use syntax:: ext:: base:: MacroKind ;
@@ -70,6 +66,7 @@ use rustc::util::nodemap::{FxHashMap, FxHashSet};
70
66
use rustc_data_structures:: flock;
71
67
72
68
use clean:: { self , AttributesExt , GetDefId , SelfTy , Mutability } ;
69
+ use config:: RenderOptions ;
73
70
use doctree;
74
71
use fold:: DocFolder ;
75
72
use html:: escape:: Escape ;
@@ -109,8 +106,6 @@ struct Context {
109
106
/// The map used to ensure all generated 'id=' attributes are unique.
110
107
id_map : Rc < RefCell < IdMap > > ,
111
108
pub shared : Arc < SharedContext > ,
112
- pub enable_index_page : bool ,
113
- pub index_page : Option < PathBuf > ,
114
109
}
115
110
116
111
struct SharedContext {
@@ -495,23 +490,25 @@ pub fn initial_ids() -> Vec<String> {
495
490
496
491
/// Generates the documentation for `crate` into the directory `dst`
497
492
pub 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 ,
503
494
passes : FxHashSet < String > ,
504
- css_file_extension : Option < PathBuf > ,
505
495
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
+
515
512
let src_root = match krate. src {
516
513
FileName :: Real ( ref p) => match p. parent ( ) {
517
514
Some ( p) => p. to_path_buf ( ) ,
@@ -528,10 +525,10 @@ pub fn run(mut krate: clean::Crate,
528
525
layout : layout:: Layout {
529
526
logo : String :: new ( ) ,
530
527
favicon : String :: new ( ) ,
531
- external_html : external_html . clone ( ) ,
528
+ external_html,
532
529
krate : krate. name . clone ( ) ,
533
530
} ,
534
- css_file_extension,
531
+ css_file_extension : extension_css ,
535
532
created_dirs : Default :: default ( ) ,
536
533
sort_modules_alphabetically,
537
534
themes,
@@ -573,6 +570,7 @@ pub fn run(mut krate: clean::Crate,
573
570
}
574
571
}
575
572
}
573
+ let dst = output;
576
574
try_err ! ( fs:: create_dir_all( & dst) , & dst) ;
577
575
krate = render_sources ( & dst, & mut scx, krate) ?;
578
576
let cx = Context {
@@ -582,8 +580,6 @@ pub fn run(mut krate: clean::Crate,
582
580
codes : ErrorCodes :: from ( UnstableFeatures :: from_environment ( ) . is_nightly_build ( ) ) ,
583
581
id_map : Rc :: new ( RefCell :: new ( id_map) ) ,
584
582
shared : Arc :: new ( scx) ,
585
- enable_index_page,
586
- index_page,
587
583
} ;
588
584
589
585
// Crawl the crate to build various caches used for the output
@@ -637,7 +633,7 @@ pub fn run(mut krate: clean::Crate,
637
633
} ,
638
634
_ => PathBuf :: new ( ) ,
639
635
} ;
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) ;
641
637
cache. extern_locations . insert ( n, ( e. name . clone ( ) , src_root,
642
638
extern_location ( e, extern_url, & cx. dst ) ) ) ;
643
639
@@ -678,7 +674,7 @@ pub fn run(mut krate: clean::Crate,
678
674
CACHE_KEY . with ( |v| * v. borrow_mut ( ) = cache. clone ( ) ) ;
679
675
CURRENT_LOCATION_KEY . with ( |s| s. borrow_mut ( ) . clear ( ) ) ;
680
676
681
- write_shared ( & cx, & krate, & * cache, index, enable_minification , matches , diag) ?;
677
+ write_shared ( & cx, & krate, & * cache, index, & md_opts , diag) ?;
682
678
683
679
// And finally render the whole crate's documentation
684
680
cx. krate ( krate)
@@ -759,8 +755,7 @@ fn write_shared(
759
755
krate : & clean:: Crate ,
760
756
cache : & Cache ,
761
757
search_index : String ,
762
- enable_minification : bool ,
763
- matches : & getopts:: Matches ,
758
+ options : & RenderOptions ,
764
759
diag : & errors:: Handler ,
765
760
) -> Result < ( ) , Error > {
766
761
// Write out the shared files. Note that these are shared among all rustdoc
@@ -773,10 +768,10 @@ fn write_shared(
773
768
774
769
write_minify ( cx. dst . join ( & format ! ( "rustdoc{}.css" , cx. shared. resource_suffix) ) ,
775
770
include_str ! ( "static/rustdoc.css" ) ,
776
- enable_minification) ?;
771
+ options . enable_minification ) ?;
777
772
write_minify ( cx. dst . join ( & format ! ( "settings{}.css" , cx. shared. resource_suffix) ) ,
778
773
include_str ! ( "static/settings.css" ) ,
779
- enable_minification) ?;
774
+ options . enable_minification ) ?;
780
775
781
776
// To avoid "light.css" to be overwritten, we'll first run over the received themes and only
782
777
// then we'll run over the "official" styles.
@@ -800,11 +795,11 @@ fn write_shared(
800
795
include_bytes ! ( "static/wheel.svg" ) ) ?;
801
796
write_minify ( cx. dst . join ( & format ! ( "light{}.css" , cx. shared. resource_suffix) ) ,
802
797
include_str ! ( "static/themes/light.css" ) ,
803
- enable_minification) ?;
798
+ options . enable_minification ) ?;
804
799
themes. insert ( "light" . to_owned ( ) ) ;
805
800
write_minify ( cx. dst . join ( & format ! ( "dark{}.css" , cx. shared. resource_suffix) ) ,
806
801
include_str ! ( "static/themes/dark.css" ) ,
807
- enable_minification) ?;
802
+ options . enable_minification ) ?;
808
803
themes. insert ( "dark" . to_owned ( ) ) ;
809
804
810
805
let mut themes: Vec < & String > = themes. iter ( ) . collect ( ) ;
@@ -860,35 +855,35 @@ themePicker.onblur = handleThemeButtonsBlur;
860
855
861
856
write_minify ( cx. dst . join ( & format ! ( "main{}.js" , cx. shared. resource_suffix) ) ,
862
857
include_str ! ( "static/main.js" ) ,
863
- enable_minification) ?;
858
+ options . enable_minification ) ?;
864
859
write_minify ( cx. dst . join ( & format ! ( "settings{}.js" , cx. shared. resource_suffix) ) ,
865
860
include_str ! ( "static/settings.js" ) ,
866
- enable_minification) ?;
861
+ options . enable_minification ) ?;
867
862
868
863
{
869
864
let mut data = format ! ( "var resourcesSuffix = \" {}\" ;\n " ,
870
865
cx. shared. resource_suffix) ;
871
866
data. push_str ( include_str ! ( "static/storage.js" ) ) ;
872
867
write_minify ( cx. dst . join ( & format ! ( "storage{}.js" , cx. shared. resource_suffix) ) ,
873
868
& data,
874
- enable_minification) ?;
869
+ options . enable_minification ) ?;
875
870
}
876
871
877
872
if let Some ( ref css) = cx. shared . css_file_extension {
878
873
let out = cx. dst . join ( & format ! ( "theme{}.css" , cx. shared. resource_suffix) ) ;
879
- if !enable_minification {
874
+ if !options . enable_minification {
880
875
try_err ! ( fs:: copy( css, out) , css) ;
881
876
} else {
882
877
let mut f = try_err ! ( File :: open( css) , css) ;
883
878
let mut buffer = String :: with_capacity ( 1000 ) ;
884
879
885
880
try_err ! ( f. read_to_string( & mut buffer) , css) ;
886
- write_minify ( out, & buffer, enable_minification) ?;
881
+ write_minify ( out, & buffer, options . enable_minification ) ?;
887
882
}
888
883
}
889
884
write_minify ( cx. dst . join ( & format ! ( "normalize{}.css" , cx. shared. resource_suffix) ) ,
890
885
include_str ! ( "static/normalize.css" ) ,
891
- enable_minification) ?;
886
+ options . enable_minification ) ?;
892
887
write ( cx. dst . join ( "FiraSans-Regular.woff" ) ,
893
888
include_bytes ! ( "static/FiraSans-Regular.woff" ) ) ?;
894
889
write ( cx. dst . join ( "FiraSans-Medium.woff" ) ,
@@ -984,19 +979,19 @@ themePicker.onblur = handleThemeButtonsBlur;
984
979
let mut w = try_err ! ( File :: create( & dst) , & dst) ;
985
980
try_err ! ( writeln!( & mut w, "var N = null;var searchIndex = {{}};" ) , & dst) ;
986
981
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,
988
983
& [ ( minifier:: js:: Keyword :: Null , "N" ) ] ) ,
989
984
& dst) ;
990
985
}
991
986
try_err ! ( writeln!( & mut w, "initSearch(searchIndex);" ) , & dst) ;
992
987
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) ;
1000
995
} else {
1001
996
let dst = cx. dst . join ( "index.html" ) ;
1002
997
let mut w = BufWriter :: new ( try_err ! ( File :: create( & dst) , & dst) ) ;
0 commit comments