diff options
| author | Ian Jackson <ijackson@chiark.greenend.org.uk> | 2020-10-13 18:52:43 +0100 |
|---|---|---|
| committer | Ian Jackson <ijackson@chiark.greenend.org.uk> | 2020-10-28 17:54:07 +0000 |
| commit | d8a449756172f7be072b87a545bacf91e10d1bb9 (patch) | |
| tree | d801717af0cd7fbdc1c8eb87d48eed28f1114851 | |
| parent | 5cd96d638c37dc7f92cb8b2fc84a3f7bfe7b7960 (diff) | |
| download | rust-d8a449756172f7be072b87a545bacf91e10d1bb9.tar.gz rust-d8a449756172f7be072b87a545bacf91e10d1bb9.zip | |
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 <ijackson@chiark.greenend.org.uk>
| -rw-r--r-- | src/librustdoc/config.rs | 16 | ||||
| -rw-r--r-- | src/librustdoc/html/layout.rs | 2 | ||||
| -rw-r--r-- | 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 baa0a934126..45106c5dbf6 100644 --- a/src/librustdoc/config.rs +++ b/src/librustdoc/config.rs @@ -377,6 +377,20 @@ impl Options { } }; + let mut default_settings: Vec<Vec<(String, String)>> = 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<String> = 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 54891133662..29e44922c76 100644 --- a/src/librustdoc/html/layout.rs +++ b/src/librustdoc/html/layout.rs @@ -178,7 +178,7 @@ pub fn render<T: Print, S: Print>( 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::<String>(), style_files = style_files .iter() diff --git a/src/librustdoc/lib.rs b/src/librustdoc/lib.rs index 616f0efcd75..90c77488ee9 100644 --- a/src/librustdoc/lib.rs +++ b/src/librustdoc/lib.rs @@ -269,6 +269,16 @@ fn opts() -> Vec<RustcOptGroup> { "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( "", |
