Skip to content

Commit e266651

Browse files
committed
Auto merge of #28649 - nhowell:improve-rustbook, r=steveklabnik
Please see the commits for details. Live demo: http://www.nickhowell.com/rust/book/ Commit 0bebbab should fix #22682 r? @steveklabnik
2 parents 2e88c36 + 0bebbab commit e266651

File tree

8 files changed

+112
-139
lines changed

8 files changed

+112
-139
lines changed

src/librustdoc/html/static/playpen.js

+2
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
/*globals $: true, rootPath: true */
1313

1414
document.addEventListener('DOMContentLoaded', function() {
15+
'use strict';
16+
1517
if (!window.playgroundUrl) {
1618
return;
1719
}

src/rustbook/build.rs

+21-21
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,6 @@ use error::{err, CliResult, CommandResult};
2323
use book;
2424
use book::{Book, BookItem};
2525

26-
use javascript;
27-
2826
use rustdoc;
2927

3028
struct Build;
@@ -82,7 +80,7 @@ fn write_toc(book: &Book, current_page: &BookItem, out: &mut Write) -> io::Resul
8280
}
8381

8482
fn render(book: &Book, tgt: &Path) -> CliResult<()> {
85-
let tmp = try!(TempDir::new("rust-book"));
83+
let tmp = try!(TempDir::new("rustbook"));
8684

8785
for (_section, item) in book.iter() {
8886
let out_path = match item.path.parent() {
@@ -113,26 +111,28 @@ fn render(book: &Book, tgt: &Path) -> CliResult<()> {
113111
// write the prelude to a temporary HTML file for rustdoc inclusion
114112
let prelude = tmp.path().join("prelude.html");
115113
{
116-
let mut toc = BufWriter::new(try!(File::create(&prelude)));
117-
try!(writeln!(&mut toc, r#"<div id="nav">
118-
<button id="toggle-nav">
119-
<span class="sr-only">Toggle navigation</span>
120-
<span class="bar"></span>
121-
<span class="bar"></span>
122-
<span class="bar"></span>
123-
</button>
124-
</div>"#));
125-
let _ = write_toc(book, &item, &mut toc);
126-
try!(writeln!(&mut toc, "<div id='page-wrapper'>"));
127-
try!(writeln!(&mut toc, "<div id='page'>"));
114+
let mut buffer = BufWriter::new(try!(File::create(&prelude)));
115+
try!(writeln!(&mut buffer, r#"
116+
<div id="nav">
117+
<button id="toggle-nav">
118+
<span class="sr-only">Toggle navigation</span>
119+
<span class="bar"></span>
120+
<span class="bar"></span>
121+
<span class="bar"></span>
122+
</button>
123+
</div>"#));
124+
let _ = write_toc(book, &item, &mut buffer);
125+
try!(writeln!(&mut buffer, "<div id='page-wrapper'>"));
126+
try!(writeln!(&mut buffer, "<div id='page'>"));
128127
}
129128

130129
// write the postlude to a temporary HTML file for rustdoc inclusion
131130
let postlude = tmp.path().join("postlude.html");
132131
{
133-
let mut toc = BufWriter::new(try!(File::create(&postlude)));
134-
try!(toc.write_all(javascript::JAVASCRIPT.as_bytes()));
135-
try!(writeln!(&mut toc, "</div></div>"));
132+
let mut buffer = BufWriter::new(try!(File::create(&postlude)));
133+
try!(writeln!(&mut buffer, "<script src='rustbook.js'></script>"));
134+
try!(writeln!(&mut buffer, "<script src='playpen.js'></script>"));
135+
try!(writeln!(&mut buffer, "</div></div>"));
136136
}
137137

138138
try!(fs::create_dir_all(&out_path));
@@ -144,7 +144,7 @@ fn render(book: &Book, tgt: &Path) -> CliResult<()> {
144144
format!("--html-before-content={}", prelude.display()),
145145
format!("--html-after-content={}", postlude.display()),
146146
format!("--markdown-playground-url=https://play.rust-lang.org"),
147-
format!("--markdown-css={}", item.path_to_root.join("rust-book.css").display()),
147+
format!("--markdown-css={}", item.path_to_root.join("rustbook.css").display()),
148148
"--markdown-no-toc".to_string(),
149149
];
150150
let output_result = rustdoc::main_args(rustdoc_args);
@@ -199,10 +199,10 @@ impl Subcommand for Build {
199199
let css = include_bytes!("static/rustbook.css");
200200
let js = include_bytes!("static/rustbook.js");
201201

202-
let mut css_file = try!(File::create(tgt.join("rust-book.css")));
202+
let mut css_file = try!(File::create(tgt.join("rustbook.css")));
203203
try!(css_file.write_all(css));
204204

205-
let mut js_file = try!(File::create(tgt.join("rust-book.js")));
205+
let mut js_file = try!(File::create(tgt.join("rustbook.js")));
206206
try!(js_file.write_all(js));
207207

208208

src/rustbook/help.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ impl Subcommand for Help {
3636
}
3737

3838
pub fn usage() {
39-
println!("Usage: rust-book <command> [<args>]");
39+
println!("Usage: rustbook <command> [<args>]");
4040
println!("");
4141
println!("The <command> must be one of:");
4242
println!(" help Print this message.");

src/rustbook/javascript.rs

-16
This file was deleted.

src/rustbook/main.rs

-2
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,6 @@ mod build;
3535
mod serve;
3636
mod test;
3737

38-
mod javascript;
39-
4038
static EXIT_STATUS: AtomicIsize = ATOMIC_ISIZE_INIT;
4139

4240
fn main() {

src/rustbook/static/rustbook.css

+28-44
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Copyright 2013 The Rust Project Developers. See the COPYRIGHT
2+
* Copyright 2013-2015 The Rust Project Developers. See the COPYRIGHT
33
* file at the top-level directory of this distribution and at
44
* http://rust-lang.org/COPYRIGHT.
55
*
@@ -10,12 +10,11 @@
1010
* except according to those terms.
1111
*/
1212

13-
@import url("../rust.css");
13+
@import url('../rust.css');
1414

1515
body {
16-
max-width:none;
17-
font: 16px/1.4 'Source Serif Pro', Georgia, Times, 'Times New Roman', serif;
18-
line-height: 1.6;
16+
max-width: none;
17+
font: 16px/1.6 'Source Serif Pro', Georgia, Times, 'Times New Roman', serif;
1918
color: #333;
2019
}
2120

@@ -28,68 +27,64 @@ h1, h2, h3, h4, h5, h6 {
2827
@media only screen {
2928
#toc {
3029
position: fixed;
31-
left: 0px;
32-
top: 0px;
33-
bottom: 0px;
30+
top: 0;
31+
left: 0;
32+
bottom: 0;
3433
width: 300px;
3534
overflow-y: auto;
36-
border-right: 1px solid rgba(0, 0, 0, 0.07);
37-
padding: 10px 10px;
35+
border-right: 1px solid #e8e8e8;
36+
padding: 0 15px;
3837
font-size: 14px;
39-
box-sizing: border-box;
40-
-webkit-overflow-scrolling: touch;
4138
background-color: #fafafa;
42-
color: #364149;
39+
-webkit-overflow-scrolling: touch;
4340
}
4441

4542
#page-wrapper {
4643
position: absolute;
47-
left: 310px;
48-
right: 0px;
49-
top: 0px;
50-
box-sizing: border-box;
51-
background: none repeat scroll 0% 0% #FFF;
44+
top: 0;
45+
left: 300px;
46+
right: 0;
47+
padding: 0 15px;
5248
-webkit-overflow-scrolling: touch;
5349
}
5450
}
5551

5652
@media only print {
57-
#toc, #nav, #menu-bar {
53+
#toc, #nav {
5854
display: none;
5955
}
6056
}
6157

62-
@media only screen and (max-width: 1060px) {
58+
@media only screen and (max-width: 1023px) {
6359
#toc {
6460
width: 100%;
65-
margin-right: 0;
6661
top: 40px;
6762
}
63+
6864
#page-wrapper {
6965
top: 40px;
70-
left: 15px;
71-
padding-right: 15px;
66+
left: 0;
7267
}
68+
7369
.mobile-hidden {
7470
display: none;
7571
}
7672
}
7773

7874
#page {
79-
margin-left: auto;
80-
margin-right:auto;
75+
margin: 0 auto;
8176
max-width: 750px;
8277
padding-bottom: 50px;
8378
}
8479

8580
.chapter {
86-
list-style: none outside none;
87-
padding-left: 0px;
81+
list-style: none;
82+
padding-left: 0;
8883
line-height: 30px;
8984
}
9085

9186
.section {
92-
list-style: none outside none;
87+
list-style: none;
9388
padding-left: 20px;
9489
line-height: 40px;
9590
}
@@ -105,28 +100,21 @@ h1, h2, h3, h4, h5, h6 {
105100
padding: 5px 0;
106101
}
107102

108-
.chapter li a.active {
109-
color: #008cff;
110-
}
111-
103+
.chapter li a.active,
112104
.chapter li a:hover {
113105
color: #008cff;
114106
text-decoration: none;
115107
}
116108

117109
#toggle-nav {
118-
height: 20px;
119-
width: 30px;
120-
padding: 3px 3px 0 3px;
121-
}
122-
123-
#toggle-nav {
110+
cursor: pointer;
124111
margin-top: 5px;
125112
width: 30px;
126113
height: 30px;
127-
background-color: #FFF;
114+
background-color: #fff;
128115
border: 1px solid #666;
129-
border-radius: 3px 3px 3px 3px;
116+
border-radius: 3px;
117+
padding: 3px 3px 0 3px;
130118
}
131119

132120
.sr-only {
@@ -160,10 +148,6 @@ pre {
160148
border-radius: 3px;
161149
}
162150

163-
.nav-previous-next {
164-
margin-top: 60px;
165-
}
166-
167151
.left {
168152
float: left;
169153
}

0 commit comments

Comments
 (0)