@@ -750,6 +750,8 @@ fn write_shared(cx: &Context,
750
750
751
751
write ( cx. dst . join ( & format ! ( "rustdoc{}.css" , cx. shared. resource_suffix) ) ,
752
752
include_bytes ! ( "static/rustdoc.css" ) ) ?;
753
+ write ( cx. dst . join ( & format ! ( "settings{}.css" , cx. shared. resource_suffix) ) ,
754
+ include_bytes ! ( "static/settings.css" ) ) ?;
753
755
754
756
// To avoid "light.css" to be overwritten, we'll first run over the received themes and only
755
757
// then we'll run over the "official" styles.
@@ -769,6 +771,8 @@ fn write_shared(cx: &Context,
769
771
770
772
write ( cx. dst . join ( & format ! ( "brush{}.svg" , cx. shared. resource_suffix) ) ,
771
773
include_bytes ! ( "static/brush.svg" ) ) ?;
774
+ write ( cx. dst . join ( & format ! ( "wheel{}.svg" , cx. shared. resource_suffix) ) ,
775
+ include_bytes ! ( "static/wheel.svg" ) ) ?;
772
776
write ( cx. dst . join ( & format ! ( "light{}.css" , cx. shared. resource_suffix) ) ,
773
777
include_bytes ! ( "static/themes/light.css" ) ) ?;
774
778
themes. insert ( "light" . to_owned ( ) ) ;
@@ -802,8 +806,7 @@ themePicker.onclick = function() {{
802
806
switchTheme(currentTheme, mainTheme, item);
803
807
}};
804
808
themes.appendChild(but);
805
- }});
806
- "# ,
809
+ }});"# ,
807
810
themes. iter( )
808
811
. map( |s| format!( "\" {}\" " , s) )
809
812
. collect:: <Vec <String >>( )
@@ -812,6 +815,8 @@ themePicker.onclick = function() {{
812
815
813
816
write ( cx. dst . join ( & format ! ( "main{}.js" , cx. shared. resource_suffix) ) ,
814
817
include_bytes ! ( "static/main.js" ) ) ?;
818
+ write ( cx. dst . join ( & format ! ( "settings{}.js" , cx. shared. resource_suffix) ) ,
819
+ include_bytes ! ( "static/settings.js" ) ) ?;
815
820
816
821
{
817
822
let mut data = format ! ( "var resourcesSuffix = \" {}\" ;\n " ,
@@ -1575,6 +1580,51 @@ impl fmt::Display for AllTypes {
1575
1580
}
1576
1581
}
1577
1582
1583
+ #[ derive( Debug ) ]
1584
+ struct Settings < ' a > {
1585
+ // (id, explanation, default value)
1586
+ settings : Vec < ( & ' static str , & ' static str , bool ) > ,
1587
+ root_path : & ' a str ,
1588
+ suffix : & ' a str ,
1589
+ }
1590
+
1591
+ impl < ' a > Settings < ' a > {
1592
+ pub fn new ( root_path : & ' a str , suffix : & ' a str ) -> Settings < ' a > {
1593
+ Settings {
1594
+ settings : vec ! [
1595
+ ( "item-declarations" , "Auto-hide item declarations." , true ) ,
1596
+ ( "item-attributes" , "Auto-hide item attributes." , true ) ,
1597
+ ] ,
1598
+ root_path,
1599
+ suffix,
1600
+ }
1601
+ }
1602
+ }
1603
+
1604
+ impl < ' a > fmt:: Display for Settings < ' a > {
1605
+ fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
1606
+ write ! ( f,
1607
+ "<h1 class='fqn'>\
1608
+ <span class='in-band'>Rustdoc settings</span>\
1609
+ </h1>\
1610
+ <div class='settings'>{}</div>\
1611
+ <script src='{}settings{}.js'></script>",
1612
+ self . settings. iter( )
1613
+ . map( |( id, text, enabled) | {
1614
+ format!( "<div class='setting-line'>\
1615
+ <label class='toggle'>\
1616
+ <input type='checkbox' id='{}' {}>\
1617
+ <span class='slider'></span>\
1618
+ </label>\
1619
+ <div>{}</div>\
1620
+ </div>", id, if * enabled { " checked" } else { "" } , text)
1621
+ } )
1622
+ . collect:: <String >( ) ,
1623
+ self . root_path,
1624
+ self . suffix)
1625
+ }
1626
+ }
1627
+
1578
1628
impl Context {
1579
1629
/// String representation of how to get back to the root path of the 'doc/'
1580
1630
/// folder in terms of a relative URL.
@@ -1618,6 +1668,8 @@ impl Context {
1618
1668
} ;
1619
1669
let final_file = self . dst . join ( & krate. name )
1620
1670
. join ( "all.html" ) ;
1671
+ let settings_file = self . dst . join ( "settings.html" ) ;
1672
+
1621
1673
let crate_name = krate. name . clone ( ) ;
1622
1674
item. name = Some ( krate. name ) ;
1623
1675
@@ -1639,7 +1691,7 @@ impl Context {
1639
1691
if !root_path. ends_with ( '/' ) {
1640
1692
root_path. push ( '/' ) ;
1641
1693
}
1642
- let page = layout:: Page {
1694
+ let mut page = layout:: Page {
1643
1695
title : "List of all items in this crate" ,
1644
1696
css_class : "mod" ,
1645
1697
root_path : "../" ,
@@ -1662,6 +1714,27 @@ impl Context {
1662
1714
self . shared. css_file_extension. is_some( ) ,
1663
1715
& self . shared. themes) ,
1664
1716
& final_file) ;
1717
+
1718
+ // Generating settings page.
1719
+ let settings = Settings :: new ( "./" , & self . shared . resource_suffix ) ;
1720
+ page. title = "Rustdoc settings" ;
1721
+ page. description = "Settings of Rustdoc" ;
1722
+ page. root_path = "./" ;
1723
+
1724
+ let mut w = BufWriter :: new ( try_err ! ( File :: create( & settings_file) , & settings_file) ) ;
1725
+ let mut themes = self . shared . themes . clone ( ) ;
1726
+ let sidebar = "<p class='location'>Settings</p><div class='sidebar-elems'></div>" ;
1727
+ themes. push ( PathBuf :: from ( "settings.css" ) ) ;
1728
+ let mut layout = self . shared . layout . clone ( ) ;
1729
+ layout. krate = String :: new ( ) ;
1730
+ layout. logo = String :: new ( ) ;
1731
+ layout. favicon = String :: new ( ) ;
1732
+ try_err ! ( layout:: render( & mut w, & layout,
1733
+ & page, & sidebar, & settings,
1734
+ self . shared. css_file_extension. is_some( ) ,
1735
+ & themes) ,
1736
+ & settings_file) ;
1737
+
1665
1738
Ok ( ( ) )
1666
1739
}
1667
1740
0 commit comments