diff --git a/src/librustdoc/html/static/playpen.js b/src/librustdoc/html/static/playpen.js index ef8bdf5e2ce97..6b96a285992bb 100644 --- a/src/librustdoc/html/static/playpen.js +++ b/src/librustdoc/html/static/playpen.js @@ -12,6 +12,8 @@ /*globals $: true, rootPath: true */ document.addEventListener('DOMContentLoaded', function() { + 'use strict'; + if (!window.playgroundUrl) { return; } diff --git a/src/rustbook/build.rs b/src/rustbook/build.rs index aca0db4e1adbe..4b6d67d2d2620 100644 --- a/src/rustbook/build.rs +++ b/src/rustbook/build.rs @@ -23,8 +23,6 @@ use error::{err, CliResult, CommandResult}; use book; use book::{Book, BookItem}; -use javascript; - use rustdoc; struct Build; @@ -82,7 +80,7 @@ fn write_toc(book: &Book, current_page: &BookItem, out: &mut Write) -> io::Resul } fn render(book: &Book, tgt: &Path) -> CliResult<()> { - let tmp = try!(TempDir::new("rust-book")); + let tmp = try!(TempDir::new("rustbook")); for (_section, item) in book.iter() { let out_path = match item.path.parent() { @@ -113,26 +111,28 @@ fn render(book: &Book, tgt: &Path) -> CliResult<()> { // write the prelude to a temporary HTML file for rustdoc inclusion let prelude = tmp.path().join("prelude.html"); { - let mut toc = BufWriter::new(try!(File::create(&prelude))); - try!(writeln!(&mut toc, r#""#)); - let _ = write_toc(book, &item, &mut toc); - try!(writeln!(&mut toc, "
")); - try!(writeln!(&mut toc, "
")); + let mut buffer = BufWriter::new(try!(File::create(&prelude))); + try!(writeln!(&mut buffer, r#" + "#)); + let _ = write_toc(book, &item, &mut buffer); + try!(writeln!(&mut buffer, "
")); + try!(writeln!(&mut buffer, "
")); } // write the postlude to a temporary HTML file for rustdoc inclusion let postlude = tmp.path().join("postlude.html"); { - let mut toc = BufWriter::new(try!(File::create(&postlude))); - try!(toc.write_all(javascript::JAVASCRIPT.as_bytes())); - try!(writeln!(&mut toc, "
")); + let mut buffer = BufWriter::new(try!(File::create(&postlude))); + try!(writeln!(&mut buffer, "")); + try!(writeln!(&mut buffer, "")); + try!(writeln!(&mut buffer, "
")); } try!(fs::create_dir_all(&out_path)); @@ -144,7 +144,7 @@ fn render(book: &Book, tgt: &Path) -> CliResult<()> { format!("--html-before-content={}", prelude.display()), format!("--html-after-content={}", postlude.display()), format!("--markdown-playground-url=https://play.rust-lang.org"), - format!("--markdown-css={}", item.path_to_root.join("rust-book.css").display()), + format!("--markdown-css={}", item.path_to_root.join("rustbook.css").display()), "--markdown-no-toc".to_string(), ]; let output_result = rustdoc::main_args(rustdoc_args); @@ -199,10 +199,10 @@ impl Subcommand for Build { let css = include_bytes!("static/rustbook.css"); let js = include_bytes!("static/rustbook.js"); - let mut css_file = try!(File::create(tgt.join("rust-book.css"))); + let mut css_file = try!(File::create(tgt.join("rustbook.css"))); try!(css_file.write_all(css)); - let mut js_file = try!(File::create(tgt.join("rust-book.js"))); + let mut js_file = try!(File::create(tgt.join("rustbook.js"))); try!(js_file.write_all(js)); diff --git a/src/rustbook/help.rs b/src/rustbook/help.rs index 995d2f2494a49..c90c2b936092a 100644 --- a/src/rustbook/help.rs +++ b/src/rustbook/help.rs @@ -36,7 +36,7 @@ impl Subcommand for Help { } pub fn usage() { - println!("Usage: rust-book []"); + println!("Usage: rustbook []"); println!(""); println!("The must be one of:"); println!(" help Print this message."); diff --git a/src/rustbook/javascript.rs b/src/rustbook/javascript.rs deleted file mode 100644 index beddc23fe2bdd..0000000000000 --- a/src/rustbook/javascript.rs +++ /dev/null @@ -1,16 +0,0 @@ -// Copyright 2015 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 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -// The rust-book JavaScript in string form. - -pub static JAVASCRIPT: &'static str = r#" - - -"#; diff --git a/src/rustbook/main.rs b/src/rustbook/main.rs index 17a34cdc611a2..d23e868eeadd1 100644 --- a/src/rustbook/main.rs +++ b/src/rustbook/main.rs @@ -35,8 +35,6 @@ mod build; mod serve; mod test; -mod javascript; - static EXIT_STATUS: AtomicIsize = ATOMIC_ISIZE_INIT; fn main() { diff --git a/src/rustbook/static/rustbook.css b/src/rustbook/static/rustbook.css index 6b9e7aa58f247..3755338f427df 100644 --- a/src/rustbook/static/rustbook.css +++ b/src/rustbook/static/rustbook.css @@ -1,5 +1,5 @@ /** - * Copyright 2013 The Rust Project Developers. See the COPYRIGHT + * Copyright 2013-2015 The Rust Project Developers. See the COPYRIGHT * file at the top-level directory of this distribution and at * http://rust-lang.org/COPYRIGHT. * @@ -10,12 +10,11 @@ * except according to those terms. */ -@import url("../rust.css"); +@import url('../rust.css'); body { - max-width:none; - font: 16px/1.4 'Source Serif Pro', Georgia, Times, 'Times New Roman', serif; - line-height: 1.6; + max-width: none; + font: 16px/1.6 'Source Serif Pro', Georgia, Times, 'Times New Roman', serif; color: #333; } @@ -28,68 +27,64 @@ h1, h2, h3, h4, h5, h6 { @media only screen { #toc { position: fixed; - left: 0px; - top: 0px; - bottom: 0px; + top: 0; + left: 0; + bottom: 0; width: 300px; overflow-y: auto; - border-right: 1px solid rgba(0, 0, 0, 0.07); - padding: 10px 10px; + border-right: 1px solid #e8e8e8; + padding: 0 15px; font-size: 14px; - box-sizing: border-box; - -webkit-overflow-scrolling: touch; background-color: #fafafa; - color: #364149; + -webkit-overflow-scrolling: touch; } #page-wrapper { position: absolute; - left: 310px; - right: 0px; - top: 0px; - box-sizing: border-box; - background: none repeat scroll 0% 0% #FFF; + top: 0; + left: 300px; + right: 0; + padding: 0 15px; -webkit-overflow-scrolling: touch; } } @media only print { - #toc, #nav, #menu-bar { + #toc, #nav { display: none; } } -@media only screen and (max-width: 1060px) { +@media only screen and (max-width: 1023px) { #toc { width: 100%; - margin-right: 0; top: 40px; } + #page-wrapper { top: 40px; - left: 15px; - padding-right: 15px; + left: 0; } + .mobile-hidden { display: none; } } #page { - margin-left: auto; - margin-right:auto; + margin: 0 auto; max-width: 750px; padding-bottom: 50px; } .chapter { - list-style: none outside none; - padding-left: 0px; + list-style: none; + padding-left: 0; line-height: 30px; } .section { - list-style: none outside none; + list-style: none; padding-left: 20px; line-height: 40px; } @@ -105,28 +100,21 @@ h1, h2, h3, h4, h5, h6 { padding: 5px 0; } -.chapter li a.active { - color: #008cff; -} - +.chapter li a.active, .chapter li a:hover { color: #008cff; text-decoration: none; } #toggle-nav { - height: 20px; - width: 30px; - padding: 3px 3px 0 3px; -} - -#toggle-nav { + cursor: pointer; margin-top: 5px; width: 30px; height: 30px; - background-color: #FFF; + background-color: #fff; border: 1px solid #666; - border-radius: 3px 3px 3px 3px; + border-radius: 3px; + padding: 3px 3px 0 3px; } .sr-only { @@ -160,10 +148,6 @@ pre { border-radius: 3px; } -.nav-previous-next { - margin-top: 60px; -} - .left { float: left; } diff --git a/src/rustbook/static/rustbook.js b/src/rustbook/static/rustbook.js index fdefab2875926..d8ab15260edb4 100644 --- a/src/rustbook/static/rustbook.js +++ b/src/rustbook/static/rustbook.js @@ -1,4 +1,4 @@ -// Copyright 2014 The Rust Project Developers. See the COPYRIGHT +// Copyright 2014-2015 The Rust Project Developers. See the COPYRIGHT // file at the top-level directory of this distribution and at // http://rust-lang.org/COPYRIGHT. // @@ -8,66 +8,71 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +/*jslint browser: true, es5: true */ +/*globals $: true, rootPath: true */ -document.addEventListener("DOMContentLoaded", function(event) { +document.addEventListener('DOMContentLoaded', function() { + 'use strict'; - document.getElementById("toggle-nav").onclick = toggleNav; + document.getElementById('toggle-nav').onclick = function(e) { + var toc = document.getElementById('toc'); + var pagewrapper = document.getElementById('page-wrapper'); + toggleClass(toc, 'mobile-hidden'); + toggleClass(pagewrapper, 'mobile-hidden'); + }; - function toggleNav() { - var toc = document.getElementById("toc"); - var pagewrapper = document.getElementById("page-wrapper"); - toggleClass(toc, "mobile-hidden"); - toggleClass(pagewrapper, "mobile-hidden"); - } + function toggleClass(el, className) { + // from http://youmightnotneedjquery.com/ + if (el.classList) { + el.classList.toggle(className); + } else { + var classes = el.className.split(' '); + var existingIndex = classes.indexOf(className); - function toggleClass(el, className) { - // from http://youmightnotneedjquery.com/ - if (el.classList) { - el.classList.toggle(className); - } else { - var classes = el.className.split(' '); - var existingIndex = classes.indexOf(className); + if (existingIndex >= 0) { + classes.splice(existingIndex, 1); + } else { + classes.push(className); + } - if (existingIndex >= 0) { - classes.splice(existingIndex, 1); - } else { - classes.push(className); - } - - el.className = classes.join(' '); - } - } + el.className = classes.join(' '); + } + } - // The below code is used to add prev and next navigation links to the bottom - // of each of the sections. - // It works by extracting the current page based on the url and iterates over - // the menu links until it finds the menu item for the current page. We then - // create a copy of the preceding and following menu links and add the - // correct css class and insert them into the bottom of the page. - var toc = document.getElementById('toc').getElementsByTagName('a'); - var href = document.location.pathname.split('/').pop(); - if (href === 'index.html' || href === '') { - href = 'README.html'; - } + // The below code is used to add prev and next navigation links to the + // bottom of each of the sections. + // It works by extracting the current page based on the url and iterates + // over the menu links until it finds the menu item for the current page. We + // then create a copy of the preceding and following menu links and add the + // correct css class and insert them into the bottom of the page. + var toc = document.getElementById('toc').getElementsByTagName('a'); + var href = document.location.pathname.split('/').pop(); - for (var i = 0; i < toc.length; i++) { - if (toc[i].attributes.href.value.split('/').pop() === href) { - var nav = document.createElement('p'); - if (i > 0) { - var prevNode = toc[i-1].cloneNode(true); - prevNode.className = 'left'; - prevNode.setAttribute('rel', 'prev'); - nav.appendChild(prevNode); - } - if (i < toc.length - 1) { - var nextNode = toc[i+1].cloneNode(true); - nextNode.className = 'right'; - nextNode.setAttribute('rel', 'next'); - nav.appendChild(nextNode); - } - document.getElementById('page').appendChild(nav); - break; + if (href === 'index.html' || href === '') { + href = 'README.html'; } - } + for (var i = 0; i < toc.length; i++) { + if (toc[i].attributes.href.value.split('/').pop() === href) { + var nav = document.createElement('p'); + + if (i > 0) { + var prevNode = toc[i-1].cloneNode(true); + prevNode.className = 'left'; + prevNode.setAttribute('rel', 'prev'); + nav.appendChild(prevNode); + } + + if (i < toc.length - 1) { + var nextNode = toc[i+1].cloneNode(true); + nextNode.className = 'right'; + nextNode.setAttribute('rel', 'next'); + nav.appendChild(nextNode); + } + + document.getElementById('page').appendChild(nav); + + break; + } + } }); diff --git a/src/rustbook/subcommand.rs b/src/rustbook/subcommand.rs index 5a8e1f695ae6e..a66c2b4f3024d 100644 --- a/src/rustbook/subcommand.rs +++ b/src/rustbook/subcommand.rs @@ -8,7 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -//! Common API for all rust-book subcommands. +//! Common API for all rustbook subcommands. use error::CliResult; use error::CommandResult;