about summary refs log tree commit diff
path: root/src/librustdoc/html
diff options
context:
space:
mode:
authorkennytm <kennytm@gmail.com>2017-10-12 16:14:22 +0800
committerkennytm <kennytm@gmail.com>2017-10-13 01:58:36 +0800
commit445bbde7844eacb3de968e2584db2d44e6c4cbab (patch)
tree7a16afc1e827ce53ffc5a9f4e86918b6b77ae5be /src/librustdoc/html
parent1807f27a338e8e3f8c3a9c99fde2223b5942e640 (diff)
parent7ea286e854d88529af76ca486ed676c9fb06e8ee (diff)
downloadrust-445bbde7844eacb3de968e2584db2d44e6c4cbab.tar.gz
rust-445bbde7844eacb3de968e2584db2d44e6c4cbab.zip
Rollup merge of #44989 - QuietMisdreavus:what-is-your-quest, r=GuillaumeGomez
let rustdoc print the crate version into docs

This PR adds a new unstable flag to rustdoc, `--crate-version`, which when present will add a new entry to the sidebar of the root module, printing the given version number:

![Screenshot of a test crate, showing "Version 1.3.37" under the crate name](https://user-images.githubusercontent.com/5217170/31104096-805e3f4c-a7a0-11e7-96fc-368b6fe063d6.png)

Closes #24336

(The WIP status is because i don't want to merge this until i can get the std docs to use it, which i need help from rustbuild people to make sure i get right.)
Diffstat (limited to 'src/librustdoc/html')
-rw-r--r--src/librustdoc/html/render.rs14
-rw-r--r--src/librustdoc/html/static/rustdoc.css9
2 files changed, 23 insertions, 0 deletions
diff --git a/src/librustdoc/html/render.rs b/src/librustdoc/html/render.rs
index e4017244522..967a19e0e96 100644
--- a/src/librustdoc/html/render.rs
+++ b/src/librustdoc/html/render.rs
@@ -256,6 +256,9 @@ pub struct Cache {
     // the access levels from crateanalysis.
     pub access_levels: Arc<AccessLevels<DefId>>,
 
+    /// The version of the crate being documented, if given fron the `--crate-version` flag.
+    pub crate_version: Option<String>,
+
     // Private fields only used when initially crawling a crate to build a cache
 
     stack: Vec<String>,
@@ -534,6 +537,7 @@ pub fn run(mut krate: clean::Crate,
         primitive_locations: FxHashMap(),
         stripped_mod: false,
         access_levels: krate.access_levels.clone(),
+        crate_version: krate.version.take(),
         orphan_impl_items: Vec::new(),
         traits: mem::replace(&mut krate.external_traits, FxHashMap()),
         deref_trait_did,
@@ -3433,6 +3437,16 @@ impl<'a> fmt::Display for Sidebar<'a> {
             write!(fmt, "{}", it.name.as_ref().unwrap())?;
             write!(fmt, "</p>")?;
 
+            if it.is_crate() {
+                if let Some(ref version) = cache().crate_version {
+                    write!(fmt,
+                           "<div class='block version'>\
+                            <p>Version {}</p>\
+                            </div>",
+                           version)?;
+                }
+            }
+
             match it.inner {
                 clean::StructItem(ref s) => sidebar_struct(fmt, it, s)?,
                 clean::TraitItem(ref t) => sidebar_trait(fmt, it, t)?,
diff --git a/src/librustdoc/html/static/rustdoc.css b/src/librustdoc/html/static/rustdoc.css
index 27574e67bc8..61a3902098f 100644
--- a/src/librustdoc/html/static/rustdoc.css
+++ b/src/librustdoc/html/static/rustdoc.css
@@ -203,6 +203,15 @@ nav.sub {
 	word-wrap: break-word;
 }
 
+.sidebar .version {
+	font-size: 15px;
+	text-align: center;
+	border-bottom: #DDDDDD 1px solid;
+	overflow-wrap: break-word;
+	word-wrap: break-word; /* deprecated */
+	word-break: break-word; /* Chrome, non-standard */
+}
+
 .location:empty {
 	border: none;
 }