@@ -1230,36 +1230,95 @@ impl AllTypes {
12301230 }
12311231}
12321232
1233+ #[ derive( Debug ) ]
1234+ enum Setting {
1235+ Section {
1236+ description : & ' static str ,
1237+ sub_settings : Vec < Setting > ,
1238+ } ,
1239+ Entry {
1240+ js_data_name : & ' static str ,
1241+ description : & ' static str ,
1242+ default_value : bool ,
1243+ }
1244+ }
1245+
1246+ impl Setting {
1247+ fn display ( & self ) -> String {
1248+ match * self {
1249+ Setting :: Section { ref description, ref sub_settings } => {
1250+ format ! (
1251+ "<div class='setting-line'>\
1252+ <div class='title'>{}</div>\
1253+ <div class='sub-setting'>{}</div>
1254+ </div>" ,
1255+ description,
1256+ sub_settings. iter( ) . map( |s| s. display( ) ) . collect:: <String >( )
1257+ )
1258+ }
1259+ Setting :: Entry { ref js_data_name, ref description, ref default_value } => {
1260+ format ! (
1261+ "<div class='setting-line'>\
1262+ <label class='toggle'>\
1263+ <input type='checkbox' id='{}' {}>\
1264+ <span class='slider'></span>\
1265+ </label>\
1266+ <div>{}</div>\
1267+ </div>",
1268+ js_data_name,
1269+ if * default_value { " checked" } else { "" } ,
1270+ description,
1271+ )
1272+ }
1273+ }
1274+ }
1275+ }
1276+
1277+ impl From < ( & ' static str , & ' static str , bool ) > for Setting {
1278+ fn from ( values : ( & ' static str , & ' static str , bool ) ) -> Setting {
1279+ Setting :: Entry {
1280+ js_data_name : values. 0 ,
1281+ description : values. 1 ,
1282+ default_value : values. 2 ,
1283+ }
1284+ }
1285+ }
1286+
1287+ impl < T : Into < Setting > > From < ( & ' static str , Vec < T > ) > for Setting {
1288+ fn from ( values : ( & ' static str , Vec < T > ) ) -> Setting {
1289+ Setting :: Section {
1290+ description : values. 0 ,
1291+ sub_settings : values. 1 . into_iter ( ) . map ( |v| v. into ( ) ) . collect :: < Vec < _ > > ( ) ,
1292+ }
1293+ }
1294+ }
1295+
12331296fn settings ( root_path : & str , suffix : & str ) -> String {
12341297 // (id, explanation, default value)
1235- let settings = [
1236- ( "item-declarations" , "Auto-hide item declarations." , true ) ,
1237- ( "item-attributes" , "Auto-hide item attributes." , true ) ,
1238- ( "trait-implementations" , "Auto-hide trait implementations documentation" ,
1239- true ) ,
1240- ( "method-docs" , "Auto-hide item methods' documentation" , false ) ,
1298+ let settings: & [ Setting ] = & [
1299+ ( "Auto-hide item declarations" , vec ! [
1300+ ( "auto-hide-struct" , "Auto-hide structs declaration" , true ) ,
1301+ ( "auto-hide-enum" , "Auto-hide enums declaration" , false ) ,
1302+ ( "auto-hide-union" , "Auto-hide unions declaration" , true ) ,
1303+ ( "auto-hide-trait" , "Auto-hide traits declaration" , true ) ,
1304+ ( "auto-hide-macro" , "Auto-hide macros declaration" , false ) ,
1305+ ] ) . into ( ) ,
1306+ ( "auto-hide-attributes" , "Auto-hide item attributes." , true ) . into ( ) ,
1307+ ( "auto-hide-method-docs" , "Auto-hide item methods' documentation" , false ) . into ( ) ,
1308+ ( "auto-hide-trait-implementations" , "Auto-hide trait implementations documentation" ,
1309+ true ) . into ( ) ,
12411310 ( "go-to-only-result" , "Directly go to item in search if there is only one result" ,
1242- false ) ,
1243- ( "line-numbers" , "Show line numbers on code examples" , false ) ,
1244- ( "disable-shortcuts" , "Disable keyboard shortcuts" , false ) ,
1311+ false ) . into ( ) ,
1312+ ( "line-numbers" , "Show line numbers on code examples" , false ) . into ( ) ,
1313+ ( "disable-shortcuts" , "Disable keyboard shortcuts" , false ) . into ( ) ,
12451314 ] ;
12461315 format ! (
12471316"<h1 class='fqn'>\
12481317 <span class='in-band'>Rustdoc settings</span>\
12491318 </h1>\
12501319 <div class='settings'>{}</div>\
12511320 <script src='{}settings{}.js'></script>",
1252- settings. iter( )
1253- . map( |( id, text, enabled) | {
1254- format!( "<div class='setting-line'>\
1255- <label class='toggle'>\
1256- <input type='checkbox' id='{}' {}>\
1257- <span class='slider'></span>\
1258- </label>\
1259- <div>{}</div>\
1260- </div>", id, if * enabled { " checked" } else { "" } , text)
1261- } )
1262- . collect:: <String >( ) ,
1321+ settings. iter( ) . map( |s| s. display( ) ) . collect:: <String >( ) ,
12631322 root_path,
12641323 suffix)
12651324}
0 commit comments