Skip to content

Commit d8a4497

Browse files
committed
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 <[email protected]>
1 parent 5cd96d6 commit d8a4497

File tree

3 files changed

+26
-2
lines changed

3 files changed

+26
-2
lines changed

src/librustdoc/config.rs

+15-1
Original file line numberDiff line numberDiff line change
@@ -377,6 +377,20 @@ impl Options {
377377
}
378378
};
379379

380+
let mut default_settings: Vec<Vec<(String, String)>> = vec![
381+
matches
382+
.opt_strs("default-setting")
383+
.iter()
384+
.map(|s| {
385+
let mut kv = s.splitn(2, '=');
386+
let k = kv.next().unwrap().to_string();
387+
let v = kv.next().unwrap_or("true").to_string();
388+
(k, v)
389+
})
390+
.collect(),
391+
];
392+
let default_settings = default_settings.drain(..).flatten().collect();
393+
380394
let test_args = matches.opt_strs("test-args");
381395
let test_args: Vec<String> =
382396
test_args.iter().flat_map(|s| s.split_whitespace()).map(|s| s.to_string()).collect();
@@ -599,7 +613,7 @@ impl Options {
599613
themes,
600614
extension_css,
601615
extern_html_root_urls,
602-
default_settings: Default::default(),
616+
default_settings,
603617
resource_suffix,
604618
enable_minification,
605619
enable_index_page,

src/librustdoc/html/layout.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ pub fn render<T: Print, S: Print>(
178178
default_settings = layout
179179
.default_settings
180180
.iter()
181-
.map(|(k, v)| format!(r#" data-{}="{}""#, k.replace('-',"_"), Escape(v),))
181+
.map(|(k, v)| format!(r#" data-{}="{}""#, k.replace('-', "_"), Escape(v),))
182182
.collect::<String>(),
183183
style_files = style_files
184184
.iter()

src/librustdoc/lib.rs

+10
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,16 @@ fn opts() -> Vec<RustcOptGroup> {
269269
"sort modules by where they appear in the program, rather than alphabetically",
270270
)
271271
}),
272+
unstable("default-setting", |o| {
273+
o.optmulti(
274+
"",
275+
"default-setting",
276+
"Default value for a rustdoc setting (used when \"rustdoc-SETTING\" is absent \
277+
from web browser Local Storage). If VALUE is not supplied, \"true\" is used. \
278+
Supported SETTINGs and VALUEs are not documented and not stable.",
279+
"SETTING[=VALUE]",
280+
)
281+
}),
272282
stable("theme", |o| {
273283
o.optmulti(
274284
"",

0 commit comments

Comments
 (0)