@@ -742,6 +742,8 @@ fn write_shared(cx: &Context,
742
742
743
743
write ( cx. dst . join ( & format ! ( "rustdoc{}.css" , cx. shared. resource_suffix) ) ,
744
744
include_bytes ! ( "static/rustdoc.css" ) ) ?;
745
+ write ( cx. dst . join ( & format ! ( "settings{}.css" , cx. shared. resource_suffix) ) ,
746
+ include_bytes ! ( "static/settings.css" ) ) ?;
745
747
746
748
// To avoid "light.css" to be overwritten, we'll first run over the received themes and only
747
749
// then we'll run over the "official" styles.
@@ -761,6 +763,8 @@ fn write_shared(cx: &Context,
761
763
762
764
write ( cx. dst . join ( & format ! ( "brush{}.svg" , cx. shared. resource_suffix) ) ,
763
765
include_bytes ! ( "static/brush.svg" ) ) ?;
766
+ write ( cx. dst . join ( & format ! ( "wheel{}.svg" , cx. shared. resource_suffix) ) ,
767
+ include_bytes ! ( "static/wheel.svg" ) ) ?;
764
768
write ( cx. dst . join ( & format ! ( "light{}.css" , cx. shared. resource_suffix) ) ,
765
769
include_bytes ! ( "static/themes/light.css" ) ) ?;
766
770
themes. insert ( "light" . to_owned ( ) ) ;
@@ -794,8 +798,7 @@ themePicker.onclick = function() {{
794
798
switchTheme(currentTheme, mainTheme, item);
795
799
}};
796
800
themes.appendChild(but);
797
- }});
798
- "# ,
801
+ }});"# ,
799
802
themes. iter( )
800
803
. map( |s| format!( "\" {}\" " , s) )
801
804
. collect:: <Vec <String >>( )
@@ -804,6 +807,8 @@ themePicker.onclick = function() {{
804
807
805
808
write ( cx. dst . join ( & format ! ( "main{}.js" , cx. shared. resource_suffix) ) ,
806
809
include_bytes ! ( "static/main.js" ) ) ?;
810
+ write ( cx. dst . join ( & format ! ( "settings{}.js" , cx. shared. resource_suffix) ) ,
811
+ include_bytes ! ( "static/settings.js" ) ) ?;
807
812
808
813
{
809
814
let mut data = format ! ( "var resourcesSuffix = \" {}\" ;\n " ,
@@ -1503,6 +1508,51 @@ impl fmt::Display for AllTypes {
1503
1508
}
1504
1509
}
1505
1510
1511
+ #[ derive( Debug ) ]
1512
+ struct Settings < ' a > {
1513
+ // (id, explanation, default value)
1514
+ settings : Vec < ( & ' static str , & ' static str , bool ) > ,
1515
+ root_path : & ' a str ,
1516
+ suffix : & ' a str ,
1517
+ }
1518
+
1519
+ impl < ' a > Settings < ' a > {
1520
+ pub fn new ( root_path : & ' a str , suffix : & ' a str ) -> Settings < ' a > {
1521
+ Settings {
1522
+ settings : vec ! [
1523
+ ( "item-declarations" , "Auto-hide item declarations." , true ) ,
1524
+ ( "item-attributes" , "Auto-hide item attributes." , true ) ,
1525
+ ] ,
1526
+ root_path,
1527
+ suffix,
1528
+ }
1529
+ }
1530
+ }
1531
+
1532
+ impl < ' a > fmt:: Display for Settings < ' a > {
1533
+ fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
1534
+ write ! ( f,
1535
+ "<h1 class='fqn'>\
1536
+ <span class='in-band'>Rustdoc settings</span>\
1537
+ </h1>\
1538
+ <div class='settings'>{}</div>\
1539
+ <script src='{}settings{}.js'></script>",
1540
+ self . settings. iter( )
1541
+ . map( |( id, text, enabled) | {
1542
+ format!( "<div class='setting-line'>\
1543
+ <label class='toggle'>\
1544
+ <input type='checkbox' id='{}' {}>\
1545
+ <span class='slider'></span>\
1546
+ </label>\
1547
+ <div>{}</div>\
1548
+ </div>", id, if * enabled { " checked" } else { "" } , text)
1549
+ } )
1550
+ . collect:: <String >( ) ,
1551
+ self . root_path,
1552
+ self . suffix)
1553
+ }
1554
+ }
1555
+
1506
1556
impl Context {
1507
1557
/// String representation of how to get back to the root path of the 'doc/'
1508
1558
/// folder in terms of a relative URL.
@@ -1546,6 +1596,8 @@ impl Context {
1546
1596
} ;
1547
1597
let final_file = self . dst . join ( & krate. name )
1548
1598
. join ( "all.html" ) ;
1599
+ let settings_file = self . dst . join ( "settings.html" ) ;
1600
+
1549
1601
let crate_name = krate. name . clone ( ) ;
1550
1602
item. name = Some ( krate. name ) ;
1551
1603
@@ -1567,7 +1619,7 @@ impl Context {
1567
1619
if !root_path. ends_with ( '/' ) {
1568
1620
root_path. push ( '/' ) ;
1569
1621
}
1570
- let page = layout:: Page {
1622
+ let mut page = layout:: Page {
1571
1623
title : "List of all items in this crate" ,
1572
1624
css_class : "mod" ,
1573
1625
root_path : "../" ,
@@ -1590,6 +1642,25 @@ impl Context {
1590
1642
self . shared. css_file_extension. is_some( ) ,
1591
1643
& self . shared. themes) ,
1592
1644
& final_file) ;
1645
+
1646
+ // If the file already exists, no need to generate it again...
1647
+ if !settings_file. is_file ( ) {
1648
+ let settings = Settings :: new ( "./" , & self . shared . resource_suffix ) ;
1649
+ page. title = "Rustdoc settings" ;
1650
+ page. description = "Settings of Rustdoc" ;
1651
+ page. root_path = "./" ;
1652
+
1653
+ let mut w = BufWriter :: new ( try_err ! ( File :: create( & settings_file) , & settings_file) ) ;
1654
+ let mut themes = self . shared . themes . clone ( ) ;
1655
+ let sidebar = "<p class='location'>Settings</p><div class='sidebar-elems'>" . to_owned ( ) ;
1656
+ themes. push ( PathBuf :: from ( "settings.css" ) ) ;
1657
+ try_err ! ( layout:: render( & mut w, & self . shared. layout,
1658
+ & page, & sidebar, & settings,
1659
+ self . shared. css_file_extension. is_some( ) ,
1660
+ & themes) ,
1661
+ & settings_file) ;
1662
+ }
1663
+
1593
1664
Ok ( ( ) )
1594
1665
}
1595
1666
0 commit comments