Skip to content

Various rustbook improvements #28649

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Sep 26, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/librustdoc/html/static/playpen.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
/*globals $: true, rootPath: true */

document.addEventListener('DOMContentLoaded', function() {
'use strict';

if (!window.playgroundUrl) {
return;
}
Expand Down
42 changes: 21 additions & 21 deletions src/rustbook/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@ use error::{err, CliResult, CommandResult};
use book;
use book::{Book, BookItem};

use javascript;

use rustdoc;

struct Build;
Expand Down Expand Up @@ -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() {
Expand Down Expand Up @@ -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#"<div id="nav">
<button id="toggle-nav">
<span class="sr-only">Toggle navigation</span>
<span class="bar"></span>
<span class="bar"></span>
<span class="bar"></span>
</button>
</div>"#));
let _ = write_toc(book, &item, &mut toc);
try!(writeln!(&mut toc, "<div id='page-wrapper'>"));
try!(writeln!(&mut toc, "<div id='page'>"));
let mut buffer = BufWriter::new(try!(File::create(&prelude)));
try!(writeln!(&mut buffer, r#"
<div id="nav">
<button id="toggle-nav">
<span class="sr-only">Toggle navigation</span>
<span class="bar"></span>
<span class="bar"></span>
<span class="bar"></span>
</button>
</div>"#));
let _ = write_toc(book, &item, &mut buffer);
try!(writeln!(&mut buffer, "<div id='page-wrapper'>"));
try!(writeln!(&mut buffer, "<div id='page'>"));
}

// 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, "</div></div>"));
let mut buffer = BufWriter::new(try!(File::create(&postlude)));
try!(writeln!(&mut buffer, "<script src='rustbook.js'></script>"));
try!(writeln!(&mut buffer, "<script src='playpen.js'></script>"));
try!(writeln!(&mut buffer, "</div></div>"));
}

try!(fs::create_dir_all(&out_path));
Expand All @@ -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);
Expand Down Expand Up @@ -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));


Expand Down
2 changes: 1 addition & 1 deletion src/rustbook/help.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ impl Subcommand for Help {
}

pub fn usage() {
println!("Usage: rust-book <command> [<args>]");
println!("Usage: rustbook <command> [<args>]");
println!("");
println!("The <command> must be one of:");
println!(" help Print this message.");
Expand Down
16 changes: 0 additions & 16 deletions src/rustbook/javascript.rs

This file was deleted.

2 changes: 0 additions & 2 deletions src/rustbook/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,6 @@ mod build;
mod serve;
mod test;

mod javascript;

static EXIT_STATUS: AtomicIsize = ATOMIC_ISIZE_INIT;

fn main() {
Expand Down
72 changes: 28 additions & 44 deletions src/rustbook/static/rustbook.css
Original file line number Diff line number Diff line change
@@ -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.
*
Expand All @@ -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;
}

Expand All @@ -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;
}
Expand All @@ -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 {
Expand Down Expand Up @@ -160,10 +148,6 @@ pre {
border-radius: 3px;
}

.nav-previous-next {
margin-top: 60px;
}

.left {
float: left;
}
Expand Down
Loading