From d8a449756172f7be072b87a545bacf91e10d1bb9 Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Tue, 13 Oct 2020 18:52:43 +0100 Subject: [PATCH] rustdoc: Provide a general --default-setting SETTING[=VALUE] option We just plumb through what the user tells us. This is flagged as unstable, mostly because I don't understand the compatibility rules that rustdoc obeys for local storage data, and how error handling of invalid data works. We collect() the needed HashMap from Vec of Vecs of (key, value) pairs, so that there is a nice place to add new more-specific options. It would have been possible to use Extend::extend but doing it this way ensures that all the used inputs are (and will stay) right next to each other. Signed-off-by: Ian Jackson --- src/librustdoc/config.rs | 16 +++++++++++++++- src/librustdoc/html/layout.rs | 2 +- src/librustdoc/lib.rs | 10 ++++++++++ 3 files changed, 26 insertions(+), 2 deletions(-) diff --git a/src/librustdoc/config.rs b/src/librustdoc/config.rs index baa0a9341267..45106c5dbf6a 100644 --- a/src/librustdoc/config.rs +++ b/src/librustdoc/config.rs @@ -377,6 +377,20 @@ impl Options { } }; + let mut default_settings: Vec> = vec![ + matches + .opt_strs("default-setting") + .iter() + .map(|s| { + let mut kv = s.splitn(2, '='); + let k = kv.next().unwrap().to_string(); + let v = kv.next().unwrap_or("true").to_string(); + (k, v) + }) + .collect(), + ]; + let default_settings = default_settings.drain(..).flatten().collect(); + let test_args = matches.opt_strs("test-args"); let test_args: Vec = test_args.iter().flat_map(|s| s.split_whitespace()).map(|s| s.to_string()).collect(); @@ -599,7 +613,7 @@ impl Options { themes, extension_css, extern_html_root_urls, - default_settings: Default::default(), + default_settings, resource_suffix, enable_minification, enable_index_page, diff --git a/src/librustdoc/html/layout.rs b/src/librustdoc/html/layout.rs index 548911336625..29e44922c76a 100644 --- a/src/librustdoc/html/layout.rs +++ b/src/librustdoc/html/layout.rs @@ -178,7 +178,7 @@ pub fn render( default_settings = layout .default_settings .iter() - .map(|(k, v)| format!(r#" data-{}="{}""#, k.replace('-',"_"), Escape(v),)) + .map(|(k, v)| format!(r#" data-{}="{}""#, k.replace('-', "_"), Escape(v),)) .collect::(), style_files = style_files .iter() diff --git a/src/librustdoc/lib.rs b/src/librustdoc/lib.rs index 616f0efcd756..90c77488ee94 100644 --- a/src/librustdoc/lib.rs +++ b/src/librustdoc/lib.rs @@ -269,6 +269,16 @@ fn opts() -> Vec { "sort modules by where they appear in the program, rather than alphabetically", ) }), + unstable("default-setting", |o| { + o.optmulti( + "", + "default-setting", + "Default value for a rustdoc setting (used when \"rustdoc-SETTING\" is absent \ + from web browser Local Storage). If VALUE is not supplied, \"true\" is used. \ + Supported SETTINGs and VALUEs are not documented and not stable.", + "SETTING[=VALUE]", + ) + }), stable("theme", |o| { o.optmulti( "",