Auto merge of #57006 - GuillaumeGomez:no-crate-filter, r=QuietMisdreavus
Add no-crate filter option on rustdoc @onur asked me about it so here it is! r? @QuietMisdreavus
This commit is contained in:
commit
43d26b1f35
9 changed files with 78 additions and 19 deletions
|
@ -185,6 +185,9 @@ pub struct RenderOptions {
|
||||||
/// If present, playground URL to use in the "Run" button added to code samples generated from
|
/// If present, playground URL to use in the "Run" button added to code samples generated from
|
||||||
/// standalone Markdown files. If not present, `playground_url` is used.
|
/// standalone Markdown files. If not present, `playground_url` is used.
|
||||||
pub markdown_playground_url: Option<String>,
|
pub markdown_playground_url: Option<String>,
|
||||||
|
/// If false, the `select` element to have search filtering by crates on rendered docs
|
||||||
|
/// won't be generated.
|
||||||
|
pub generate_search_filter: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Options {
|
impl Options {
|
||||||
|
@ -427,6 +430,7 @@ impl Options {
|
||||||
let crate_version = matches.opt_str("crate-version");
|
let crate_version = matches.opt_str("crate-version");
|
||||||
let enable_index_page = matches.opt_present("enable-index-page") || index_page.is_some();
|
let enable_index_page = matches.opt_present("enable-index-page") || index_page.is_some();
|
||||||
let static_root_path = matches.opt_str("static-root-path");
|
let static_root_path = matches.opt_str("static-root-path");
|
||||||
|
let generate_search_filter = !matches.opt_present("disable-per-crate-search");
|
||||||
|
|
||||||
let (lint_opts, describe_lints, lint_cap) = get_cmd_lint_options(matches, error_format);
|
let (lint_opts, describe_lints, lint_cap) = get_cmd_lint_options(matches, error_format);
|
||||||
|
|
||||||
|
@ -469,6 +473,7 @@ impl Options {
|
||||||
markdown_no_toc,
|
markdown_no_toc,
|
||||||
markdown_css,
|
markdown_css,
|
||||||
markdown_playground_url,
|
markdown_playground_url,
|
||||||
|
generate_search_filter,
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,10 +25,15 @@ pub struct Page<'a> {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn render<T: fmt::Display, S: fmt::Display>(
|
pub fn render<T: fmt::Display, S: fmt::Display>(
|
||||||
dst: &mut dyn io::Write, layout: &Layout, page: &Page, sidebar: &S, t: &T,
|
dst: &mut dyn io::Write,
|
||||||
css_file_extension: bool, themes: &[PathBuf])
|
layout: &Layout,
|
||||||
-> io::Result<()>
|
page: &Page,
|
||||||
{
|
sidebar: &S,
|
||||||
|
t: &T,
|
||||||
|
css_file_extension: bool,
|
||||||
|
themes: &[PathBuf],
|
||||||
|
generate_search_filter: bool,
|
||||||
|
) -> io::Result<()> {
|
||||||
let static_root_path = page.static_root_path.unwrap_or(page.root_path);
|
let static_root_path = page.static_root_path.unwrap_or(page.root_path);
|
||||||
write!(dst,
|
write!(dst,
|
||||||
"<!DOCTYPE html>\
|
"<!DOCTYPE html>\
|
||||||
|
@ -81,10 +86,7 @@ pub fn render<T: fmt::Display, S: fmt::Display>(
|
||||||
<nav class=\"sub\">\
|
<nav class=\"sub\">\
|
||||||
<form class=\"search-form js-only\">\
|
<form class=\"search-form js-only\">\
|
||||||
<div class=\"search-container\">\
|
<div class=\"search-container\">\
|
||||||
<div>\
|
<div>{filter_crates}\
|
||||||
<select id=\"crate-search\">\
|
|
||||||
<option value=\"All crates\">All crates</option>\
|
|
||||||
</select>\
|
|
||||||
<input class=\"search-input\" name=\"search\" \
|
<input class=\"search-input\" name=\"search\" \
|
||||||
autocomplete=\"off\" \
|
autocomplete=\"off\" \
|
||||||
spellcheck=\"false\" \
|
spellcheck=\"false\" \
|
||||||
|
@ -214,6 +216,13 @@ pub fn render<T: fmt::Display, S: fmt::Display>(
|
||||||
root_path=page.root_path,
|
root_path=page.root_path,
|
||||||
extra_script=e)
|
extra_script=e)
|
||||||
}).collect::<String>(),
|
}).collect::<String>(),
|
||||||
|
filter_crates=if generate_search_filter {
|
||||||
|
"<select id=\"crate-search\">\
|
||||||
|
<option value=\"All crates\">All crates</option>\
|
||||||
|
</select>"
|
||||||
|
} else {
|
||||||
|
""
|
||||||
|
},
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -133,6 +133,9 @@ struct SharedContext {
|
||||||
/// Optional path string to be used to load static files on output pages. If not set, uses
|
/// Optional path string to be used to load static files on output pages. If not set, uses
|
||||||
/// combinations of `../` to reach the documentation root.
|
/// combinations of `../` to reach the documentation root.
|
||||||
pub static_root_path: Option<String>,
|
pub static_root_path: Option<String>,
|
||||||
|
/// If false, the `select` element to have search filtering by crates on rendered docs
|
||||||
|
/// won't be generated.
|
||||||
|
pub generate_search_filter: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl SharedContext {
|
impl SharedContext {
|
||||||
|
@ -500,6 +503,7 @@ pub fn run(mut krate: clean::Crate,
|
||||||
extern_html_root_urls,
|
extern_html_root_urls,
|
||||||
resource_suffix,
|
resource_suffix,
|
||||||
static_root_path,
|
static_root_path,
|
||||||
|
generate_search_filter,
|
||||||
..
|
..
|
||||||
} = options;
|
} = options;
|
||||||
|
|
||||||
|
@ -528,6 +532,7 @@ pub fn run(mut krate: clean::Crate,
|
||||||
themes,
|
themes,
|
||||||
resource_suffix,
|
resource_suffix,
|
||||||
static_root_path,
|
static_root_path,
|
||||||
|
generate_search_filter,
|
||||||
};
|
};
|
||||||
|
|
||||||
// If user passed in `--playground-url` arg, we fill in crate name here
|
// If user passed in `--playground-url` arg, we fill in crate name here
|
||||||
|
@ -1099,7 +1104,8 @@ themePicker.onblur = handleThemeButtonsBlur;
|
||||||
try_err!(layout::render(&mut w, &cx.shared.layout,
|
try_err!(layout::render(&mut w, &cx.shared.layout,
|
||||||
&page, &(""), &content,
|
&page, &(""), &content,
|
||||||
cx.shared.css_file_extension.is_some(),
|
cx.shared.css_file_extension.is_some(),
|
||||||
&cx.shared.themes), &dst);
|
&cx.shared.themes,
|
||||||
|
cx.shared.generate_search_filter), &dst);
|
||||||
try_err!(w.flush(), &dst);
|
try_err!(w.flush(), &dst);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1372,7 +1378,8 @@ impl<'a> SourceCollector<'a> {
|
||||||
layout::render(&mut w, &self.scx.layout,
|
layout::render(&mut w, &self.scx.layout,
|
||||||
&page, &(""), &Source(contents),
|
&page, &(""), &Source(contents),
|
||||||
self.scx.css_file_extension.is_some(),
|
self.scx.css_file_extension.is_some(),
|
||||||
&self.scx.themes)?;
|
&self.scx.themes,
|
||||||
|
self.scx.generate_search_filter)?;
|
||||||
w.flush()?;
|
w.flush()?;
|
||||||
self.scx.local_sources.insert(p.clone(), href);
|
self.scx.local_sources.insert(p.clone(), href);
|
||||||
Ok(())
|
Ok(())
|
||||||
|
@ -1974,7 +1981,8 @@ impl Context {
|
||||||
try_err!(layout::render(&mut w, &self.shared.layout,
|
try_err!(layout::render(&mut w, &self.shared.layout,
|
||||||
&page, &sidebar, &all,
|
&page, &sidebar, &all,
|
||||||
self.shared.css_file_extension.is_some(),
|
self.shared.css_file_extension.is_some(),
|
||||||
&self.shared.themes),
|
&self.shared.themes,
|
||||||
|
self.shared.generate_search_filter),
|
||||||
&final_file);
|
&final_file);
|
||||||
|
|
||||||
// Generating settings page.
|
// Generating settings page.
|
||||||
|
@ -1994,7 +2002,8 @@ impl Context {
|
||||||
try_err!(layout::render(&mut w, &layout,
|
try_err!(layout::render(&mut w, &layout,
|
||||||
&page, &sidebar, &settings,
|
&page, &sidebar, &settings,
|
||||||
self.shared.css_file_extension.is_some(),
|
self.shared.css_file_extension.is_some(),
|
||||||
&themes),
|
&themes,
|
||||||
|
self.shared.generate_search_filter),
|
||||||
&settings_file);
|
&settings_file);
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
|
@ -2055,7 +2064,8 @@ impl Context {
|
||||||
&Sidebar{ cx: self, item: it },
|
&Sidebar{ cx: self, item: it },
|
||||||
&Item{ cx: self, item: it },
|
&Item{ cx: self, item: it },
|
||||||
self.shared.css_file_extension.is_some(),
|
self.shared.css_file_extension.is_some(),
|
||||||
&self.shared.themes)?;
|
&self.shared.themes,
|
||||||
|
self.shared.generate_search_filter)?;
|
||||||
} else {
|
} else {
|
||||||
let mut url = self.root_path();
|
let mut url = self.root_path();
|
||||||
if let Some(&(ref names, ty)) = cache().paths.get(&it.def_id) {
|
if let Some(&(ref names, ty)) = cache().paths.get(&it.def_id) {
|
||||||
|
|
|
@ -2422,9 +2422,11 @@ if (!DOMTokenList.prototype.remove) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
var crates_text = [];
|
var crates_text = [];
|
||||||
for (var crate in crates) {
|
if (crates.length > 1) {
|
||||||
if (crates.hasOwnProperty(crate)) {
|
for (var crate in crates) {
|
||||||
crates_text.push(crate);
|
if (crates.hasOwnProperty(crate)) {
|
||||||
|
crates_text.push(crate);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
crates_text.sort(function(a, b) {
|
crates_text.sort(function(a, b) {
|
||||||
|
|
|
@ -649,7 +649,7 @@ a {
|
||||||
box-sizing: border-box !important;
|
box-sizing: border-box !important;
|
||||||
outline: none;
|
outline: none;
|
||||||
border: none;
|
border: none;
|
||||||
border-radius: 0 1px 1px 0;
|
border-radius: 1px;
|
||||||
margin-top: 5px;
|
margin-top: 5px;
|
||||||
padding: 10px 16px;
|
padding: 10px 16px;
|
||||||
font-size: 17px;
|
font-size: 17px;
|
||||||
|
@ -659,6 +659,10 @@ a {
|
||||||
width: 100%;
|
width: 100%;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#crate-search + .search-input {
|
||||||
|
border-radius: 0 1px 1px 0;
|
||||||
|
}
|
||||||
|
|
||||||
.search-input:focus {
|
.search-input:focus {
|
||||||
border-radius: 2px;
|
border-radius: 2px;
|
||||||
border: 0;
|
border: 0;
|
||||||
|
|
|
@ -182,7 +182,7 @@ a.test-arrow {
|
||||||
|
|
||||||
.search-input {
|
.search-input {
|
||||||
color: #111;
|
color: #111;
|
||||||
box-shadow: 1px 0 0 1px #000, 0 0 0 2px transparent;
|
box-shadow: 0 0 0 1px #000, 0 0 0 2px transparent;
|
||||||
background-color: #f0f0f0;
|
background-color: #f0f0f0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -190,6 +190,10 @@ a.test-arrow {
|
||||||
border-color: #008dfd;
|
border-color: #008dfd;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#crate-search + .search-input {
|
||||||
|
box-shadow: 1px 0 0 1px #000, 0 0 0 2px transparent;
|
||||||
|
}
|
||||||
|
|
||||||
.stab.unstable { background: #FFF5D6; border-color: #FFC600; color: #404040; }
|
.stab.unstable { background: #FFF5D6; border-color: #FFC600; color: #404040; }
|
||||||
.stab.internal { background: #FFB9B3; border-color: #B71C1C; color: #404040; }
|
.stab.internal { background: #FFB9B3; border-color: #B71C1C; color: #404040; }
|
||||||
.stab.deprecated { background: #F3DFFF; border-color: #7F0087; color: #404040; }
|
.stab.deprecated { background: #F3DFFF; border-color: #7F0087; color: #404040; }
|
||||||
|
|
|
@ -183,7 +183,7 @@ a.test-arrow {
|
||||||
|
|
||||||
.search-input {
|
.search-input {
|
||||||
color: #555;
|
color: #555;
|
||||||
box-shadow: 1px 0 0 1px #e0e0e0, 0 0 0 2px transparent;
|
box-shadow: 0 0 0 1px #e0e0e0, 0 0 0 2px transparent;
|
||||||
background-color: white;
|
background-color: white;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -191,6 +191,10 @@ a.test-arrow {
|
||||||
border-color: #66afe9;
|
border-color: #66afe9;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#crate-search + .search-input {
|
||||||
|
box-shadow: 1px 0 0 1px #e0e0e0, 0 0 0 2px transparent;
|
||||||
|
}
|
||||||
|
|
||||||
.stab.unstable { background: #FFF5D6; border-color: #FFC600; }
|
.stab.unstable { background: #FFF5D6; border-color: #FFC600; }
|
||||||
.stab.internal { background: #FFB9B3; border-color: #B71C1C; }
|
.stab.internal { background: #FFB9B3; border-color: #B71C1C; }
|
||||||
.stab.deprecated { background: #F3DFFF; border-color: #7F0087; }
|
.stab.deprecated { background: #F3DFFF; border-color: #7F0087; }
|
||||||
|
|
|
@ -336,6 +336,11 @@ fn opts() -> Vec<RustcOptGroup> {
|
||||||
If not set, uses combinations of '../' to reach the documentation root.",
|
If not set, uses combinations of '../' to reach the documentation root.",
|
||||||
"PATH")
|
"PATH")
|
||||||
}),
|
}),
|
||||||
|
unstable("disable-per-crate-search", |o| {
|
||||||
|
o.optflag("",
|
||||||
|
"disable-per-crate-search",
|
||||||
|
"disables generating the crate selector on the search box")
|
||||||
|
}),
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
16
src/test/rustdoc/no-crate-filter.rs
Normal file
16
src/test/rustdoc/no-crate-filter.rs
Normal file
|
@ -0,0 +1,16 @@
|
||||||
|
// Copyright 2018 The Rust Project Developers. See the COPYRIGHT
|
||||||
|
// file at the top-level directory of this distribution and at
|
||||||
|
// http://rust-lang.org/COPYRIGHT.
|
||||||
|
//
|
||||||
|
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
||||||
|
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||||
|
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
||||||
|
// option. This file may not be copied, modified, or distributed
|
||||||
|
// except according to those terms.
|
||||||
|
|
||||||
|
#![crate_name = "foo"]
|
||||||
|
|
||||||
|
// compile-flags: -Z unstable-options --disable-per-crate-search
|
||||||
|
|
||||||
|
// @!has 'foo/struct.Foo.html' '//*[id="crate-search"]'
|
||||||
|
pub struct Foo;
|
Loading…
Add table
Add a link
Reference in a new issue