Skip to content

Commit

Permalink
auto merge of #20802 : huonw/rust/book-css, r=steveklabnik
Browse files Browse the repository at this point in the history
There is likely to be new users with the alpha release, and there are a lot of documents on the internet (StackOverflow, reddit, blogs) that refer to these guides, so emitting a more helpful error than "404" is nice. Hence, I've temporarily reinstated stub documents for each of the old guides, referring to as relevant a part of the book as possible.

Also, rustbook was silently ignoring some errors, which lead to an inconsistency with directory creation/file writing. This meant the CSS file was not being written if no `doc` directory existed in the users build dir (e.g. the buildbots). This should mean that the CSS will appear automatically in later builds.
  • Loading branch information
bors committed Jan 10, 2015
2 parents 9205d74 + afe260f commit 391e010
Show file tree
Hide file tree
Showing 18 changed files with 76 additions and 24 deletions.
8 changes: 7 additions & 1 deletion mk/docs.mk
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,12 @@ DOCS := index intro tutorial complement-bugreport \
complement-lang-faq complement-design-faq complement-project-faq \
rustdoc reference

# Legacy guides, preserved for a while to reduce the number of 404s
DOCS += guide-crates guide-error-handling guide-ffi guide-macros guide \
guide-ownership guide-plugins guide-pointers guide-strings guide-tasks \
guide-testing


PDF_DOCS := reference

RUSTDOC_DEPS_reference := doc/full-toc.inc
Expand Down Expand Up @@ -277,6 +283,6 @@ compiler-docs: $(COMPILER_DOC_TARGETS)

trpl: doc/book/index.html

doc/book/index.html: $(RUSTBOOK_EXE) $(wildcard $(S)/src/doc/trpl/*.md)
doc/book/index.html: $(RUSTBOOK_EXE) $(wildcard $(S)/src/doc/trpl/*.md) | doc/
$(Q)rm -rf doc/book
$(Q)$(RUSTBOOK) build $(S)src/doc/trpl doc/book
4 changes: 4 additions & 0 deletions src/doc/guide-crates.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
% The (old) Rust Crates and Modules Guide

This content has moved into the
[the Rust Programming Language book](book/crates-and-modules.html).
4 changes: 4 additions & 0 deletions src/doc/guide-error-handling.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
% Error Handling in Rust

This content has moved into the
[the Rust Programming Language book](book/error-handling.html).
4 changes: 4 additions & 0 deletions src/doc/guide-ffi.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
% The (old) Rust Foreign Function Interface Guide

This content has moved into the
[the Rust Programming Language book](book/ffi.html).
4 changes: 4 additions & 0 deletions src/doc/guide-macros.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
% The (old) Rust Macros Guide

This content has moved into the
[the Rust Programming Language book](book/macros.html).
4 changes: 4 additions & 0 deletions src/doc/guide-ownership.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
% The (old) Rust Ownership Guide

This content has moved into the
[the Rust Programming Language book](book/ownership.html).
4 changes: 4 additions & 0 deletions src/doc/guide-plugins.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
% The (old) Rust Compiler Plugins Guide

This content has moved into the
[the Rust Programming Language book](book/plugins.html).
4 changes: 4 additions & 0 deletions src/doc/guide-pointers.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
% The (old) Rust Pointer Guide

This content has moved into the
[the Rust Programming Language book](book/pointers.html).
4 changes: 4 additions & 0 deletions src/doc/guide-strings.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
% The (old) Guide to Rust Strings

This content has moved into the
[the Rust Programming Language book](book/strings.html).
4 changes: 4 additions & 0 deletions src/doc/guide-tasks.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
% The (old) Rust Threads and Communication Guide

This content has moved into the
[the Rust Programming Language book](book/tasks.html).
4 changes: 4 additions & 0 deletions src/doc/guide-testing.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
% The (old) Rust Testing Guide

This content has moved into the
[the Rust Programming Language book](book/testing.html).
4 changes: 4 additions & 0 deletions src/doc/guide-unsafe.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
% Writing Safe Low-level and Unsafe Code in Rust

This content has moved into the
[the Rust Programming Language book](book/unsafe.html).
4 changes: 4 additions & 0 deletions src/doc/guide.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
% The (old) Rust Guide

This content has moved into the
[the Rust Programming Language book](book/README.html).
7 changes: 4 additions & 3 deletions src/rustbook/book.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ pub fn parse_summary<R: Reader>(input: R, src: &Path) -> Result<Book, Vec<String
let path_from_root = match src.join(given_path.unwrap()).path_relative_from(src) {
Some(p) => p,
None => {
errors.push(format!("Paths in SUMMARY.md must be relative, \
errors.push(format!("paths in SUMMARY.md must be relative, \
but path '{}' for section '{}' is not.",
given_path.unwrap(), title));
Path::new("")
Expand All @@ -148,8 +148,9 @@ pub fn parse_summary<R: Reader>(input: R, src: &Path) -> Result<Book, Vec<String
}).sum() / 4 + 1;

if level > stack.len() + 1 {
// FIXME: better error message
errors.push(format!("Section '{}' is indented too many levels.", item.title));
errors.push(format!("section '{}' is indented too deeply; \
found {}, expected {} or less",
item.title, level, stack.len() + 1));
} else if level <= stack.len() {
collapse(&mut stack, &mut top_items, level);
}
Expand Down
27 changes: 9 additions & 18 deletions src/rustbook/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,7 @@ fn write_toc(book: &Book, path_to_root: &Path, out: &mut Writer) -> IoResult<()>
}

fn render(book: &Book, tgt: &Path) -> CliResult<()> {
let tmp = TempDir::new("rust-book")
.ok()
// FIXME: lift to Result instead
.expect("could not create temporary directory");
let tmp = try!(TempDir::new("rust-book"));

for (section, item) in book.iter() {
println!("{} {}", section, item.title);
Expand Down Expand Up @@ -163,30 +160,24 @@ impl Subcommand for Build {
tgt = Path::new(os::args()[3].clone());
}

let _ = fs::mkdir(&tgt, io::USER_DIR); // FIXME: handle errors
try!(fs::mkdir(&tgt, io::USER_DIR));

// FIXME: handle errors
let _ = File::create(&tgt.join("rust-book.css")).write_str(css::STYLE);
try!(File::create(&tgt.join("rust-book.css")).write_str(css::STYLE));

let summary = File::open(&src.join("SUMMARY.md"));
let summary = try!(File::open(&src.join("SUMMARY.md")));
match book::parse_summary(summary, &src) {
Ok(book) => {
// execute rustdoc on the whole book
try!(render(&book, &tgt).map_err(|err| {
term.err(&format!("error: {}", err.description())[]);
err.detail().map(|detail| {
term.err(&format!("detail: {}", detail)[]);
});
err
}))
render(&book, &tgt)
}
Err(errors) => {
let n = errors.len();
for err in errors.into_iter() {
term.err(&err[]);
term.err(&format!("error: {}", err)[]);
}

Err(box format!("{} errors occurred", n) as Box<Error>)
}
}

Ok(()) // lol
}
}
2 changes: 1 addition & 1 deletion src/rustbook/css.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
// The rust-book CSS in string form.

pub static STYLE: &'static str = r#"
@import url("//static.rust-lang.org/doc/master/rust.css");
@import url("../rust.css");
body {
max-width:none;
Expand Down
1 change: 1 addition & 0 deletions src/rustbook/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,4 +79,5 @@ impl Error for IoError {
}
}


//fn iter_map_err<T, U, E, I: Iterator<Result<T,E>>>(iter: I,
7 changes: 6 additions & 1 deletion src/rustbook/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,12 @@ fn main() {
Ok(_) => {
match subcmd.execute(&mut term) {
Ok(_) => (),
Err(_) => os::set_exit_status(-1),
Err(err) => {
term.err(&format!("error: {}", err.description())[]);
err.detail().map(|detail| {
term.err(&format!("detail: {}", detail)[]);
});
}
}
}
Err(err) => {
Expand Down

0 comments on commit 391e010

Please sign in to comment.