]> git.lizzy.rs Git - rust.git/commitdiff
Add no-crate filter option on rustdoc
authorGuillaume Gomez <guillaume1.gomez@gmail.com>
Thu, 20 Dec 2018 12:28:55 +0000 (13:28 +0100)
committerGuillaume Gomez <guillaume1.gomez@gmail.com>
Mon, 24 Dec 2018 17:19:36 +0000 (18:19 +0100)
src/librustdoc/config.rs
src/librustdoc/html/layout.rs
src/librustdoc/html/render.rs
src/librustdoc/html/static/main.js
src/librustdoc/html/static/rustdoc.css
src/librustdoc/html/static/themes/dark.css
src/librustdoc/html/static/themes/light.css
src/librustdoc/lib.rs
src/test/rustdoc/no-crate-filter.rs [new file with mode: 0644]

index f9a46fe362e3c6c4a43b472e2664f1f083fd9e88..7962b45907a7d241c986459592e4a10845c5af16 100644 (file)
@@ -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<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 {
@@ -437,6 +440,7 @@ pub fn from_matches(matches: &getopts::Matches) -> Result<Options, isize> {
         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<Options, isize> {
                 markdown_no_toc,
                 markdown_css,
                 markdown_playground_url,
+                generate_search_filter,
             }
         })
     }
index d8a57bc93fd6c1e1c3ce8d8c5966b05450313456..9caeec39ab104d627699c7d9948f404f3f90a705 100644 (file)
@@ -35,10 +35,15 @@ pub struct Page<'a> {
 }
 
 pub fn render<T: fmt::Display, S: fmt::Display>(
-    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,
 "<!DOCTYPE html>\
@@ -91,10 +96,7 @@ pub fn render<T: fmt::Display, S: fmt::Display>(
     <nav class=\"sub\">\
         <form class=\"search-form js-only\">\
             <div class=\"search-container\">\
-                <div>\
-                    <select id=\"crate-search\">\
-                        <option value=\"All crates\">All crates</option>\
-                    </select>\
+                <div>{filter_crates}\
                     <input class=\"search-input\" name=\"search\" \
                            autocomplete=\"off\" \
                            spellcheck=\"false\" \
@@ -224,6 +226,13 @@ pub fn render<T: fmt::Display, S: fmt::Display>(
                 root_path=page.root_path,
                 extra_script=e)
     }).collect::<String>(),
+    filter_crates=if generate_search_filter {
+        "<select id=\"crate-search\">\
+            <option value=\"All crates\">All crates</option>\
+        </select>"
+    } else {
+        ""
+    },
     )
 }
 
index e47ec9ec2f051b9dc008e72e5aab0811030d4e28..5974cc114511776048b291114858f1501d6dad74 100644 (file)
@@ -143,6 +143,9 @@ struct SharedContext {
     /// Optional path string to be used to load static files on output pages. If not set, uses
     /// combinations of `../` to reach the documentation root.
     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 {
@@ -510,6 +513,7 @@ pub fn run(mut krate: clean::Crate,
         extern_html_root_urls,
         resource_suffix,
         static_root_path,
+        generate_search_filter,
         ..
     } = options;
 
@@ -538,6 +542,7 @@ pub fn run(mut krate: clean::Crate,
         themes,
         resource_suffix,
         static_root_path,
+        generate_search_filter,
     };
 
     // If user passed in `--playground-url` arg, we fill in crate name here
@@ -1109,7 +1114,8 @@ fn to_json_string(&self) -> String {
             try_err!(layout::render(&mut w, &cx.shared.layout,
                                     &page, &(""), &content,
                                     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);
         }
     }
@@ -1384,7 +1390,8 @@ fn emit_source(&mut self, filename: &FileName) -> io::Result<()> {
         layout::render(&mut w, &self.scx.layout,
                        &page, &(""), &Source(contents),
                        self.scx.css_file_extension.is_some(),
-                       &self.scx.themes)?;
+                       &self.scx.themes,
+                       self.scx.generate_search_filter)?;
         w.flush()?;
         self.scx.local_sources.insert(p.clone(), href);
         Ok(())
@@ -1986,7 +1993,8 @@ fn krate(self, mut krate: clean::Crate) -> Result<(), Error> {
         try_err!(layout::render(&mut w, &self.shared.layout,
                                 &page, &sidebar, &all,
                                 self.shared.css_file_extension.is_some(),
-                                &self.shared.themes),
+                                &self.shared.themes,
+                                self.shared.generate_search_filter),
                  &final_file);
 
         // Generating settings page.
@@ -2006,7 +2014,8 @@ fn krate(self, mut krate: clean::Crate) -> Result<(), Error> {
         try_err!(layout::render(&mut w, &layout,
                                 &page, &sidebar, &settings,
                                 self.shared.css_file_extension.is_some(),
-                                &themes),
+                                &themes,
+                                self.shared.generate_search_filter),
                  &settings_file);
 
         Ok(())
@@ -2067,7 +2076,8 @@ fn render_item(&self,
                            &Sidebar{ cx: self, item: it },
                            &Item{ cx: self, item: it },
                            self.shared.css_file_extension.is_some(),
-                           &self.shared.themes)?;
+                           &self.shared.themes,
+                           self.shared.generate_search_filter)?;
         } else {
             let mut url = self.root_path();
             if let Some(&(ref names, ty)) = cache().paths.get(&it.def_id) {
index d5b8ecd4807f13442bc650c94da00095c4d2090c..3052e30afb1c0c3e237cec252903c5a616617d44 100644 (file)
@@ -2434,9 +2434,11 @@ if (!DOMTokenList.prototype.remove) {
             return;
         }
         var crates_text = [];
-        for (var crate in crates) {
-            if (crates.hasOwnProperty(crate)) {
-                crates_text.push(crate);
+        if (crates.length > 1) {
+            for (var crate in crates) {
+                if (crates.hasOwnProperty(crate)) {
+                    crates_text.push(crate);
+                }
             }
         }
         crates_text.sort(function(a, b) {
index 3958986e492775f5f7335e92c50370222bdf3b8b..86241671ecd26388b6cbb6d18264930f95a65725 100644 (file)
@@ -661,7 +661,7 @@ a {
        box-sizing: border-box !important;
        outline: none;
        border: none;
-       border-radius: 0 1px 1px 0;
+       border-radius: 1px;
        margin-top: 5px;
        padding: 10px 16px;
        font-size: 17px;
@@ -671,6 +671,10 @@ a {
        width: 100%;
 }
 
+#crate-search + .search-input {
+       border-radius: 0 1px 1px 0;
+}
+
 .search-input:focus {
        border-radius: 2px;
        border: 0;
index be3ffed2b2659f70e8b7933258e0536bcdd21c96..f5c07dd85d1a185d7c1574db975d6dfddb73339c 100644 (file)
@@ -194,7 +194,7 @@ a.test-arrow {
 
 .search-input {
        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;
 }
 
@@ -202,6 +202,10 @@ a.test-arrow {
        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.internal { background: #FFB9B3; border-color: #B71C1C; color: #404040; }
 .stab.deprecated { background: #F3DFFF; border-color: #7F0087;  color: #404040; }
index 4ae10492ae6b2a23e55b20567102a62e76f80dd9..446e765252f7a8eb07991e63d4319a48bb9c83f0 100644 (file)
@@ -195,7 +195,7 @@ a.test-arrow {
 
 .search-input {
        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;
 }
 
@@ -203,6 +203,10 @@ a.test-arrow {
        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.internal { background: #FFB9B3; border-color: #B71C1C; }
 .stab.deprecated { background: #F3DFFF; border-color: #7F0087; }
index 4f59f67e94f98e2e2a965d589d4508c375d44742..6edb0ea74cff489868cbdc91743766d7d1a395fe 100644 (file)
@@ -346,6 +346,11 @@ fn opts() -> Vec<RustcOptGroup> {
                       If not set, uses combinations of '../' to reach the documentation root.",
                      "PATH")
         }),
+        unstable("disable-per-crate-search", |o| {
+            o.optflag("",
+                      "disable-per-crate-search",
+                      "disables generating the crate selector on the search box")
+        }),
     ]
 }
 
diff --git a/src/test/rustdoc/no-crate-filter.rs b/src/test/rustdoc/no-crate-filter.rs
new file mode 100644 (file)
index 0000000..e49ce9e
--- /dev/null
@@ -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;