From dbcf68951c564f946ab0021c7699ea1a4bf861d0 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Thu, 20 Dec 2018 13:28:55 +0100 Subject: [PATCH] Add no-crate filter option on rustdoc --- src/librustdoc/config.rs | 5 +++++ src/librustdoc/html/layout.rs | 25 ++++++++++++++------- src/librustdoc/html/render.rs | 20 ++++++++++++----- src/librustdoc/html/static/main.js | 8 ++++--- src/librustdoc/html/static/rustdoc.css | 6 ++++- src/librustdoc/html/static/themes/dark.css | 6 ++++- src/librustdoc/html/static/themes/light.css | 6 ++++- src/librustdoc/lib.rs | 5 +++++ src/test/rustdoc/no-crate-filter.rs | 16 +++++++++++++ 9 files changed, 78 insertions(+), 19 deletions(-) create mode 100644 src/test/rustdoc/no-crate-filter.rs diff --git a/src/librustdoc/config.rs b/src/librustdoc/config.rs index f9a46fe362e..7962b45907a 100644 --- a/src/librustdoc/config.rs +++ b/src/librustdoc/config.rs @@ -195,6 +195,9 @@ pub struct RenderOptions { /// 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. pub markdown_playground_url: Option, + /// 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 { @@ -437,6 +440,7 @@ pub fn from_matches(matches: &getopts::Matches) -> Result { let crate_version = matches.opt_str("crate-version"); 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 generate_search_filter = !matches.opt_present("disable-per-crate-search"); let (lint_opts, describe_lints, lint_cap) = get_cmd_lint_options(matches, error_format); @@ -479,6 +483,7 @@ pub fn from_matches(matches: &getopts::Matches) -> Result { markdown_no_toc, markdown_css, markdown_playground_url, + generate_search_filter, } }) } diff --git a/src/librustdoc/html/layout.rs b/src/librustdoc/html/layout.rs index d8a57bc93fd..9caeec39ab1 100644 --- a/src/librustdoc/html/layout.rs +++ b/src/librustdoc/html/layout.rs @@ -35,10 +35,15 @@ pub struct Page<'a> { } pub fn render( - dst: &mut dyn io::Write, layout: &Layout, page: &Page, sidebar: &S, t: &T, - css_file_extension: bool, themes: &[PathBuf]) - -> io::Result<()> -{ + dst: &mut dyn io::Write, + layout: &Layout, + 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); write!(dst, "\ @@ -91,10 +96,7 @@ pub fn render(